Commit 33317fd1 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent a0ed0fea
// Copyright (C) 2018 Nexedi SA and Contributors.
// Copyright (C) 2018-2019 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// Package btree provides B⁺ Trees for ZODB.
//
......
// Copyright (c) 2001, 2002 Zope Foundation and Contributors.
// All Rights Reserved.
//
// Copyright (C) 2018 Nexedi SA and Contributors.
// Copyright (C) 2018-2019 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This software is subject to the provisions of the Zope Public License,
......@@ -224,12 +224,15 @@ func (b *Bucket) get(key KEY) (interface{}, bool) {
// ---- min/max key ----
// XXX
func (t *BTree) MinKey(ctx context.Context) (_ KEY, _ bool, err error) {
// MinKey returns minimum key in BTree.
//
// If the tree is empty, ok=false is returned.
// t does not need to be activated beforehand.
func (t *BTree) MinKey(ctx context.Context) (_ KEY, ok bool, err error) {
defer xerr.Contextf(&err, "btree(%s): minkey", t.POid())
err = t.PActivate(ctx)
if err != nil {
return 0, false, err // XXX 0 ok?
return 0, false, err
}
if len(t.data) == 0 {
......@@ -238,7 +241,7 @@ func (t *BTree) MinKey(ctx context.Context) (_ KEY, _ bool, err error) {
return 0, false, nil
}
// XXX -> just use t.firstBucket
// NOTE -> can also use t.firstBucket
for {
child := t.data[0].child.(zodb.IPersistent)
t.PDeactivate()
......@@ -259,12 +262,15 @@ func (t *BTree) MinKey(ctx context.Context) (_ KEY, _ bool, err error) {
}
}
// XXX
// MaxKey returns maximum key in BTree.
//
// If the tree is empty, ok=false is returned.
// t does not need to be activated beforehand.
func (t *BTree) MaxKey(ctx context.Context) (_ KEY, _ bool, err error) {
defer xerr.Contextf(&err, "btree(%s): maxkey", t.POid())
err = t.PActivate(ctx)
if err != nil {
return 0, false, err // XXX 0 ok?
return 0, false, err
}
l := len(t.data)
......@@ -294,16 +300,20 @@ func (t *BTree) MaxKey(ctx context.Context) (_ KEY, _ bool, err error) {
}
}
// XXX
func (b *Bucket) MinKey() (KEY, bool) {
// MinKey returns minimum key in Bucket.
//
// If the bucket is empty, ok=false is returned.
func (b *Bucket) MinKey() (_ KEY, ok bool) {
if len(b.keys) == 0 {
return 0, false
}
return b.keys[0], true
}
// XXX
func (b *Bucket) MaxKey() (KEY, bool) {
// MaxKey returns maximum key in Bucket.
//
// If the bucket is empty, ok=false is returned.
func (b *Bucket) MaxKey() (_ KEY, ok bool) {
l := len(b.keys)
if l == 0 {
return 0, false
......
......@@ -3,7 +3,7 @@
// Copyright (c) 2001, 2002 Zope Foundation and Contributors.
// All Rights Reserved.
//
// Copyright (C) 2018 Nexedi SA and Contributors.
// Copyright (C) 2018-2019 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This software is subject to the provisions of the Zope Public License,
......@@ -226,12 +226,15 @@ func (b *IOBucket) get(key int32) (interface{}, bool) {
// ---- min/max key ----
// XXX
func (t *IOBTree) MinKey(ctx context.Context) (_ int32, _ bool, err error) {
// MinKey returns minimum key in IOBTree.
//
// If the tree is empty, ok=false is returned.
// t does not need to be activated beforehand.
func (t *IOBTree) MinKey(ctx context.Context) (_ int32, ok bool, err error) {
defer xerr.Contextf(&err, "btree(%s): minkey", t.POid())
err = t.PActivate(ctx)
if err != nil {
return 0, false, err // XXX 0 ok?
return 0, false, err
}
if len(t.data) == 0 {
......@@ -240,6 +243,7 @@ func (t *IOBTree) MinKey(ctx context.Context) (_ int32, _ bool, err error) {
return 0, false, nil
}
// NOTE -> can also use t.firstBucket
for {
child := t.data[0].child.(zodb.IPersistent)
t.PDeactivate()
......@@ -260,12 +264,15 @@ func (t *IOBTree) MinKey(ctx context.Context) (_ int32, _ bool, err error) {
}
}
// XXX
// MaxKey returns maximum key in IOBTree.
//
// If the tree is empty, ok=false is returned.
// t does not need to be activated beforehand.
func (t *IOBTree) MaxKey(ctx context.Context) (_ int32, _ bool, err error) {
defer xerr.Contextf(&err, "btree(%s): maxkey", t.POid())
err = t.PActivate(ctx)
if err != nil {
return 0, false, err // XXX 0 ok?
return 0, false, err
}
l := len(t.data)
......@@ -295,16 +302,20 @@ func (t *IOBTree) MaxKey(ctx context.Context) (_ int32, _ bool, err error) {
}
}
// XXX
func (b *IOBucket) MinKey() (int32, bool) {
// MinKey returns minimum key in IOBucket.
//
// If the bucket is empty, ok=false is returned.
func (b *IOBucket) MinKey() (_ int32, ok bool) {
if len(b.keys) == 0 {
return 0, false
}
return b.keys[0], true
}
// XXX
func (b *IOBucket) MaxKey() (int32, bool) {
// MaxKey returns maximum key in IOBucket.
//
// If the bucket is empty, ok=false is returned.
func (b *IOBucket) MaxKey() (_ int32, ok bool) {
l := len(b.keys)
if l == 0 {
return 0, false
......
......@@ -3,7 +3,7 @@
// Copyright (c) 2001, 2002 Zope Foundation and Contributors.
// All Rights Reserved.
//
// Copyright (C) 2018 Nexedi SA and Contributors.
// Copyright (C) 2018-2019 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This software is subject to the provisions of the Zope Public License,
......@@ -226,12 +226,15 @@ func (b *LOBucket) get(key int64) (interface{}, bool) {
// ---- min/max key ----
// XXX
func (t *LOBTree) MinKey(ctx context.Context) (_ int64, _ bool, err error) {
// MinKey returns minimum key in LOBTree.
//
// If the tree is empty, ok=false is returned.
// t does not need to be activated beforehand.
func (t *LOBTree) MinKey(ctx context.Context) (_ int64, ok bool, err error) {
defer xerr.Contextf(&err, "btree(%s): minkey", t.POid())
err = t.PActivate(ctx)
if err != nil {
return 0, false, err // XXX 0 ok?
return 0, false, err
}
if len(t.data) == 0 {
......@@ -240,6 +243,7 @@ func (t *LOBTree) MinKey(ctx context.Context) (_ int64, _ bool, err error) {
return 0, false, nil
}
// NOTE -> can also use t.firstBucket
for {
child := t.data[0].child.(zodb.IPersistent)
t.PDeactivate()
......@@ -260,12 +264,15 @@ func (t *LOBTree) MinKey(ctx context.Context) (_ int64, _ bool, err error) {
}
}
// XXX
// MaxKey returns maximum key in LOBTree.
//
// If the tree is empty, ok=false is returned.
// t does not need to be activated beforehand.
func (t *LOBTree) MaxKey(ctx context.Context) (_ int64, _ bool, err error) {
defer xerr.Contextf(&err, "btree(%s): maxkey", t.POid())
err = t.PActivate(ctx)
if err != nil {
return 0, false, err // XXX 0 ok?
return 0, false, err
}
l := len(t.data)
......@@ -295,16 +302,20 @@ func (t *LOBTree) MaxKey(ctx context.Context) (_ int64, _ bool, err error) {
}
}
// XXX
func (b *LOBucket) MinKey() (int64, bool) {
// MinKey returns minimum key in LOBucket.
//
// If the bucket is empty, ok=false is returned.
func (b *LOBucket) MinKey() (_ int64, ok bool) {
if len(b.keys) == 0 {
return 0, false
}
return b.keys[0], true
}
// XXX
func (b *LOBucket) MaxKey() (int64, bool) {
// MaxKey returns maximum key in LOBucket.
//
// If the bucket is empty, ok=false is returned.
func (b *LOBucket) MaxKey() (_ int64, ok bool) {
l := len(b.keys)
if l == 0 {
return 0, false
......
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