Commit 2dc1e2e0 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 1b3a514b
This diff is collapsed.
This diff is collapsed.
...@@ -33,7 +33,7 @@ import ( ...@@ -33,7 +33,7 @@ import (
// kv is one (key, value) pair. // kv is one (key, value) pair.
type kv struct { type kv struct {
key KEY key int64
value interface{} value interface{}
} }
...@@ -52,7 +52,7 @@ type testEntry struct { ...@@ -52,7 +52,7 @@ type testEntry struct {
// bmapping represents Get of Bucket or BTree. // bmapping represents Get of Bucket or BTree.
type bmapping interface { type bmapping interface {
Get(context.Context, KEY) (interface{}, bool, error) Get(context.Context, int64) (interface{}, bool, error)
} }
func TestBTree(t *testing.T) { func TestBTree(t *testing.T) {
...@@ -89,11 +89,11 @@ func TestBTree(t *testing.T) { ...@@ -89,11 +89,11 @@ func TestBTree(t *testing.T) {
want := "" want := ""
switch tt.kind { switch tt.kind {
case kindBucket: case kindBucket:
if _, ok = obj.(*Bucket); !ok { if _, ok = obj.(*LOBucket); !ok {
want = "Bucket" want = "Bucket"
} }
case kindBTree: case kindBTree:
if _, ok = obj.(*BTree); !ok { if _, ok = obj.(*LOBTree); !ok {
want = "BTree" want = "BTree"
} }
default: default:
...@@ -132,12 +132,12 @@ func TestBTree(t *testing.T) { ...@@ -132,12 +132,12 @@ func TestBTree(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
B3, ok := xB3.(*BTree) B3, ok := xB3.(*LOBTree)
if !ok { if !ok {
t.Fatalf("B3: %v; got %T; want BTree", B3_oid, xB3) t.Fatalf("B3: %v; got %T; want BTree", B3_oid, xB3)
} }
for i := KEY(0); i <= B3_maxkey; i++ { for i := int64(0); i <= B3_maxkey; i++ {
v, ok, err := B3.Get(ctx, i) v, ok, err := B3.Get(ctx, i)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
...@@ -151,21 +151,21 @@ func TestBTree(t *testing.T) { ...@@ -151,21 +151,21 @@ func TestBTree(t *testing.T) {
} }
// verifyFirstBucket verifies that b.firstbucket is correct and returns it. // verifyFirstBucket verifies that b.firstbucket is correct and returns it.
var verifyFirstBucket func(b *BTree) *Bucket var verifyFirstBucket func(b *LOBTree) *LOBucket
verifyFirstBucket = func(b *BTree) *Bucket { verifyFirstBucket = func(b *LOBTree) *LOBucket {
err := b.PActivate(ctx); X(err) err := b.PActivate(ctx); X(err)
defer b.PDeactivate() defer b.PDeactivate()
var firstbucket *Bucket var firstbucket *LOBucket
switch child := b.data[0].child.(type) { switch child := b.data[0].child.(type) {
default: default:
t.Fatalf("btree(%s): child[0] is %T", b.POid(), b.data[0].child) t.Fatalf("btree(%s): child[0] is %T", b.POid(), b.data[0].child)
case *BTree: case *LOBTree:
firstbucket = verifyFirstBucket(child) firstbucket = verifyFirstBucket(child)
case *Bucket: case *LOBucket:
firstbucket = child firstbucket = child
} }
......
#!/bin/bash -e
# btree.go.in -> specialized with concrete types
# gen-btree KIND KEY out
# Copyright (C) 2017 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
KIND=$1
KEY=$2
out=$3
kind=${KIND,,} # IO -> io
input=$(dirname $0)/btree.go.in
echo "// Code generated by gen-btree; DO NOT EDIT." >$out
echo >>$out
sed \
-e "s/<kind>/$kind/g" \
-e "s/<KIND>/$KIND/g" \
-e "s/KEY/$KEY/g" \
-e "s/\bBTree\b/${KIND}BTree/g" \
-e "s/\bEntry\b/${KIND}Entry/g" \
-e "s/\bBucket\b/${KIND}Bucket/g" \
-e "s/\bBucketEntry\b/${KIND}BucketEntry/g" \
-e "s/\bbtreeState\b/${kind}btreeState/g" \
-e "s/\bbucketState\b/${kind}bucketState/g" \
$input >>$out
This diff is collapsed.
This diff is collapsed.
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