Ziptree (ziptree v1.0.0)
What is a zip tree
Zip tree is a random access data structure that is equivalent to a skiplist, but instead of being stored in multiple arrays it is stored in a binary balanced tree.
It was created in 2018 (Zip Trees, by Robert E. Tarjan, Caleb C. Levy, Stephen Timmel) and then futher improved in 2023 (Zip-zip Trees: Making Zip Trees More Balanced, Biased, Compact, or Persistent by Ofek Gila, Michael T. Goodrich, Robert E. Tarjan)
What is this lib
This is a nif for the rust implementation of zip trees, more specifically the zip zip tree implementation.
Summary
Functions
Deletes the element with a certain key from the zip tree. It's O(log n). Please note that ziptree is a mutable structure, so while we return the updated zip tree for ease of use, any variables that stored the ziptree before the put will be altered as well.
Gets the value for a certain key. It's O(log n).
Creates a new zip tree. The ziptree is a reference, and you can only manipulate it using this lib's functions.
Inserts the element in the zip tree. Not all types can be used for the key or the value, we do not allow Reference, Function, Port or Pid. It's O(log n). Please note that ziptree is a mutable structure, so while we return the updated zip tree for ease of use, any variables that stored the ziptree before the put will be altered as well.
Returns the size of the zip tree, that is, the total number of inserted elements. It's O(1) because it's stored, not calculated.
Types
ziptree()
@type ziptree() :: reference()
Functions
delete(ziptree, key)
Deletes the element with a certain key from the zip tree. It's O(log n). Please note that ziptree is a mutable structure, so while we return the updated zip tree for ease of use, any variables that stored the ziptree before the put will be altered as well.
get(ziptree, key)
Gets the value for a certain key. It's O(log n).
new()
@spec new() :: {:ok, ziptree()}
Creates a new zip tree. The ziptree is a reference, and you can only manipulate it using this lib's functions.
put(ziptree, key, value)
Inserts the element in the zip tree. Not all types can be used for the key or the value, we do not allow Reference, Function, Port or Pid. It's O(log n). Please note that ziptree is a mutable structure, so while we return the updated zip tree for ease of use, any variables that stored the ziptree before the put will be altered as well.
size(ziptree)
Returns the size of the zip tree, that is, the total number of inserted elements. It's O(1) because it's stored, not calculated.