MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / search_single_inner

Function search_single_inner

cranelift/bforest/src/path.rs:798–845  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

796
797 #[test]
798 fn search_single_inner() {
799 // Testing Path::new() for trees with a single inner node and two leaves.
800 let mut pool = NodePool::<TF>::new();
801 let leaf1 = pool.alloc_node(NodeData::leaf(10, 'a')).panic_on_oom();
802 let leaf2 = pool.alloc_node(NodeData::leaf(20, 'b')).panic_on_oom();
803 let root = pool
804 .alloc_node(NodeData::inner(leaf1, 20, leaf2))
805 .panic_on_oom();
806 let mut p = Path::default();
807 let comp = TC();
808
809 // Search for key less than stored keys.
810 assert_eq!(p.find(5, root, &pool, &comp), None);
811 assert_eq!(p.size, 2);
812 assert_eq!(p.node[0], root);
813 assert_eq!(p.entry[0], 0);
814 assert_eq!(p.node[1], leaf1);
815 assert_eq!(p.entry[1], 0);
816
817 assert_eq!(p.find(10, root, &pool, &comp), Some('a'));
818 assert_eq!(p.size, 2);
819 assert_eq!(p.node[0], root);
820 assert_eq!(p.entry[0], 0);
821 assert_eq!(p.node[1], leaf1);
822 assert_eq!(p.entry[1], 0);
823
824 // Midway between the two leaf nodes.
825 assert_eq!(p.find(15, root, &pool, &comp), None);
826 assert_eq!(p.size, 2);
827 assert_eq!(p.node[0], root);
828 assert_eq!(p.entry[0], 0);
829 assert_eq!(p.node[1], leaf1);
830 assert_eq!(p.entry[1], 1);
831
832 assert_eq!(p.find(20, root, &pool, &comp), Some('b'));
833 assert_eq!(p.size, 2);
834 assert_eq!(p.node[0], root);
835 assert_eq!(p.entry[0], 1);
836 assert_eq!(p.node[1], leaf2);
837 assert_eq!(p.entry[1], 0);
838
839 assert_eq!(p.find(25, root, &pool, &comp), None);
840 assert_eq!(p.size, 2);
841 assert_eq!(p.node[0], root);
842 assert_eq!(p.entry[0], 1);
843 assert_eq!(p.node[1], leaf2);
844 assert_eq!(p.entry[1], 1);
845 }
846}

Callers

nothing calls this directly

Calls 6

leafFunction · 0.85
innerFunction · 0.85
TCClass · 0.85
panic_on_oomMethod · 0.80
alloc_nodeMethod · 0.80
newFunction · 0.50

Tested by

no test coverage detected