Ejemplo n.º 1
0
    def find_leaf_block(self, key, root):
        if root == -1:
            block = IndexBlock(self.get_free_block_pointer(), self._index_name, self._index_directory)
            block.create_dummy_node()
            return block

        block = self.read_block(root)
        parent = -1

        while not block.is_leaf():
            parent = block.get_location()
            index_nodes = block.get_index_nodes()
            flag = 0
            for node in index_nodes:
                if key < node.get_key():
                    flag = 1
                    block_location = node.get_index_block_pointer()
                    break
            if flag == 0:
                block_location = block.get_dummy_node_pointer()
            if block_location == -1:
                return self.read_block(parent)
            if block_location == None:
                x = 1
            block = self.read_block(block_location)
        return block
Ejemplo n.º 2
0
    def find_leaf_block(self, key, root):
        if root == -1:
            block = IndexBlock(self.get_free_block_pointer(), self._index_name, self._index_directory)
            block.create_dummy_node()
            return block
        block = IndexBlock(root, self._index_name, self._index_directory)
        parent = -1
        block.read_block(self._fd)

        while not block.is_leaf():
            parent = block.get_location()
            index_nodes = block.get_index_nodes()
            for node in index_nodes:
                if key < node.get_key():
                    block = IndexBlock(node.get_index_block_pointer(), self._index_name, self._index_directory)
                    break
            if block.get_location() == -1:
                return parent
            block.read_block(self._fd)
        return block