From 67f38a7fb1c35d739c04ec15ed5fe729b6637642 Mon Sep 17 00:00:00 2001 From: Yotam Tanay Date: Sat, 16 Sep 2023 22:01:11 +0300 Subject: [PATCH] Fix key value in ThreadedRodeo deserialization The key is set to be the highest key seen, causing the insertion immediately following the deserialization to create a collision in the string map --- src/threaded_rodeo.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/threaded_rodeo.rs b/src/threaded_rodeo.rs index 51a27d4..5176d87 100644 --- a/src/threaded_rodeo.rs +++ b/src/threaded_rodeo.rs @@ -979,8 +979,9 @@ where .expect("failed to allocate memory for interner"); for (string, key) in deser_map { - if key.into_usize() > highest { - highest = key.into_usize(); + let next_key = key.into_usize() + 1; + if next_key > highest { + highest = next_key; } let allocated = unsafe { @@ -1707,6 +1708,12 @@ mod tests { let deser: ThreadedRodeo = serde_json::from_str(&ser).unwrap(); let deser2: ThreadedRodeo = serde_json::from_str(&ser2).unwrap(); + // Verify that the "next" key is set correctly + assert_eq!( + rodeo.key.load(Ordering::Relaxed), + deser.key.load(Ordering::Relaxed) + ); + for (correct_key, correct_str) in [(a, "a"), (b, "b"), (c, "c"), (d, "d")].iter().copied() { assert_eq!(correct_key, deser.get(correct_str).unwrap()); assert_eq!(correct_key, deser2.get(correct_str).unwrap());