Skip to content

Commit

Permalink
Refactor removeCommon
Browse files Browse the repository at this point in the history
  • Loading branch information
brb committed Jun 3, 2016
1 parent 0f5692e commit 70f52e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions ipam/tracker/awsvpc.go
Expand Up @@ -224,19 +224,20 @@ func (t *AWSVPCTracker) infof(fmt string, args ...interface{}) {
// Helpers

// removeCommon filters out CIDR ranges which are contained in both a and b slices.
// Both slices have to be sorted in increasing order.
func removeCommon(a, b []address.CIDR) (newA, newB []address.CIDR) {
i, j := 0, 0

for i < len(a) && j < len(b) {
switch {
case a[i].Equal(b[j]):
if a[i].Equal(b[j]) {
i++
j++
continue
case a[i].End() < b[j].End():
}
if a[i].End() < b[j].End() {
newA = append(newA, a[i])
i++
default:
} else {
newB = append(newB, b[j])
j++
}
Expand Down
2 changes: 1 addition & 1 deletion ipam/tracker/tracker.go
Expand Up @@ -11,7 +11,7 @@ type LocalRangeTracker interface {
// prevRanges corresponds to ranges which were owned by a peer before
// a change in the ring, while currRanges to the ones which are currently
// owned by the peer.
// Both slices have to be sorted in increasing order.
HandleUpdate(prevRanges, currRanges []address.Range) error
// String returns a user-friendly name of the tracker.
String() string
}

0 comments on commit 70f52e2

Please sign in to comment.