File: child_iter.rs

package info (click to toggle)
rust-radix-trie 0.1.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 224 kB
  • sloc: makefile: 2
file content (20 lines) | stat: -rw-r--r-- 592 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
extern crate radix_trie;

use radix_trie::{Trie, TrieCommon};

fn main() {
    let mut t = Trie::new();
    t.insert("z", 2);
    t.insert("aba", 5);
    t.insert("abb", 6);
    t.insert("abc", 50);

    // This is a bit of a hack that relies on knowing the binary representation of
    // strings... "abd" works, but "abz" doesn't...
    let ab_sum = t.get_raw_ancestor(&"abd").children().fold(0, |acc, c| {
        println!("Iterating over child with value: {:?}", c.value());
        acc + *c.value().unwrap_or(&0)
    });
    println!("{}", ab_sum);
    assert_eq!(ab_sum, 5 + 6 + 50);
}