Execute interleaved operations for concurrent simulation
(
tree: &mut BPlusTreeMap<i32, String>,
thread1_ops: &[(bool, i32)],
thread2_ops: &[(bool, i32)],
)
| 397 | |
| 398 | /// Execute interleaved operations for concurrent simulation |
| 399 | pub 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 |
no test coverage detected