From 37b52b7f9bcb9bb7353637563f24f18193b6c5d3 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Sat, 21 May 2022 21:47:35 -0700 Subject: Fix iteration when the tree is 7 levels deep + collisions Fixes issue #84. Co-authored-by: eli --- tests/test_map.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests') diff --git a/tests/test_map.py b/tests/test_map.py index 9fffd8c..4640029 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -254,6 +254,40 @@ class BaseMapTest: self.assertEqual(len(h), 0) self.assertEqual(list(h.items()), []) + def test_map_collision_3(self): + # Test that iteration works with the deepest tree possible. + + C = HashKey(0b10000000_00000000_00000000_00000000, 'C') + D = HashKey(0b10000000_00000000_00000000_00000000, 'D') + + E = HashKey(0b00000000_00000000_00000000_00000000, 'E') + + h = self.Map() + h = h.set(C, 'C') + h = h.set(D, 'D') + h = h.set(E, 'E') + + # BitmapNode(size=2 count=1 bitmap=0b1): + # NULL: + # BitmapNode(size=2 count=1 bitmap=0b1): + # NULL: + # BitmapNode(size=2 count=1 bitmap=0b1): + # NULL: + # BitmapNode(size=2 count=1 bitmap=0b1): + # NULL: + # BitmapNode(size=2 count=1 bitmap=0b1): + # NULL: + # BitmapNode(size=2 count=1 bitmap=0b1): + # NULL: + # BitmapNode(size=4 count=2 bitmap=0b101): + # : 'E' + # NULL: + # CollisionNode(size=4 id=0x107a24520): + # : 'C' + # : 'D' + + self.assertEqual({k.name for k in h.keys()}, {'C', 'D', 'E'}) + def test_map_stress_02(self): COLLECTION_SIZE = 20000 TEST_ITERS_EVERY = 647 -- cgit v1.2.3