A key,value store that works on anything.
This works using a binary search tree. In the first version, it's a very naive algorithm, but it will probably be updated to be a red-black tree or something else.
TreeEdge
TreeMap
TreeNode
TreeMap
- Create a treemapequals
- Compare two treemaps and return true iff they contain same keys and valuesfind
- Find a value based on the keyinsert
- Insert a value into the maptraverse
- Visit all pairs in the map in order.TreeEdge
type TreeEdge<K: Copy Eq Ord, V: Copy> = Option<@TreeNode<K, V>>
TreeMap
type TreeMap<K: Copy Eq Ord, V: Copy> = @mut TreeEdge<K, V>
TreeNode
struct TreeNode <K: Copy Eq Ord, V: Copy>{
key: K,
mut value: V,
mut left: TreeEdge<K, V>,
mut right: TreeEdge<K, V>,
}
TreeMap
fn TreeMap<K: Copy Eq Ord, V: Copy>() -> TreeMap<K, V>
Create a treemap
equals
fn equals<K: Copy Eq Ord,
V: Copy Eq>(t1: &const TreeEdge<K, V>, t2: &const TreeEdge<K, V>) ->
bool
Compare two treemaps and return true iff they contain same keys and values
find
fn find<K: Copy Eq Ord, V: Copy>(m: &const TreeEdge<K, V>, k: K) -> Option<V>
Find a value based on the key
insert
fn insert<K: Copy Eq Ord, V: Copy>(m: &mut TreeEdge<K, V>, k: K, v: V)
Insert a value into the map
traverse
fn traverse<K: Copy Eq Ord, V: Copy>(m: &const TreeEdge<K, V>, f: &fn(&K, &V))
Visit all pairs in the map in order.