summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_context.py
diff options
context:
space:
mode:
authorYury Selivanov <yury@edgedb.com>2022-05-23 19:09:59 (GMT)
committerGitHub <noreply@github.com>2022-05-23 19:09:59 (GMT)
commitc1f5c903a7e4ed27190488f4e33b00d3c3d952e5 (patch)
tree6c0fe48100b58b23bd1cb0fcf63a27cb0d2ac7f6 /Lib/test/test_context.py
parenta49721ea075a18a7787ace6752b4eb0954e1b607 (diff)
downloadcpython-c1f5c903a7e4ed27190488f4e33b00d3c3d952e5.zip
cpython-c1f5c903a7e4ed27190488f4e33b00d3c3d952e5.tar.gz
cpython-c1f5c903a7e4ed27190488f4e33b00d3c3d952e5.tar.bz2
gh-93065: Fix HAMT to iterate correctly over 7-level deep trees (GH-93066)
Also while there, clarify a few things about why we reduce the hash to 32 bits. Co-authored-by: Eli Libman <eli@hyro.ai> Co-authored-by: Yury Selivanov <yury@edgedb.com> Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Lib/test/test_context.py')
-rw-r--r--Lib/test/test_context.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_context.py b/Lib/test/test_context.py
index 3132cea..b1aece4 100644
--- a/Lib/test/test_context.py
+++ b/Lib/test/test_context.py
@@ -535,6 +535,41 @@ class HamtTest(unittest.TestCase):
self.assertEqual(len(h4), 2)
self.assertEqual(len(h5), 3)
+ def test_hamt_collision_3(self):
+ # Test that iteration works with the deepest tree possible.
+ # https://github.com/python/cpython/issues/93065
+
+ C = HashKey(0b10000000_00000000_00000000_00000000, 'C')
+ D = HashKey(0b10000000_00000000_00000000_00000000, 'D')
+
+ E = HashKey(0b00000000_00000000_00000000_00000000, 'E')
+
+ h = hamt()
+ 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):
+ # <Key name:E hash:0>: 'E'
+ # NULL:
+ # CollisionNode(size=4 id=0x107a24520):
+ # <Key name:C hash:2147483648>: 'C'
+ # <Key name:D hash:2147483648>: 'D'
+
+ self.assertEqual({k.name for k in h.keys()}, {'C', 'D', 'E'})
+
def test_hamt_stress(self):
COLLECTION_SIZE = 7000
TEST_ITERS_EVERY = 647