Commit b96e30f1 authored by Jan Mercl's avatar Jan Mercl

Add seek test.

parent e2e747ce
......@@ -1298,3 +1298,35 @@ func TestPut(t *testing.T) {
}
}
}
func TestSeek(t *testing.T) {
const N = 1 << 13
tr := TreeNew(cmp)
for i := 0; i < N; i++ {
k := 2*i + 1
tr.Set(k, nil)
}
for i := 0; i < N; i++ {
k := 2 * i
e, ok := tr.Seek(k)
if ok {
t.Fatal(k)
}
for j := i; j < N; j++ {
k2, _, err := e.Next()
if err != nil {
t.Fatal(k, err)
}
if g, e := k2, 2*j+1; g != e {
t.Fatal(j, g, e)
}
}
_, _, err := e.Next()
if err != io.EOF {
t.Fatalf("expected io.EOF, got %v", err)
}
}
}
......@@ -473,9 +473,9 @@ func (t *Tree) overflow(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{
t.split(p, q, pi, i, k, v)
}
// Seek returns an Enumerator positioned on a an item such that k >= item's
// key. ok reports if k == item.key The Enumerator's position is possibly
// after the last item in the tree.
// Seek returns an Enumerator positioned on an item such that k >= item's key.
// ok reports if k == item.key The Enumerator's position is possibly after the
// last item in the tree.
func (t *Tree) Seek(k interface{} /*K*/) (e *Enumerator, ok bool) {
q := t.r
if q == nil {
......
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