This repository contains Fractal Tree Index implemented in Python.
The implementation is stored on FractalTree.py file. The Data is stored as python List, enabling the tree to be compatible across data types. The following steps must be followed to utilize the tree for creating an index:
To create a tree object, use the following syntax:
tree = FractalTree(order)
where order
is the order of Nodes in the tree.
To insert data in the tree, a key, value pair must be passed to the FractalTree.buffer()
method. If the data is not in a (key, value) format, use the python builtin Hash
Method to generate a key for your data point.
Once data is in a (key, value) pair, use the following syntax for insertion:
message = (key, value, "insert")
tree.buffer(message)
To retrieve stored data from the tree, call the FractalTree.search_retrieval
Method. The method can be called as follows:
tree.search_retrieval(key)
Deletion follows a similar syntax to insertion. There are two methods to delete from the tree.
Call the FractalTree.delete
Method directly:
tree.delete(key)
Push a delete message to the tree using the FractalTree.buffer
Method:
message = (key, "delete")
tree.buffer(message)
This repository contains an implementation of Fractal Tree Index. These indexes are built up on B+ Trees and provide faster insertion speeds. The following two classes are the principle components of the implementation:
Each node stores keys and values. Keys are not unique to each value, and as such values are stored as a list under each key.
order (int)
: The maximum number of keys each node can hold.
keys (List)
: Contains the list of all keys at a Node.
values (List)
: Contains a list of all values (if leaf is True) or else a list of child objects of type FractalTree
of the Node.
parent (FractalTree Object)
: Stores the parent FractalTree
Object of the Node.
leaf (bool)
: True if Node is a leaf Node, False otherwise. (True by default).
buffer (List)
: Contains the list of all messages buffered in Node. Size of buffer equals order//2
.
adds an insert/delete message to the self node's buffer.
Return value:
If: the buffer is full, return None
else: returns the message itself
Adds a key-value pair to the node.
Return value: None
Splits the node into two and stores them as child nodes.
Return value: None
Returns True if the node is full.
Return type: bool
Prints the keys at each level.
Return type: None
Fractal Tree object, consisting of nodes. Adheres to the self balancing property. Nodes split automatically into two once full. After a split, the center of split floats upward to be inserted in the parent node (merge).
root (Node)
: Stores the root node of the Tree (Contains empty Node
object by default).
For a given node and key, returns the index where the key should be inserted and the child/value at that index.
Return Type: a list
of two items of the following type: [Node
or int
, int
]
For a parent and child node, extract a pivot from the child to be inserted into the keys of the parent. Insert the values from the child into the values of the parent.
Return Type: None
Inserts a key-value pair to a leaf node. If the leaf node is full, split the leaf node into two. This method can be called from within the class's apply_message() method.
Inputs:
parent_node
: parent of the leaf node
leaf_node
: The leaf node on which to insert key, value
key
: The key of the data
value
: Data value corresponding to the key
Return Type: None
Returns a value for a given key, and None if the key does not exist.
Return Type: Node
Object or None
if key doesn't exist
Prints the keys at each level.
Return Type: None
Searches for a key value in the tree along with its buffers.
Return Type: a list containing key and value of the used data type.
Buffers an incoming message of insert/delete to Tree.
Return Type: None
Flushes messages in the node's buffer down a level.
Return Type: None
Applies the insert/delete message on the -> node.
Return Type: None
Searches for a key value in the tree.
Return Type: leaf node object of Node
type that contains the key.
search and find the leaf node where the value may exists
Return Type: None
This project was built on Python 3.9.0 64-bit. No external dependences and libraries used.
This project was made for Data Structures II Spring 2021 Offering at Habib University by team Fibonnaci Additions.