default constructor of a VEB tree is disabled.
to construct a VEB tree one should provide the maximum element one wish to be able to store.
another possibility is to construct a VEB tree by providing an array.
this method returns the capacity of the tree. It is equal to the next power of two with regard to the maximum element
this method is used to add an element to the tree. duplicate values will be ignored.
this method is used to determine, whether an element is currently present in the tree
This is a nontrivial opIndex operator on indizies of the tree. Given an index a range (!) is returned, which is, either the range of elements in the tree build up by [predecessor(i) .. successor(i)] (i. e. excluding the successor(i)), when the given index is not set. Or, if the given index is set, [member(i), successor(i)]. If an index out of bounds is given, an empty array is returned. The tree must not be empty to use this function.
opSlice operator to get the underlying array. This is a draft version, as it uses the successor method of the class. So getting the underlying array is proportional to n. As this functionaly is not seen as crucial, it is enough for the first time.
opSlice operator to get the underlying array between given bounds. This is a draft version, as it uses the successor method of the class. So getting the underlying array is proportional to min(n, m), where n is the number of elements between bounds and m are the number of present elements in the tree.
this method retrieves the predecessor of the given input.
this method is used to remove elements from the tree. not existing values will be ignored.
this method retrieves the successor of the given input.
This method returns the amount of elements currently present in the tree. This is a draft version, as it uses the slice operator of the class. So getting this number has a complexity proportional to n. As this functionaly is not seen as crucial, it is enough for the first time.
this method is used to determine the maximum of the tree
this method is used to determine the minimum of the tree
assert(!__traits(compiles, new vebTree())); vebTree vT = new vebTree(1000); assert(vT.capacity == 1024); assert(vT.min.isNull); vT.insert(2); vT.insert(5); assert(!vT.member(8)); vT.insert(88); vT.insert(8); assert(vT.predecessor(75) == 8); assert(vT.successor(6) == 8); assert(!vT.member(1029)); vT.insert(1029); assert(!vT.member(1029)); assert(!vT.member(865)); vT.insert(865); assert(vT.member(865)); vT.insert(865); assert(vT.member(865)); assert(!vT.member(866)); vT.remove(866); assert(vT.member(865)); vT.remove(865); assert(!vT.member(865));
uint currentSeed = 83843; // unpredictableSeed(); rndGenInUse.seed(currentSeed); //initialize the random generator uint M = uniform(0U,1 << 14, rndGenInUse); //set universe size to some integer. //M = 30_000_000; vebTree vT = new vebTree(M); //create the tree assert(vT.capacity == nextPowerOfTwo(M)); uint m = vT.fill(1000); //(try to) fill the tree with thousend values uint n; Nullable!uint i = vT.predecessor(vT.max)+1; // discover the thousend (or little less) values with the predecessor method while(!i.isNull) { ++n; i = vT.predecessor(i); } // assert, that all members are discovered, iff when no predecessors are left assert(n == m);
This class represents the VEB tree itself. For the sake of convinience it saves the provided at the initialization step wished maximum element. However at the point of development it is only used for testing. Beyond this, it stores only the reference to the root element, as the theory tells.