Commit 8b62f868 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 44b252e6
...@@ -132,12 +132,9 @@ func (δtail *ΔTail) SliceByRev(low, high Tid) /*readonly*/ []δRevEntry { ...@@ -132,12 +132,9 @@ func (δtail *ΔTail) SliceByRev(low, high Tid) /*readonly*/ []δRevEntry {
return nil // ø 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+1] return tailv[i:j+1]
......
...@@ -72,7 +72,7 @@ func TestΔTail(t *testing.T) { ...@@ -72,7 +72,7 @@ func TestΔTail(t *testing.T) {
// SliceByRev // SliceByRev
fmt.Printf("\nwhole: (%s, %s] %v\n", δtail.Tail(), δtail.Head(), tailv) 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) fmt.Printf("(%s, %s] -> [%d:%d)\n", rlo, rhi, ilo, ihi)
...@@ -81,18 +81,44 @@ func TestΔTail(t *testing.T) { ...@@ -81,18 +81,44 @@ func TestΔTail(t *testing.T) {
if !tailvEqual(have, want) { if !tailvEqual(have, want) {
t.Fatalf("SliceByRev(%s, %s) -> %v ; want %v", rlo, rhi, have, want) t.Fatalf("SliceByRev(%s, %s) -> %v ; want %v", rlo, rhi, have, want)
} }
if len(have) == 0 {
return
}
// make sure returned region is indeed correct
tbefore := Tid(0)
if ilo-1 >= 0 {
tbefore = tailv[ilo-1].rev-1
}
tail := tailv[ilo].rev-1
head := tailv[ihi-1].rev
hafter := TidMax
if ihi < len(tailv) {
hafter = tailv[ihi].rev
}
if !(tbefore < rlo && rlo <= tail && head <= rhi && rhi < hafter) {
t.Fatalf("SliceByRev(%s, %s) -> %v ; edges do not match query:\n" +
"%s (%s, %s] %s", rlo, rhi, have, tbefore, tail, head, hafter)
}
} }
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) && ilo+1 <= ihi {
sliceByRev( sliceByRev(
tailv[ilo].rev, tailv[ilo].rev - 1,
tailv[ihi].rev - 1, tailv[ihi].rev - 1,
ilo+1, ihi, ilo, ihi,
)
// [ilo, ihi]
sliceByRev(
tailv[ilo].rev - 1,
tailv[ihi].rev,
ilo, ihi+1,
) )
}
// (ilo, ihi] // (ilo, ihi]
if ilo+1 < len(tailv) { if ilo+1 < len(tailv) {
...@@ -103,21 +129,16 @@ func TestΔTail(t *testing.T) { ...@@ -103,21 +129,16 @@ func TestΔTail(t *testing.T) {
) )
} }
// [ilo, ihi) // (ilo, ihi)
if ilo+1 < len(tailv) && ilo+1 <= ihi {
sliceByRev( sliceByRev(
tailv[ilo].rev - 1, tailv[ilo].rev,
tailv[ihi].rev - 1, tailv[ihi].rev - 1,
ilo, ihi, ilo+1, ihi,
)
// [ilo, ihi]
sliceByRev(
tailv[ilo].rev - 1,
tailv[ihi].rev,
ilo, ihi+1,
) )
} }
} }
}
// verify lastRevOf query / index // verify lastRevOf query / index
lastRevOf := make(map[Oid]Tid) lastRevOf := make(map[Oid]Tid)
......
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