Skip to content

Expose 0x100000000 #141

Closed
Closed

Description

@anacrolix

Several methods (like RemoveRange), take a non-inclusive upper bound that must be 0x100000000 to get the effect of >= begin ([begin, inf]). It would be helpful if this value was exposed, as passing -1, or 0, MaxUint32 or MaxUint64 will not have the desired effect.

Activity

  1. maciej commented on Feb 5, 2018

    @maciej
    Member

    @anacrolix I'm sorry, I'm afraid I don't understand you. Could you provide some example code to illustrate the issue?

  2. anacrolix commented on Feb 6, 2018

    @anacrolix
    ContributorAuthor

    If you read https://github.com/RoaringBitmap/roaring/blob/master/roaring.go#L1069 you will see the only way to remove math.MaxUint32 is to pass 0x1000000 as a uint64. This is also pointed out in the method doc. Passing any other value will result in uint32 truncation to a rangeEnd-1 that was not intended.

  3. anacrolix commented on Feb 6, 2018

    @anacrolix
    ContributorAuthor

    That should be 0x100000000. See this:

    func TestRoaringRangeEnd(t *testing.T) {
    	r := roaring.New()
    	r.Add(roaring.MaxUint32)
    	require.EqualValues(t, 1, r.GetCardinality())
    	r.RemoveRange(0, roaring.MaxUint32)
    	assert.EqualValues(t, 1, r.GetCardinality()) // nope, missed
    	r.RemoveRange(0, math.MaxUint64)
    	assert.EqualValues(t, 1, r.GetCardinality()) // missed again!
    	r.RemoveRange(0, 0x100000001)
    	assert.EqualValues(t, 1, r.GetCardinality()) // you lose!
    	r.RemoveRange(0, 0x100000000)
    	assert.EqualValues(t, 0, r.GetCardinality()) // hacks
    }
    
  4. lemire commented on Feb 6, 2018

    @lemire
    Member

    I think all we need to do is to check whether the upper range exceeds 0x100000000. I'll prepare a commit.

  5. added a commit that references this issue on Feb 6, 2018
  6. lemire commented on Feb 6, 2018

    @lemire
    Member

    The following test now passes:

    func TestRoaringRangeEnd(t *testing.T) {
    	r := New()
    	r.Add(MaxUint32)
    	if 1 != r.GetCardinality() {
    		t.FailNow()
    	}
    	r.RemoveRange(0, MaxUint32)
    	if 1 != r.GetCardinality() {
    		t.FailNow()
    	}
    	r.RemoveRange(0, math.MaxUint64)
    	if 0 != r.GetCardinality() {
    		t.FailNow()
    	}
    	r.Add(MaxUint32)
    	if 1 != r.GetCardinality() {
    		t.FailNow()
    	}
    	r.RemoveRange(0, 0x100000001)
    	if 0 != r.GetCardinality() {
    		t.FailNow()
    	}
    	r.Add(MaxUint32)
    	if 1 != r.GetCardinality() {
    		t.FailNow()
    	}
    	r.RemoveRange(0, 0x100000000)
    	if 0 != r.GetCardinality() {
    		t.FailNow()
    	}
    }
    
    
  7. added a commit that references this issue on Apr 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions