veb v0.2.0 Veb View Source
This is an functional implement of the Integer data structure, van Emde Boas tree. As it’s in the functional environment, the data structure actually implemented is the RS-vEB tree, which is the normal VEB improved in the time complexity of creation and the space complexity of storage.
Currently, this module has implemented insert!, delete, successor, predecessor operations, the time complexity of which is $O(log{log{u}})$, where $u$ is the size of the data universe. And there are also operations like from_list, to_list, which are based on those basic operations.
There exists an limitation of $u$, that is, $u$ must be a power of the $2$. However, a automatical deriving method is written in creating operations, you can simply provide the max value of your data, and then the $u$ will be calculated easily.
As it is promised in the paper, the space complexity is $O(n)$, where $n$ is the number os your data. According to some randomized tests, the speed of this implement is not bad.
Link to this section Summary
Types
Type t stands for the RS-vEB tree. It is filled with nil and empty map when no element is insert!ed, and dynamically built as insert!ing and deleting
Functions
Delete the given element from the tree, if not exist, do nothing
Delete the given element from the tree, if not exist, raise an error
Delete the given element from the tree, may cause unexpected result when the key is invalid
Create a tree from a list. Similarily as the new(), you can change the mode by providing the atom. “:auto” is set as default, which is to enum the list to find the max value
Return the count of the valid binary bits of the given number
insert an element, if existed, do nothing. Or return {:error, v} when the value is not valid
insert an element with overflow check
insert! an element unsafely, you should make sure that the element is within the bound
Return the max element of a RS-vEB tree, or nil when given with the empty tree or nil
Check whether the given element is in the given tree
Return the max element of a RS-vEB tree, or nil when given the empty tree or nil
Create a tree, using the given $u$, or deriving $u$ from the given max value. The second mode is set as default. You can change the mode by providing the atom
Return the predecessor element or return nil when the tree is nil or empty or the required element is not exist
Return the successor element or return nil when the tree is nil or empty or the required element is not exist
Create a list from a tree. Note that nil tree is not supported and will cause runtime error
Link to this section Types
Type t stands for the RS-vEB tree. It is filled with nil and empty map when no element is insert!ed, and dynamically built as insert!ing and deleting.
Link to this section Functions
Delete the given element from the tree, if not exist, do nothing.
Delete the given element from the tree, if not exist, raise an error.
Delete the given element from the tree, may cause unexpected result when the key is invalid.
from_list(list, non_neg_integer, :auto | :by_max | :by_u) :: t
Create a tree from a list. Similarily as the new(), you can change the mode by providing the atom. “:auto” is set as default, which is to enum the list to find the max value.
Return the count of the valid binary bits of the given number.
insert an element, if existed, do nothing. Or return {:error, v} when the value is not valid.
insert an element with overflow check.
insert! an element unsafely, you should make sure that the element is within the bound.
Return the max element of a RS-vEB tree, or nil when given with the empty tree or nil
Check whether the given element is in the given tree.
Return the max element of a RS-vEB tree, or nil when given the empty tree or nil
new(non_neg_integer, :by_max | :by_u) :: t
Create a tree, using the given $u$, or deriving $u$ from the given max value. The second mode is set as default. You can change the mode by providing the atom.
pred(t | nil, non_neg_integer) :: non_neg_integer | nil
Return the predecessor element or return nil when the tree is nil or empty or the required element is not exist.
succ(t | nil, non_neg_integer) :: non_neg_integer | nil
Return the successor element or return nil when the tree is nil or empty or the required element is not exist.
Create a list from a tree. Note that nil tree is not supported and will cause runtime error.