veb v0.1.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

t()

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

Link to this type t() View Source
t() :: %Veb{cluster: %{} | %{required(non_neg_integer) => t}, log_u: non_neg_integer, max: nil | non_neg_integer, min: nil | non_neg_integer, summary: nil | t}

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

Link to this function delete(v, x) View Source
delete(t | nil, non_neg_integer) :: t | nil | {:error, t}

Delete the given element from the tree, if not exist, do nothing.

Link to this function delete!(v, x) View Source
delete!(t | nil, non_neg_integer) :: t | nil

Delete the given element from the tree, if not exist, raise an error.

Link to this function delete_unsafe(v, x) View Source
delete_unsafe(t | nil, non_neg_integer) :: t | nil

Delete the given element from the tree, may cause unexpected result when the key is invalid.

Link to this function from_list(list, limit \\ 0, mode \\ :auto) View Source
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.

Link to this function get_bits(n) View Source
get_bits(non_neg_integer) :: non_neg_integer

Return the count of the valid binary bits of the given number.

Link to this function insert(v, x) View Source
insert(t, non_neg_integer) :: t | {:error, t}

insert an element, if existed, do nothing. Or return {:error, v} when the value is not valid.

Link to this function insert!(v, x) View Source
insert!(t, non_neg_integer) :: t

insert an element with overflow check.

Link to this function insert_unsafe(v, x) View Source
insert_unsafe(t, non_neg_integer) :: t

insert! an element unsafely, you should make sure that the element is within the bound.

Link to this function max(v) View Source
max(nil | t) :: nil | non_neg_integer

Return the max element of a RS-vEB tree, or nil when given with the empty tree or nil

Link to this function member?(v, x) View Source
member?(t, non_neg_integer) :: true | false

Check whether the given element is in the given tree.

Link to this function min(v) View Source
min(nil | t) :: nil | non_neg_integer

Return the max element of a RS-vEB tree, or nil when given the empty tree or nil

Link to this function new(limit, mode \\ :by_max) View Source
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.

Link to this function pred(v, x) View Source
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.

Link to this function succ(v, x) View Source
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.

Link to this function to_list(v) View Source
to_list(t) :: list

Create a list from a tree. Note that nil tree is not supported and will cause runtime error.