Commit 44b252e6 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 9e3260a7
...@@ -115,7 +115,7 @@ func (δtail *ΔTail) SliceByRev(low, high Tid) /*readonly*/ []δRevEntry { ...@@ -115,7 +115,7 @@ func (δtail *ΔTail) SliceByRev(low, high Tid) /*readonly*/ []δRevEntry {
tail := δtail.Tail() tail := δtail.Tail()
head := δtail.head head := δtail.head
if !(tail <= low && low <= high && high <= head) { if !(tail <= low && low <= high && high <= head) {
panic(fmt.Sprintf("δtail.Slice: (%s, %s] invalid; tail..head = %s..%s", low, high, tail, head)) panic(fmt.Sprintf("δtail.Slice: invalid query: (%s, %s]; (tail, head] = (%s, %s]", low, high, tail, head))
} }
tailv := δtail.tailv tailv := δtail.tailv
...@@ -125,16 +125,22 @@ func (δtail *ΔTail) SliceByRev(low, high Tid) /*readonly*/ []δRevEntry { ...@@ -125,16 +125,22 @@ func (δtail *ΔTail) SliceByRev(low, high Tid) /*readonly*/ []δRevEntry {
return tailv return tailv
} }
// find max j : [j].rev <= high XXX linear scan // find max j : [j].rev high XXX linear scan
j := len(tailv)-1 j := len(tailv)-1
for ; tailv[j].rev > high; j-- {} for ; j >= 0 && tailv[j].rev > high; j-- {}
if j < 0 {
return nil // ø
}
//fmt.Printf("j: %d\n", j)
// find max i : [i].rev > low XXX linear scan // find max i : [i].rev > low XXX linear scan
i := j i := j
for ; i >= 0 && tailv[i].rev > low; i-- {} for ; i >= 0 && tailv[i].rev > low; i-- {}
// XXX i < 0
i++ i++
return tailv[i:j] return tailv[i:j+1]
} }
// XXX add way to extend coverage without appending changed data? (i.e. if a // XXX add way to extend coverage without appending changed data? (i.e. if a
......
...@@ -71,9 +71,11 @@ func TestΔTail(t *testing.T) { ...@@ -71,9 +71,11 @@ func TestΔTail(t *testing.T) {
// SliceByRev // SliceByRev
fmt.Printf("\nwhole: (%s, %s] %v\n", δtail.Tail(), δtail.Head(), tailv)
// check that δtail.SliceByRev(rlo, rhi) == tailv[ilo:ihi]. // check that δtail.SliceByRev(rlo, rhi) == tailv[ilo:ihi].
sliceByRev := func(rlo, rhi Tid, ilo, ihi int) { sliceByRev := func(rlo, rhi Tid, ilo, ihi int) {
t.Helper() t.Helper()
fmt.Printf("(%s, %s] -> [%d:%d)\n", rlo, rhi, ilo, ihi)
have := δtail.SliceByRev(rlo, rhi) have := δtail.SliceByRev(rlo, rhi)
want := tailv[ilo:ihi] want := tailv[ilo:ihi]
if !tailvEqual(have, want) { if !tailvEqual(have, want) {
...@@ -84,7 +86,7 @@ func TestΔTail(t *testing.T) { ...@@ -84,7 +86,7 @@ func TestΔTail(t *testing.T) {
for ilo := 0; ilo < len(tailv); ilo++ { for ilo := 0; ilo < len(tailv); ilo++ {
for ihi := ilo; ihi < len(tailv); ihi++ { for ihi := ilo; ihi < len(tailv); ihi++ {
// (ilo, ihi) ? // (ilo, ihi) ?
if ilo+1 < len(tailv) { if ilo+1 < len(tailv) && ilo+1 <= ihi {
sliceByRev( sliceByRev(
tailv[ilo].rev, tailv[ilo].rev,
tailv[ihi].rev - 1, tailv[ihi].rev - 1,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment