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

exp/lighthorizon, xdr: Rename CheckpointIndex to better reflect its capabilty. #4510

Merged
merged 3 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rename NextActive -> NextActiveBit to be descriptive
  • Loading branch information
Shaptic committed Aug 5, 2022
commit 9eb3cc72a64aa76661b526427832bf87b92ae9be
2 changes: 1 addition & 1 deletion exp/lighthorizon/index/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (s *store) NextActive(account, indexId string, afterCheckpoint uint32) (uin
if err != nil {
return 0, err
}
return ind.NextActive(afterCheckpoint)
return ind.NextActiveBit(afterCheckpoint)
}

func (s *store) getCreateTrieIndex(prefix string) (*types.TrieIndex, error) {
Expand Down
10 changes: 5 additions & 5 deletions exp/lighthorizon/index/types/bitmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (i *BitmapIndex) iterate(f func(index uint32)) error {

for {
var err error
curr, err = i.nextActive(curr + 1)
curr, err = i.nextActiveBit(curr + 1)
if err != nil {
if err == io.EOF {
break
Expand Down Expand Up @@ -166,16 +166,16 @@ func (i *BitmapIndex) Merge(other *BitmapIndex) error {
return err
}

// NextActive returns the next checkpoint (inclusive) where this index is
// NextActiveBit returns the next checkpoint (inclusive) where this index is
Shaptic marked this conversation as resolved.
Show resolved Hide resolved
// active. "Inclusive" means that if the index is active at `checkpoint`, this
// returns `checkpoint`.
func (i *BitmapIndex) NextActive(index uint32) (uint32, error) {
func (i *BitmapIndex) NextActiveBit(index uint32) (uint32, error) {
i.mutex.RLock()
defer i.mutex.RUnlock()
return i.nextActive(index)
return i.nextActiveBit(index)
}

func (i *BitmapIndex) nextActive(index uint32) (uint32, error) {
func (i *BitmapIndex) nextActiveBit(index uint32) (uint32, error) {
if i.firstBit == 0 || index > i.lastBit {
// We're past the end.
// TODO: Should this be an error? or how should we signal NONE here?
Expand Down
24 changes: 12 additions & 12 deletions exp/lighthorizon/index/types/bitmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestNextActive(t *testing.T) {
t.Run("empty", func(t *testing.T) {
index := &BitmapIndex{}

i, err := index.NextActive(0)
i, err := index.NextActiveBit(0)
assert.Equal(t, uint32(0), i)
assert.EqualError(t, err, io.EOF.Error())
})
Expand All @@ -142,7 +142,7 @@ func TestNextActive(t *testing.T) {
index.SetActive(3)

// 16 is well-past the end
i, err := index.NextActive(16)
i, err := index.NextActiveBit(16)
assert.Equal(t, uint32(0), i)
assert.EqualError(t, err, io.EOF.Error())
})
Expand All @@ -151,7 +151,7 @@ func TestNextActive(t *testing.T) {
index := &BitmapIndex{}
index.SetActive(1)

i, err := index.NextActive(1)
i, err := index.NextActiveBit(1)
assert.NoError(t, err)
assert.Equal(t, uint32(1), i)
})
Expand All @@ -160,7 +160,7 @@ func TestNextActive(t *testing.T) {
index := &BitmapIndex{}
index.SetActive(9)

i, err := index.NextActive(1)
i, err := index.NextActiveBit(1)
assert.NoError(t, err)
assert.Equal(t, uint32(9), i)
})
Expand All @@ -170,19 +170,19 @@ func TestNextActive(t *testing.T) {
severalSet.SetActive(11)

t.Run("several bits set (first)", func(t *testing.T) {
i, err := severalSet.NextActive(9)
i, err := severalSet.NextActiveBit(9)
assert.NoError(t, err)
assert.Equal(t, uint32(9), i)
})

t.Run("several bits set (second)", func(t *testing.T) {
i, err := severalSet.NextActive(10)
i, err := severalSet.NextActiveBit(10)
assert.NoError(t, err)
assert.Equal(t, uint32(11), i)
})

t.Run("several bits set (second, inclusive)", func(t *testing.T) {
i, err := severalSet.NextActive(11)
i, err := severalSet.NextActiveBit(11)
assert.NoError(t, err)
assert.Equal(t, uint32(11), i)
})
Expand All @@ -194,27 +194,27 @@ func TestNextActive(t *testing.T) {
index.SetActive(129)

// Before the first
i, err := index.NextActive(8)
i, err := index.NextActiveBit(8)
assert.NoError(t, err)
assert.Equal(t, uint32(9), i)

// at the first
i, err = index.NextActive(9)
i, err = index.NextActiveBit(9)
assert.NoError(t, err)
assert.Equal(t, uint32(9), i)

// In the middle
i, err = index.NextActive(11)
i, err = index.NextActiveBit(11)
assert.NoError(t, err)
assert.Equal(t, uint32(129), i)

// At the end
i, err = index.NextActive(129)
i, err = index.NextActiveBit(129)
assert.NoError(t, err)
assert.Equal(t, uint32(129), i)

// after the end
i, err = index.NextActive(130)
i, err = index.NextActiveBit(130)
assert.EqualError(t, err, io.EOF.Error())
assert.Equal(t, uint32(0), i)
})
Expand Down