Auto-balanced binary search tree implementation that works with secondary memory to store records. Supports insertion, key-based search, range-based search and remove.
-
operator bool()
- Casts as true the class instance if his
index file
already exists and false otherwise.
- Casts as true the class instance if his
-
create index()
- Iterates over the
heap file
and insert record per record each key in theindex file
- If the index already exists, deletes the existing index in order to re-build a new index.
- Iterates over the
-
insert(KeyType key, long pointer)
- Inserts a new
node(key, pointer)
in theindex file
. Such node stores areference
to a record in aheap file
and its correspondentkey
associated. - Internally, descends the
AVL
until aDISK_NULL
node is reached in order to put the new node at the end of theindex file
and reassign the father pointer. - If a node with the same
key
already exists there are two cases: if theindex file
is indexing a non-repeatable key, in which case an exception is thrown; otherwise, the nodes that shares the samekey
get linked in aforward list
.
- Inserts a new
-
search(KeyType key)
- Searches all the records such that
record.key = key
- If the
index file
is indexing a non-repeatable key, returns one record at most.
- Searches all the records such that
-
range_search(KeyType lower_bound, KeyType upper_bound)
- Searches all the records such that
lower_bound <= index(record) <= upper_bound
- It makes recursive calls, pruning the states that are not useful for the search.
- Searches all the records such that
-
remove(KeyType key)
- Removes (logically) all the records such that
index(record) = key
by marking all therecord.removed
astrue
and removing such nodes of theAVL
.
- Removes (logically) all the records such that
If the AVL is indexing a primary or secondary key:
Member Function | Performance | Description |
---|---|---|
insert(KeyType key) |
Descends in the tree and inserts below a leaf node (often makes rotations). | |
search(KeyType key) |
Descends in the tree until the key is found. | |
remove(KeyType key) |
Descends in the tree until the key is found; then, chooses the remove method given the node state (often makes rotations). | |
range_search(KeyType lower_bound, KeyType upper_bound) |
Descends the tree searching for the nodes that haves keys in the range and prunes the recursion to visit only the needed nodes. |
If the AVL is indexing any other field:
Member Function | Performance | Description |
---|---|---|
insert(KeyType key) |
Descends in the tree and inserts below a leaf node (often makes rotations). If the key is repeated, links the new node using LIFO method. |
|
search(KeyType key) |
Descends in the tree until the key is found; then, iterates over the linked list of repeated keys |
|
remove(KeyType key) |
Descends in the tree until the key is found. Then, removes logically each record in the heap file . Finally, chooses the remove method given the node state (often makes rotations). |
|
range_search(KeyType lower_bound, KeyType upper_bound) |
Descends the tree searching for the nodes that haves keys in the range and prunes the recursion to visit only the needed nodes. |