Commit e829e4c8 authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/btree: Introduce constants for min/max key value

We were already using math.Min<Key> in one place, but the number of such
places is going to increase. -> Keep min/max definition in only one place.
parent 501f5aea
...@@ -102,6 +102,9 @@ type BucketEntry struct { ...@@ -102,6 +102,9 @@ type BucketEntry struct {
value interface{} value interface{}
} }
const _KeyMin KEY = math.Min<Key>
const _KeyMax KEY = math.Max<Key>
// ---- access []entry ---- // ---- access []entry ----
// Key returns BTree entry key. // Key returns BTree entry key.
...@@ -583,7 +586,7 @@ func (bt *btreeState) PySetState(pystate interface{}) (err error) { ...@@ -583,7 +586,7 @@ func (bt *btreeState) PySetState(pystate interface{}) (err error) {
var kprev int64 var kprev int64
var childrenKind int // 1 - BTree, 2 - Bucket var childrenKind int // 1 - BTree, 2 - Bucket
for i, idx := 0, 0; i < n; i++ { for i, idx := 0, 0; i < n; i++ {
key := int64(math.Min<Key>) // KEY(-∞) (qualifies for ≤) key := int64(_KeyMin) // KEY(-∞) (qualifies for ≤)
if i > 0 { if i > 0 {
// key[0] is unused and not saved // key[0] is unused and not saved
key, ok = t[idx].(int64) // XXX Xint key, ok = t[idx].(int64) // XXX Xint
......
...@@ -28,6 +28,8 @@ out=$3 ...@@ -28,6 +28,8 @@ out=$3
kind=${KIND,,} # IO -> io kind=${KIND,,} # IO -> io
Key=${KEY^} Key=${KEY^}
KEYKIND=${KIND:0:1} # IO -> I
input=$(dirname $0)/btree.go.in input=$(dirname $0)/btree.go.in
echo "// Code generated by gen-btree; DO NOT EDIT." >$out echo "// Code generated by gen-btree; DO NOT EDIT." >$out
...@@ -45,4 +47,6 @@ sed \ ...@@ -45,4 +47,6 @@ sed \
-e "s/\bBucketEntry\b/${KIND}BucketEntry/g" \ -e "s/\bBucketEntry\b/${KIND}BucketEntry/g" \
-e "s/\bbtreeState\b/${kind}btreeState/g" \ -e "s/\bbtreeState\b/${kind}btreeState/g" \
-e "s/\bbucketState\b/${kind}bucketState/g" \ -e "s/\bbucketState\b/${kind}bucketState/g" \
-e "s/\b_KeyMin\b/_${KEYKIND}KeyMin/g" \
-e "s/\b_KeyMax\b/_${KEYKIND}KeyMax/g" \
$input >>$out $input >>$out
...@@ -104,6 +104,9 @@ type IOBucketEntry struct { ...@@ -104,6 +104,9 @@ type IOBucketEntry struct {
value interface{} value interface{}
} }
const _IKeyMin int32 = math.MinInt32
const _IKeyMax int32 = math.MaxInt32
// ---- access []entry ---- // ---- access []entry ----
// Key returns IOBTree entry key. // Key returns IOBTree entry key.
...@@ -585,7 +588,7 @@ func (bt *iobtreeState) PySetState(pystate interface{}) (err error) { ...@@ -585,7 +588,7 @@ func (bt *iobtreeState) PySetState(pystate interface{}) (err error) {
var kprev int64 var kprev int64
var childrenKind int // 1 - IOBTree, 2 - IOBucket var childrenKind int // 1 - IOBTree, 2 - IOBucket
for i, idx := 0, 0; i < n; i++ { for i, idx := 0, 0; i < n; i++ {
key := int64(math.MinInt32) // int32(-∞) (qualifies for ≤) key := int64(_IKeyMin) // int32(-∞) (qualifies for ≤)
if i > 0 { if i > 0 {
// key[0] is unused and not saved // key[0] is unused and not saved
key, ok = t[idx].(int64) // XXX Xint key, ok = t[idx].(int64) // XXX Xint
......
...@@ -104,6 +104,9 @@ type LOBucketEntry struct { ...@@ -104,6 +104,9 @@ type LOBucketEntry struct {
value interface{} value interface{}
} }
const _LKeyMin int64 = math.MinInt64
const _LKeyMax int64 = math.MaxInt64
// ---- access []entry ---- // ---- access []entry ----
// Key returns LOBTree entry key. // Key returns LOBTree entry key.
...@@ -585,7 +588,7 @@ func (bt *lobtreeState) PySetState(pystate interface{}) (err error) { ...@@ -585,7 +588,7 @@ func (bt *lobtreeState) PySetState(pystate interface{}) (err error) {
var kprev int64 var kprev int64
var childrenKind int // 1 - LOBTree, 2 - LOBucket var childrenKind int // 1 - LOBTree, 2 - LOBucket
for i, idx := 0, 0; i < n; i++ { for i, idx := 0, 0; i < n; i++ {
key := int64(math.MinInt64) // int64(-∞) (qualifies for ≤) key := int64(_LKeyMin) // int64(-∞) (qualifies for ≤)
if i > 0 { if i > 0 {
// key[0] is unused and not saved // key[0] is unused and not saved
key, ok = t[idx].(int64) // XXX Xint key, ok = t[idx].(int64) // XXX Xint
......
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