Skip to content

Fix iteration when the tree is 7 levels deep + collisions #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion immutables/_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdint.h>
#include "Python.h"

#define _Py_HAMT_MAX_TREE_DEPTH 7
#define _Py_HAMT_MAX_TREE_DEPTH 8


#define Map_Check(o) (Py_TYPE(o) == &_Map_Type)
Expand Down
34 changes: 34 additions & 0 deletions tests/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,40 @@ def test_map_stress_01(self):
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):
# <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_map_stress_02(self):
COLLECTION_SIZE = 20000
TEST_ITERS_EVERY = 647
Expand Down