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

Function split_level0_leaf

cranelift/bforest/src/map.rs:1016–1064  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1014
1015 #[test]
1016 fn split_level0_leaf() {
1017 // Various ways of splitting a full leaf node at level 0.
1018 let f = &mut MapForest::<u32, f32>::new();
1019
1020 fn full_leaf(f: &mut MapForest<u32, f32>) -> Map<u32, f32> {
1021 let mut m = Map::new();
1022 for n in 1..8 {
1023 m.insert(n * 10, n as f32 * 1.1, f, &());
1024 }
1025 m
1026 }
1027
1028 // Insert at front of leaf.
1029 let mut m = full_leaf(f);
1030 m.insert(5, 4.2, f, &());
1031 m.verify(f, &());
1032 assert_eq!(m.get(5, f, &()), Some(4.2));
1033
1034 // Retain even entries, with altered values.
1035 m.retain(f, |k, v| {
1036 *v = (k / 10) as f32;
1037 (k % 20) == 0
1038 });
1039 assert_eq!(
1040 m.iter(f).collect::<Vec<_>>(),
1041 [(20, 2.0), (40, 4.0), (60, 6.0)]
1042 );
1043
1044 // Insert at back of leaf.
1045 let mut m = full_leaf(f);
1046 m.insert(80, 4.2, f, &());
1047 m.verify(f, &());
1048 assert_eq!(m.get(80, f, &()), Some(4.2));
1049
1050 // Insert before middle (40).
1051 let mut m = full_leaf(f);
1052 m.insert(35, 4.2, f, &());
1053 m.verify(f, &());
1054 assert_eq!(m.get(35, f, &()), Some(4.2));
1055
1056 // Insert after middle (40).
1057 let mut m = full_leaf(f);
1058 m.insert(45, 4.2, f, &());
1059 m.verify(f, &());
1060 assert_eq!(m.get(45, f, &()), Some(4.2));
1061
1062 m.clear(f);
1063 assert!(m.is_empty());
1064 }
1065
1066 #[test]
1067 fn split_level1_leaf() {

Callers

nothing calls this directly

Calls 6

full_leafFunction · 0.85
newFunction · 0.50
insertMethod · 0.45
verifyMethod · 0.45
retainMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected