michaelsproul / rust_radix_trie

Fast generic radix trie implemented in Rust
https://docs.rs/radix_trie/
MIT License
188 stars 33 forks source link

get_raw_ancestor none with multiple children #64

Open sampaioletti opened 3 years ago

sampaioletti commented 3 years ago

Very sure this is from my lack of understanding of a radix tree...but can someone tell me why the second test fails pls. Thanks in advance.

    #[test]
    fn test_example() {
        let mut t = Trie::new();
        t.insert("/1", "1");
        t.insert("/1/1.1", "1.1");
        t.insert("/1/1.2", "1.2");
        t.insert("/1/1.3", "1.3");
        // t.insert("/2", "2");
        let v: Vec<&str> = t
            .get_raw_ancestor("")
            .children()
            .map(|s| *s.value().unwrap())
            .collect();

        let mut iter = v.iter();
        assert!(*iter.next().unwrap() == "1");
        assert!(iter.next().is_none());
    }
    #[test]
    fn test_example_fails() {
        let mut t = Trie::new();
        t.insert("/1", "1");
        t.insert("/1/1.1", "1.1");
        t.insert("/1/1.2", "1.2");
        t.insert("/1/1.3", "1.3");
        t.insert("/2", "2"); // <- uncommented
        let v: Vec<&str> = t
            .get_raw_ancestor("")
            .children()
            .map(|s| *s.value().unwrap()) //<-panics
            .collect();

        let mut iter = v.iter();
        assert!(*iter.next().unwrap() == "1");
        assert!(*iter.next().unwrap() == "2");
        assert!(iter.next().is_none());
    }