Skip to content

Commit 37b52b7

Browse files
1st1molaxx
andcommitted
Fix iteration when the tree is 7 levels deep + collisions
Fixes issue #84. Co-authored-by: eli <[email protected]>
1 parent 71ecba5 commit 37b52b7

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

immutables/_map.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <stdint.h>
55
#include "Python.h"
66

7-
#define _Py_HAMT_MAX_TREE_DEPTH 7
7+
#define _Py_HAMT_MAX_TREE_DEPTH 8
88

99

1010
#define Map_Check(o) (Py_TYPE(o) == &_Map_Type)

tests/test_map.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,40 @@ def test_map_stress_01(self):
254254
self.assertEqual(len(h), 0)
255255
self.assertEqual(list(h.items()), [])
256256

257+
def test_map_collision_3(self):
258+
# Test that iteration works with the deepest tree possible.
259+
260+
C = HashKey(0b10000000_00000000_00000000_00000000, 'C')
261+
D = HashKey(0b10000000_00000000_00000000_00000000, 'D')
262+
263+
E = HashKey(0b00000000_00000000_00000000_00000000, 'E')
264+
265+
h = self.Map()
266+
h = h.set(C, 'C')
267+
h = h.set(D, 'D')
268+
h = h.set(E, 'E')
269+
270+
# BitmapNode(size=2 count=1 bitmap=0b1):
271+
# NULL:
272+
# BitmapNode(size=2 count=1 bitmap=0b1):
273+
# NULL:
274+
# BitmapNode(size=2 count=1 bitmap=0b1):
275+
# NULL:
276+
# BitmapNode(size=2 count=1 bitmap=0b1):
277+
# NULL:
278+
# BitmapNode(size=2 count=1 bitmap=0b1):
279+
# NULL:
280+
# BitmapNode(size=2 count=1 bitmap=0b1):
281+
# NULL:
282+
# BitmapNode(size=4 count=2 bitmap=0b101):
283+
# <Key name:E hash:0>: 'E'
284+
# NULL:
285+
# CollisionNode(size=4 id=0x107a24520):
286+
# <Key name:C hash:2147483648>: 'C'
287+
# <Key name:D hash:2147483648>: 'D'
288+
289+
self.assertEqual({k.name for k in h.keys()}, {'C', 'D', 'E'})
290+
257291
def test_map_stress_02(self):
258292
COLLECTION_SIZE = 20000
259293
TEST_ITERS_EVERY = 647

0 commit comments

Comments
 (0)