Module avl_tree_map

Source
Expand description

A proper sorted map

§About

This sorted map uses the library’s AVL tree as its backing structure, providing O(log(n)) search, insert, and delete operations.

§Example

    use dsa_rust::associative::avl_tree_map::TreeMap;

    let text = "and the final paragraph clearly came from the heart, 
    or whatever cool yet sensitive organ Sadie kept in place of one.";

    let mut map = TreeMap::<char, usize>::new();

    for e in text.chars() {
        if map.contains(e) {
            let old = map.remove(e).unwrap();
            map.put(e, old.value() + 1);
        } else {
            map.put(e, 1);
        }
    }
    println!("TreeMap character occurrence");
    for e in map.iter() {
        println!("{e:?}");
    }

    println!("\nTreeMap vowel occurrence");
    for vowel in ['a', 'e', 'i', 'o', 'u', 'y'] {
        eprintln!("{vowel}: {}", map.get(vowel).unwrap_or(&0));
    }
TreeMap character occurrence
('\n', 1)
(' ', 24)
(',', 1)
('.', 1)
('S', 1)
('a', 12)
('c', 4)
('d', 2)
('e', 14)
('f', 3)
('g', 2)
('h', 5)
('i', 5)
('k', 1)
('l', 5)
('m', 2)
('n', 6)
('o', 7)
('p', 4)
('r', 8)
('s', 2)
('t', 7)
('v', 2)
('w', 1)
('y', 2)

TreeMap vowel occurrence
a: 12
e: 14
i: 5
o: 7
u: 0
y: 2

Structs§

Entry
The wrapper struct that allows TreeMap<K, V> to use AVLTree. Because T is Ord, Entry<K, V> must implement Eq and PartialOrd, which themselves must implement PartialEq. All traits use key for ordering.
Iter
TreeMap
See the module-level documentation for more details.