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

Multi-cursor components: queue slice #2996

Merged
merged 6 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 3 additions & 3 deletions service/history/queues/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ type (
Remaining() Iterator
}

paginationFnProvider func(Range) collection.PaginationFn[tasks.Task]
PaginationFnProvider func(Range) collection.PaginationFn[tasks.Task]

IteratorImpl struct {
paginationFnProvider paginationFnProvider
paginationFnProvider PaginationFnProvider
remainingRange Range

pagingIterator collection.Iterator[tasks.Task]
}
)

func NewIterator(
paginationFnProvider paginationFnProvider,
paginationFnProvider PaginationFnProvider,
r Range,
) *IteratorImpl {
return &IteratorImpl{
Expand Down
2 changes: 1 addition & 1 deletion service/history/queues/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (r *Range) Merge(
)
}

func (r *Range) Equal(
func (r *Range) Equals(
input Range,
) bool {
return r.InclusiveMin.CompareTo(input.InclusiveMin) == 0 &&
Expand Down
24 changes: 12 additions & 12 deletions service/history/queues/range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ func (s *rangeSuite) TestSplit() {
splitKey := NewRandomKeyInRange(r)

left, right := r.Split(splitKey)
s.True(left.Equal(NewRange(r.InclusiveMin, splitKey)))
s.True(right.Equal(NewRange(splitKey, r.ExclusiveMax)))
s.True(left.Equals(NewRange(r.InclusiveMin, splitKey)))
s.True(right.Equals(NewRange(splitKey, r.ExclusiveMax)))
}

func (s *rangeSuite) TestMerge() {
Expand All @@ -298,29 +298,29 @@ func (s *rangeSuite) TestMerge() {
NewRandomKeyInRange(r),
)
mergedRange := r.Merge(testRange)
s.True(mergedRange.Equal(testRange.Merge(r)))
s.True(mergedRange.Equal(NewRange(tasks.MinimumKey, r.ExclusiveMax)))
s.True(mergedRange.Equals(testRange.Merge(r)))
s.True(mergedRange.Equals(NewRange(tasks.MinimumKey, r.ExclusiveMax)))

testRange = NewRange(
NewRandomKeyInRange(r),
tasks.MaximumKey,
)
mergedRange = r.Merge(testRange)
s.True(mergedRange.Equal(testRange.Merge(r)))
s.True(mergedRange.Equal(NewRange(r.InclusiveMin, tasks.MaximumKey)))
s.True(mergedRange.Equals(testRange.Merge(r)))
s.True(mergedRange.Equals(NewRange(r.InclusiveMin, tasks.MaximumKey)))

testRange = NewRange(tasks.MinimumKey, tasks.MaximumKey)
mergedRange = r.Merge(testRange)
s.True(mergedRange.Equal(testRange.Merge(r)))
s.True(mergedRange.Equal(NewRange(tasks.MinimumKey, tasks.MaximumKey)))
s.True(mergedRange.Equals(testRange.Merge(r)))
s.True(mergedRange.Equals(NewRange(tasks.MinimumKey, tasks.MaximumKey)))

testRange = NewRange(tasks.MinimumKey, r.InclusiveMin)
mergedRange = r.Merge(testRange)
s.True(mergedRange.Equal(testRange.Merge(r)))
s.True(mergedRange.Equal(NewRange(tasks.MinimumKey, r.ExclusiveMax)))
s.True(mergedRange.Equals(testRange.Merge(r)))
s.True(mergedRange.Equals(NewRange(tasks.MinimumKey, r.ExclusiveMax)))

testRange = NewRange(r.ExclusiveMax, tasks.MaximumKey)
mergedRange = r.Merge(testRange)
s.True(mergedRange.Equal(testRange.Merge(r)))
s.True(mergedRange.Equal(NewRange(r.InclusiveMin, tasks.MaximumKey)))
s.True(mergedRange.Equals(testRange.Merge(r)))
s.True(mergedRange.Equals(NewRange(r.InclusiveMin, tasks.MaximumKey)))
}
19 changes: 18 additions & 1 deletion service/history/queues/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (s *Scope) MergeByRange(
func (s *Scope) CanMergeByPredicate(
incomingScope Scope,
) bool {
return s.Range.Equal(incomingScope.Range)
return s.Range.Equals(incomingScope.Range)
}

func (s *Scope) MergeByPredicate(
Expand All @@ -121,3 +121,20 @@ func (s *Scope) MergeByPredicate(
// TODO: special check if the predicates are the same type
return NewScope(s.Range, predicates.Or(s.Predicate, incomingScope.Predicate))
}

func (s *Scope) IsEmpty() bool {
if s.Range.IsEmpty() {
return true
}

if _, ok := s.Predicate.(*predicates.EmptyImpl[tasks.Task]); ok {
return true
}

return false
}

func (s *Scope) Equals(scope Scope) bool {
return s.Range.Equals(scope.Range) &&
s.Predicate.Equals(scope.Predicate)
}
Loading