MCPcopy Create free account
hub / github.com/KentBeck/BPlusTree3 / execute_interleaved_ops

Function execute_interleaved_ops

rust/tests/test_utils.rs:399–427  ·  view source on GitHub ↗

Execute interleaved operations for concurrent simulation

(
    tree: &mut BPlusTreeMap<i32, String>,
    thread1_ops: &[(bool, i32)],
    thread2_ops: &[(bool, i32)],
)

Source from the content-addressed store, hash-verified

397
398/// Execute interleaved operations for concurrent simulation
399pub fn execute_interleaved_ops(
400 tree: &mut BPlusTreeMap<i32, String>,
401 thread1_ops: &[(bool, i32)],
402 thread2_ops: &[(bool, i32)],
403) {
404 for i in 0..thread1_ops.len() {
405 // Thread 1 operation
406 let (is_insert, key) = thread1_ops[i];
407 if is_insert {
408 tree.insert(key * 10, format!("t1-{}", key));
409 } else {
410 tree.remove(&(key * 10));
411 }
412
413 // Check invariants after each operation
414 assert_invariants(tree, &format!("after thread1 op {}", i));
415
416 // Thread 2 operation
417 let (is_insert, key) = thread2_ops[i];
418 if is_insert {
419 tree.insert(key * 10 + 1, format!("t2-{}", key));
420 } else {
421 tree.remove(&(key * 10 + 1));
422 }
423
424 // Check invariants after each operation
425 assert_invariants(tree, &format!("after thread2 op {}", i));
426 }
427}
428
429// ============================================================================
430// DEBUGGING AND STATISTICS

Calls 4

assert_invariantsFunction · 0.85
lenMethod · 0.45
insertMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected