Skip to content

Conversation

@mkeskells
Copy link
Contributor

@mkeskells mkeskells commented Jul 25, 2025

SUMMARY

dont count and compare with 0
just see if any of the registers are non empty

Automated Checks

Part of #776

@lemire
Copy link
Member

lemire commented Jul 28, 2025

This is good, but why not...

public boolean isEmpty() {
  return highLowContainer.isEmpty();
}

@mkeskells
Copy link
Contributor Author

This is good, but why not...

public boolean isEmpty() {
  return highLowContainer.isEmpty();
}

I was not sure of the invariance

All of the tests pass with that so I have pushed the suggestion

@blacelle
Copy link
Member

All mutating methods seems indeed to check for emptyness. There might be obscure edge-cases when deserializing (e.g. from non-Java implementations which might not prune empty containers).

@mkeskells
Copy link
Contributor Author

mkeskells commented Jul 29, 2025

All mutating methods seems indeed to check for emptyness. There might be obscure edge-cases when deserializing (e.g. from non-Java implementations which might not prune empty containers).

I han not considered the case of deserialisation from another form, or from a previous version that didnt prune

The code doesnt seems to expect this invariance (e.g. trim check for empty())
if would be simple to add a post deserialisation check

private void removeEmpty() {
    if (!highLowContainer.isEmpty()) {
      KeyIterator keyIterator = highLowContainer.highKeyIterator();
      while (keyIterator.hasNext()) {
        keyIterator.next();
        long containerIdx = keyIterator.currentContainerIdx();
        Container container = highLowContainer.getContainer(containerIdx);
        if (container.isEmpty()) {
          keyIterator.remove();
        }
      }
    }
  }

As a side note it looks like highKeyIterator doesnt implement the Iterator contract. It advances on hasNext not on next

@lemire lemire merged commit 600b7c4 into RoaringBitmap:master Jul 30, 2025
7 checks passed
@lemire
Copy link
Member

lemire commented Jul 30, 2025

Merged.

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.

3 participants