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

Function search_single_leaf

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

Source from the content-addressed store, hash-verified

743
744 #[test]
745 fn search_single_leaf() {
746 // Testing Path::new() for trees with a single leaf node.
747 let mut pool = NodePool::<TF>::new();
748 let root = pool.alloc_node(NodeData::leaf(10, 'a')).panic_on_oom();
749 let mut p = Path::default();
750 let comp = TC();
751
752 // Search for key less than stored key.
753 assert_eq!(p.find(5, root, &pool, &comp), None);
754 assert_eq!(p.size, 1);
755 assert_eq!(p.node[0], root);
756 assert_eq!(p.entry[0], 0);
757
758 // Search for stored key.
759 assert_eq!(p.find(10, root, &pool, &comp), Some('a'));
760 assert_eq!(p.size, 1);
761 assert_eq!(p.node[0], root);
762 assert_eq!(p.entry[0], 0);
763
764 // Search for key greater than stored key.
765 assert_eq!(p.find(15, root, &pool, &comp), None);
766 assert_eq!(p.size, 1);
767 assert_eq!(p.node[0], root);
768 assert_eq!(p.entry[0], 1);
769
770 // Modify leaf node to contain two values.
771 match pool[root] {
772 NodeData::Leaf {
773 ref mut size,
774 ref mut keys,
775 ref mut vals,
776 } => {
777 *size = 2;
778 keys[1] = 20;
779 vals[1] = 'b';
780 }
781 _ => unreachable!(),
782 }
783
784 // Search for key between stored keys.
785 assert_eq!(p.find(15, root, &pool, &comp), None);
786 assert_eq!(p.size, 1);
787 assert_eq!(p.node[0], root);
788 assert_eq!(p.entry[0], 1);
789
790 // Search for key greater than stored keys.
791 assert_eq!(p.find(25, root, &pool, &comp), None);
792 assert_eq!(p.size, 1);
793 assert_eq!(p.node[0], root);
794 assert_eq!(p.entry[0], 2);
795 }
796
797 #[test]
798 fn search_single_inner() {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected