Index string provenance with metered image and session tables
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
use super::*;
|
||||
#[test]
|
||||
fn collision_chains_distinguish_full_identity_and_survive_tombstones() {
|
||||
let b = RuntimeBudget::default();
|
||||
let mut table = IdentityIndex::new(&b);
|
||||
let keys: Vec<_> = (0..1000)
|
||||
.map(|address| Identity { address, length: 4 })
|
||||
.filter(|k| k.hash() & 7 == 0)
|
||||
.take(4)
|
||||
.collect();
|
||||
for (i, key) in keys.iter().enumerate() {
|
||||
table.prepare(&b).unwrap();
|
||||
table.insert(*key, i);
|
||||
}
|
||||
for key in &keys {
|
||||
assert!(table.contains(*key, || {}));
|
||||
}
|
||||
table.retain(|i| *i != 1);
|
||||
assert!(!table.contains(keys[1], || {}));
|
||||
assert!(table.contains(keys[3], || {}));
|
||||
assert!(!table.contains(Identity { length: 5, ..keys[3] }, || {}));
|
||||
table.prepare(&b).unwrap(); // Rebuild removes tombstones at half occupancy.
|
||||
table.insert(keys[1], 1);
|
||||
assert_eq!(table.len(), 4);
|
||||
assert_eq!(table.tombstones, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tombstone_reuse_keeps_collision_successors_and_length_is_part_of_key() {
|
||||
let b = RuntimeBudget::default();
|
||||
let mut t = IdentityIndex::new(&b);
|
||||
let key = Identity { address: 16, length: 0 };
|
||||
t.prepare(&b).unwrap();
|
||||
t.insert(key, 1);
|
||||
t.prepare(&b).unwrap();
|
||||
t.insert(Identity { length: 1, ..key }, 2);
|
||||
t.retain(|v| *v != 1);
|
||||
assert_eq!(t.tombstones, 1);
|
||||
t.prepare(&b).unwrap();
|
||||
t.insert(key, 3);
|
||||
assert_eq!(t.tombstones, 0);
|
||||
assert!(t.contains(key, || {}));
|
||||
assert!(t.contains(Identity { length: 1, ..key }, || {}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn controlled_probe_counts_and_half_load_survive_growth_and_rebuild() {
|
||||
let b = RuntimeBudget::default();
|
||||
let mut table = IdentityIndex::new(&b);
|
||||
for n in 0..1024 {
|
||||
table.prepare(&b).unwrap();
|
||||
table.insert(Identity { address: n * 16, length: n % 7 }, n);
|
||||
assert!(table.live * 2 <= table.buckets.len());
|
||||
}
|
||||
let mut max_probes = 0;
|
||||
for n in 0..2048 {
|
||||
let mut probes = 0;
|
||||
assert_eq!(
|
||||
table.contains(Identity { address: n * 16, length: n % 7 }, || probes += 1),
|
||||
n < 1024
|
||||
);
|
||||
max_probes = max_probes.max(probes);
|
||||
}
|
||||
// A reproducible synthetic-key bound for this fixture, not a hash-table
|
||||
// worst-case claim or a constraint on allocator-selected real addresses.
|
||||
assert!(max_probes <= 32, "fixture probes={max_probes}");
|
||||
table.retain(|n| n % 2 == 0);
|
||||
table.prepare(&b).unwrap();
|
||||
for n in 0..1024 {
|
||||
assert_eq!(table.contains(Identity { address: n * 16, length: n % 7 }, || {}), n % 2 == 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user