A tool to test the binary search tree
This is an implementation of a persistent binary search tree for the GLib open-source data structures library. You may download the source code in an independent library of its own.
My implementation uses a Treap  as the underlying binary search tree, and then uses the node-copying method as desribed by Driscol, et al. At the same time, the code behind the persistence can be generalized to provide an additional data structure that performs Fractional Cascading for no extra cost to the BST implementation. There are currently no readily available open source implementations of a persistent BST.
This would be a great tool for students, academic researchers, and other developers. There are 2 other BSTs that a tool to test the binary search tree work effectively to provide a persistent BST, while also maintaining a very efficient implementation for when persistence is not used. Treaps can be expected to outperform Red-Black Trees for any sized tree.
The constant in the search cost for a Treap is Approximately equal to AVL trees and slightly less for large treesand is always smaller than Red-Black Trees. It's a small constant regardless.
Treaps are also much simpler to implement, requiring less complicated code. However Treaps are a randomized data structure, which some people try to stay away from. An AVL tree is not suitable for a persistant structure since deleting a node may require up to log n rotations, on a path up to the root, in order to rebalance the tree. A Treap only requires a constant average number of rotations both on insert and delete. These methods perform a search for a query key q and can return one of three things: The value corresponding to the exact key qor else NULL if q is not a tool to test the binary search tree.
These methods provide an essential functionality of a binary search tree, and are one of the few distinct advantages of a binary search tree over a hash table.
A hash table cannot tell you what element is the next or previous key when a search fails to find anything. The original implementation used a left and right pointer in each a tool to test the binary search tree of the tree, but no parent pointer.
These left and right child pointers were also used, in the leaves, to point to the previous and next node in sorted order, so that tree traversal could be done incrementally without knowing the parent. To make the tree persistent, each node must be aware of who is maintaining pointers to it, that is, it's incoming pointers. Instead, a node would need to keep a pointer to its next and previous nodes.
This adds two new pointers to the data structure. Instead, I opted to add a parent pointer, and not use the left and right child pointers in this way at the leaves. When multiple copies of a node can exist due to persistence, they need to all share the same key and value attributes. Instead of putting these two pointers in every copy of a node, I opted to move them into an auxilerary GTreeNodeData structure, which is shared between all nodes through the new data pointer.
Since there are multiple nodes pointing to the same data, we can't free the data and call the key and value destroy functions the first time a node is freed. Lastly, the stolen attribute was added to the GTreeNodeData structure to keep track of which nodes are removed from the tree or stolen from it.
The reference count and stolen flag add another two bit values when compiled under my test environment with gcc and "-O2". The parentleftand right pointers were moved out of the GTreeNode structure, and into GTreeNodeVersionwith a version added along with them.
An array of this structure was a tool to test the binary search tree added back into the GTreeNodeallowing the node to have an array of pointers to its neighbours, with a version attached to each one. This version is equivalent to the version stamp described in . I chose to make this a dynamically allocated array requiring the pointer v and size nv in GTreeNode so to reduce the memory footprint of a tree without any persistence.
If a tree remains in its first version, all nodes are created with an array of only one GTreeNodeVersion. This increases the space nodes in a persistent tree by a pointer and a counter, but reduces the footprint in a tree without persistence by three structures of three pointers and a bit integer each. You can see this difference in space in Table 2 when persistence is used.
The size of a persistent GTreeNode is roughly twice the size of an upstream node, when persistence is not being used. When multiple versions are used, a tool to test the binary search tree of these things are shared between copies of a node, but without persistence they all belong solely to a single node. During development, I considered using a single GTreeNode for all persistent versions of a node, removing the need for the data pointer and redirection to find a node's key or value.
This change would be equivalent to increasing the size of every GTreeNode pointer inside the tree, increasing the total space used in the end, while also increasing the complexity of the code.
Because of this I chose to instead allocate a new GTreeNode each time a node needs to add a pointer to its table, vbut does not have room. Once a tree is persistant, it may have multiple root nodes. Each time the root node changes, a new pointer into the tree needs to be remembered. The nr attribute tracks how many GTreeRootVersion structures are in the array. Each GTreeRootVersion contains a version, which is the version at which the node it points to became root.
Thus all versions afterwards will also have the same node as a root, until another GTreeRootVersion is added to the array r. The number of possible root nodes is unbounded, but on average will be no more than O log nas a new node a tool to test the binary search tree becomes the root if it has the lowest priority in the entire tree.
Searching for the correct node based on a version is done with a binary search, and so is expected to take O log log n time, and does not significantly impact the running time of a search in older versions of the tree. Since all insert and delete operations take place in the latest version of a GTree, it can be expected that nodes must find their newest set of pointers more often than their older versions, and so I wanted to optimize this operation.
The attribute v is stored with the newest largest version first, in index 0. All other versions are then stored in increasing order in indices 1 to n Thus if we stored versions 1 to 5, they would be stored in order "". This saves one pointer dereference and one pointer addition at each node when traversing the newest tree, as the node's nv attribute does not need to be read and the pointer v points directly to the first element of the array.
A tool to test the binary search tree array r in GTreewhich is an array of GTreeRootVersion structures is treated in the same way, with the newest largest version first, and all others sorted in increasing order in the successive array cells. I performed tests of my implementation of a GTree against the one currently in the upstream GLib library to determine the performance impact of having persistence available.
To make a fair evaluation, I compare the amount of time and the number of rotations required to insert, query, and delete nodes in a GTree which does not use any persistence. This way the comparison is only for functionality which existed upstream beforehand, and is a measure of how applying these patches to the GLib library would impact current users of the GTree a tool to test the binary search tree.
However I was also interested in how much of a cost would be involved to use persistence in the GTree. For this test I compared the amount of time to insert, query, and delete nodes in a GTree which does use persistence versus one which does not, but using my persistant implementation in both cases.
In the case which uses persistence, I tested two different scenarios. The first test spreads the inserted keys across approximately four different versions, and the second one creates a new version for every key inserted.
This is a measure of the cost involved to use persistence for users interested in using the feature. The machine which these tests were performed on has a bit Intel processor, with 4KB of cache. I have two source trees, one for my persistent GTree implementation, and one which is simple the current upstream git head commit 6b7b7aeedecebb9ed33which I will refer to as persistent and upstream respectively.
For testing purposes, I applied a patch to both source trees in order to allow me to count the number of rotations being performed. The compiler I used is the bit version of gcc GCC 4. In the upstream tree, I performed the following steps: In the persistent tree, I performed the following steps: This creates two installations of GLib in my home directory, one which a tool to test the binary search tree the persistent GTree, and one which uses the upstream non-persistent GTree, both compiled without extra debug info, and with optimization level -O2.
I used these test programs, test-single. Note that dynamic linking is required for this test to correctly use both GLib versions. When comparing the upstream and persistent implementations, the test uses the same random seed, so that the same keys are inserted into each tree, and the same queries are made, etc. The two implementations are compared using three different random seeds for each set of elements inserted into them, giving three different sets of key values to be inserted, queried, and deleted.
The set of elements is 10 6 one million elements, and each successive set grows by 10 5. My full test results are available at the endwith the results summarized in the tables below.
In the first table we compare the upstream GTree implementation to the persistent GTree, when only using funtionality in the upstream version, a tool to test the binary search tree without making use of persistence. The full a tool to test the binary search tree show clearly what is summarized in this table. Inserting an element in the persistent tree a tool to test the binary search tree less than 1. The different number of rotations is because we use a Treap versus the AVL tree in upstream.
The AVL tree does slightly more rotations, creating a slightly better balanced tree in these tests. However, when multiple versions are used later, the balance of the persistent GTree improves significantly, leading me to believe that the hashing a tool to test the binary search tree function in the Treap implementation has room for improvement in generating more random-like priorities.
The query time in the persistent GTree is nearly identical on average to the upstream tree, and this difference is a tool to test the binary search tree of the size of the tree, though we can see the Treaps unpredictability in the full results, as adding more elements to the tree can improve the query time.
Deletions require more rotations in the treap, but generally take less time than in the upstream AVL tree, possibly because they don't need to modify nodes all the way to the root. The only real impact from using the persistent GTree comes in the memory footprint. By using the persistent tree with only 1 version, the memory foot print approximately doubles, as the structure has additional pointers and variables which are not all needed until additional versions are added to the tree.
In the second table we see the cost of using versions in a persistent GTree. From the table it is clear that the costs for using a tool to test the binary search tree are quite reasonable. The time to insert an element increases, but only by a constant amount, completely independent of the size of the tree, or the number of versions in the tree.
This cost comes from the fact that finding the right child pointer in each node along a path requires a search for the correct version, and that more memory allocations may be done when inserting and rotating the new node into place. The number of rotations per insert increases, about on par with the upstream GTree, and query time drops significantly. This appears to be due to priority function in the Treap giving better pseudo-random values since we are doing more memory allocations, pushing memory addresses further apart.
The time to delete and the number of rotations needed to delete also drop as the tree is more balanced, and there is only a constant amount of increased overhead due to having multiple versions. The last two a tool to test the binary search tree in this table, the time to destroy the tree, and the size of the tree, are both averaged over the number of elements inserted into the tree plus the number of versions in the tree divided by four.
The number of versions is divided by four because a new piece of memory is allocated for a node after it is modified over four different versions. It is clear that the size of the GTree, and thus the time to destroy it, should be proportional to the number of elements and the number of versions, and the results show the constant factor relating to them.
When using one version, or n versions, regardless of the number of elements inserted or number of versions, the size value shown in this table remains constant, and is very close to the size of a single node, implying that on average one node is added to the GTree structure per insert, even when adding a new version. In summary, adding persistence to the GTree data structure did not impact the performance of the structure in any significant way, while adding greater functionality to a tool to test the binary search tree structure.
Insertion in particular became slower, but it did so only by an epsilon constant factor, while other operations are not affected negatively at all and some seemed to improve.
The memory footprint required to add this additional functionality does increase the size of the structure by a factor of approximately two, as shown in the description of the implementation details.
Com Ja Zasady ochrany osobnich udaju Ja Disclaimer. Informacni a obchodni vedeni nalezt na internetovych strankach predstavuje autory pouze nazor.
Binarni moznosti zahrnovat vysoce rizikove a nejsou vhodne pro vsechny investory.