Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyxdd committed Jul 6, 2022
1 parent 7cedeed commit 5b462b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions frame_sorter.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *frameSorter) push(data []byte, offset protocol.ByteCount, doneCb func()

start := offset
end := offset + protocol.ByteCount(len(data))
covInterval := &utils.ByteInterval{start, end}
covInterval := &utils.ByteInterval{Start: start, End: end}

gaps := s.gapTree.Match(covInterval)

Expand All @@ -61,10 +61,13 @@ func (s *frameSorter) push(data []byte, offset protocol.ByteCount, doneCb func()
endGap := gaps[len(gaps)-1].(*utils.ByteInterval)
startGapEqualsEndGap := len(gaps) == 1

if startGapEqualsEndGap && end <= startGap.Start {
return errDuplicateStreamData
}

startsInGap := covInterval.Start >= startGap.Start && covInterval.Start <= startGap.End
endsInGap := covInterval.End >= endGap.Start && covInterval.End < endGap.End

// startGapNext := startGap.Next()
startGapEnd := startGap.End // save it, in case startGap is modified
endGapStart := endGap.Start // save it, in case endGap is modified
endGapEnd := endGap.End // save it, in case endGap is modified
Expand Down Expand Up @@ -126,7 +129,7 @@ func (s *frameSorter) push(data []byte, offset protocol.ByteCount, doneCb func()

if !startGapEqualsEndGap {
s.deleteConsecutive(startGapEnd)
for _, gap := range gaps {
for _, gap := range gaps[1:] {
g := gap.(*utils.ByteInterval)
if g.End >= endGapStart {
break
Expand Down
13 changes: 13 additions & 0 deletions internal/utils/tree/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestBtree(t *testing.T) {
&interval{start: 1, end: 2},
&interval{start: 5, end: 6},
&interval{start: 7, end: 8},
&interval{start: 20, end: 100},
&interval{start: 11, end: 12},
}
btree := New()
Expand Down Expand Up @@ -84,4 +85,16 @@ func TestBtree(t *testing.T) {
if rs[1].(*interval).start != 3 || rs[1].(*interval).end != 4 {
t.Errorf("expected result 2 to be [3, 4], got %v", rs[1])
}

btree.Delete(&interval{start: 11, end: 12})

rs = btree.Match(&interval{start: 12, end: 19})
if len(rs) != 0 {
t.Errorf("expected 0 results, got %d", len(rs))
}

expect, actual = len(values)-2, btree.Len()
if actual != expect {
t.Error("length should equal", expect, "actual", actual)
}
}

0 comments on commit 5b462b6

Please sign in to comment.