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