Skip to content
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

node48 children can have holes #565

Merged
merged 3 commits into from
Jan 20, 2024
Merged

node48 children can have holes #565

merged 3 commits into from
Jan 20, 2024

Conversation

Dr-Emann
Copy link
Member

@Dr-Emann Dr-Emann commented Jan 20, 2024

When removing from a node48, the child is simply set to NULL. For example, if the state is (ignoring that it actually needs at least 17 items to not be a node16):

keys: {[0]=0, [1]=1}
children: {[0]=child1, [1]=child2}
count: 2

After removing key 0, the state will be:

keys: {[0]=48, [1]=1}
children: {[0]=NULL, [1]=child2}
count: 1

If we then try to insert at key 3, the item at children[count] is already in use: we have to find and reuse the 0th child.

Rather than matching the java implementation (though see the first commit 7dbad58), keep a bitset of available children slots. This slightly increases the size of the node48 struct, but it means:

  • We don't have to initialize all children to null at init time
  • We don't have to loop looking for a child (sometimes) on insert

This also has some fixes for art_printf:

  • When printing keys, don't cast to char, if char is signed, when integer promoted, a 0xFF char will be printed as FFFFFFFF
  • Correctly output keys for node48
  • Include child index for node48
  • Correct child output for node48

This matches the [java implementation][1] in Roaring.

When removing from a node48, the child is simply set to NULL. For example, if
the state is (ignoring that it actually needs at least 17 items to not be a
node16):

```
keys: {[0]=0, [1]=1}
children: {[0]=child1, [1]=child2}
count: 2
```

After removing key 0, the state will be:

```
keys: {[0]=48, [1]=1}
children: {[0]=NULL, [1]=child2}
count: 1
```

If we then try to insert at key 3, the item at `children[count]` is already in
use: we have to find and reuse the 0th child.

This also has some fixes for `art_printf`:

* When printing keys, don't cast to char, if char is signed, when integer
  promoted, a 0xFF char will be printed as `FFFFFFFF`
* Correctly output keys for node48
* Include child index for node48
* Correct child output for node48

[1]: https://github.com/RoaringBitmap/RoaringBitmap/blob/1ed0242d1f298cf93d3666a754eb4bb4c5180c4c/RoaringBitmap/src/main/java/org/roaringbitmap/art/Node48.java#L181-L187
@Dr-Emann Dr-Emann requested a review from SLieve January 20, 2024 08:46
Copy link
Contributor

@SLieve SLieve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for finding and fixing!

src/art/art.c Show resolved Hide resolved
src/art/art.c Show resolved Hide resolved
tests/roaring64_unit.cpp Outdated Show resolved Hide resolved
Rather than searching for an unset child, we can just use the first set bit in
a bitset of available children.

Also, when freeing the node, rather than iterating through all 256 possible
keys, just iterate through all set children directly.

This slightly increases the size of the node48 struct, but it means:

* We don't have to initialize all children to null at init time
* We don't have to loop looking for a child (sometimes) on insert
@Dr-Emann
Copy link
Member Author

Forgot to free at the end of the test

@Dr-Emann Dr-Emann merged commit f4bb67a into master Jan 20, 2024
44 checks passed
@Dr-Emann
Copy link
Member Author

As a bonus, with this and the other PRs merged so far, I've now been fuzzing for a few hours with no issues 🎉

@Dr-Emann Dr-Emann deleted the r64_node48_holes branch January 20, 2024 20:55
@SLieve
Copy link
Contributor

SLieve commented Jan 20, 2024

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants