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

Function leaf_balance

cranelift/bforest/src/node.rs:778–804  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

776
777 #[test]
778 fn leaf_balance() {
779 let mut lhs = NodeData::<TF>::leaf('a', SetValue());
780 for i in 1..6 {
781 assert!(lhs.try_leaf_insert(usize::from(i), ('a' as u8 + i) as char, SetValue()));
782 }
783 assert_eq!(lhs.to_string(), "[ a b c d e f ]");
784
785 let mut rhs = NodeData::<TF>::leaf('0', SetValue());
786 for i in 1..8 {
787 assert!(rhs.try_leaf_insert(usize::from(i), ('0' as u8 + i) as char, SetValue()));
788 }
789 assert_eq!(rhs.to_string(), "[ 0 1 2 3 4 5 6 7 ]");
790
791 // 6+8 elements all fits in rhs.
792 assert_eq!(lhs.balance('0', &mut rhs), None);
793 assert_eq!(rhs.to_string(), "[ a b c d e f 0 1 2 3 4 5 6 7 ]");
794
795 assert!(lhs.try_leaf_insert(0, 'x', SetValue()));
796 assert!(lhs.try_leaf_insert(1, 'y', SetValue()));
797 assert!(lhs.try_leaf_insert(2, 'z', SetValue()));
798 assert_eq!(lhs.to_string(), "[ x y z ]");
799
800 // 3+14 elements need redistribution.
801 assert_eq!(lhs.balance('a', &mut rhs), Some('0'));
802 assert_eq!(lhs.to_string(), "[ x y z a b c d e f ]");
803 assert_eq!(rhs.to_string(), "[ 0 1 2 3 4 5 6 7 ]");
804 }
805}

Callers

nothing calls this directly

Calls 2

leafFunction · 0.85
SetValueClass · 0.85

Tested by

no test coverage detected