Destutter graph/...
This commit is contained in:
parent
913d567ae1
commit
40f3363cde
20 changed files with 188 additions and 189 deletions
|
|
@ -19,26 +19,26 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
leveldb_it "github.com/syndtr/goleveldb/leveldb/iterator"
|
||||
leveldb_opt "github.com/syndtr/goleveldb/leveldb/opt"
|
||||
"github.com/syndtr/goleveldb/leveldb/iterator"
|
||||
"github.com/syndtr/goleveldb/leveldb/opt"
|
||||
|
||||
"github.com/google/cayley/graph"
|
||||
)
|
||||
|
||||
type LevelDBAllIterator struct {
|
||||
type AllIterator struct {
|
||||
graph.BaseIterator
|
||||
prefix []byte
|
||||
dir string
|
||||
open bool
|
||||
it leveldb_it.Iterator
|
||||
ts *LevelDBTripleStore
|
||||
ro *leveldb_opt.ReadOptions
|
||||
it iterator.Iterator
|
||||
ts *TripleStore
|
||||
ro *opt.ReadOptions
|
||||
}
|
||||
|
||||
func NewLevelDBAllIterator(prefix, dir string, ts *LevelDBTripleStore) *LevelDBAllIterator {
|
||||
var it LevelDBAllIterator
|
||||
func NewLevelDBAllIterator(prefix, dir string, ts *TripleStore) *AllIterator {
|
||||
var it AllIterator
|
||||
graph.BaseIteratorInit(&it.BaseIterator)
|
||||
it.ro = &leveldb_opt.ReadOptions{}
|
||||
it.ro = &opt.ReadOptions{}
|
||||
it.ro.DontFillCache = true
|
||||
it.it = ts.db.NewIterator(nil, it.ro)
|
||||
it.prefix = []byte(prefix)
|
||||
|
|
@ -53,7 +53,7 @@ func NewLevelDBAllIterator(prefix, dir string, ts *LevelDBTripleStore) *LevelDBA
|
|||
return &it
|
||||
}
|
||||
|
||||
func (a *LevelDBAllIterator) Reset() {
|
||||
func (a *AllIterator) Reset() {
|
||||
if !a.open {
|
||||
a.it = a.ts.db.NewIterator(nil, a.ro)
|
||||
a.open = true
|
||||
|
|
@ -65,13 +65,13 @@ func (a *LevelDBAllIterator) Reset() {
|
|||
}
|
||||
}
|
||||
|
||||
func (a *LevelDBAllIterator) Clone() graph.Iterator {
|
||||
func (a *AllIterator) Clone() graph.Iterator {
|
||||
out := NewLevelDBAllIterator(string(a.prefix), a.dir, a.ts)
|
||||
out.CopyTagsFrom(a)
|
||||
return out
|
||||
}
|
||||
|
||||
func (a *LevelDBAllIterator) Next() (graph.TSVal, bool) {
|
||||
func (a *AllIterator) Next() (graph.TSVal, bool) {
|
||||
if !a.open {
|
||||
a.Last = nil
|
||||
return nil, false
|
||||
|
|
@ -91,19 +91,19 @@ func (a *LevelDBAllIterator) Next() (graph.TSVal, bool) {
|
|||
return out, true
|
||||
}
|
||||
|
||||
func (a *LevelDBAllIterator) Check(v graph.TSVal) bool {
|
||||
func (a *AllIterator) Check(v graph.TSVal) bool {
|
||||
a.Last = v
|
||||
return true
|
||||
}
|
||||
|
||||
func (lit *LevelDBAllIterator) Close() {
|
||||
func (lit *AllIterator) Close() {
|
||||
if lit.open {
|
||||
lit.it.Release()
|
||||
lit.open = false
|
||||
}
|
||||
}
|
||||
|
||||
func (a *LevelDBAllIterator) Size() (int64, bool) {
|
||||
func (a *AllIterator) Size() (int64, bool) {
|
||||
size, err := a.ts.GetApproximateSizeForPrefix(a.prefix)
|
||||
if err == nil {
|
||||
return size, false
|
||||
|
|
@ -112,19 +112,19 @@ func (a *LevelDBAllIterator) Size() (int64, bool) {
|
|||
return int64(^uint64(0) >> 1), false
|
||||
}
|
||||
|
||||
func (lit *LevelDBAllIterator) DebugString(indent int) string {
|
||||
func (lit *AllIterator) DebugString(indent int) string {
|
||||
size, _ := lit.Size()
|
||||
return fmt.Sprintf("%s(%s tags: %v leveldb size:%d %s %p)", strings.Repeat(" ", indent), lit.Type(), lit.Tags(), size, lit.dir, lit)
|
||||
}
|
||||
|
||||
func (lit *LevelDBAllIterator) Type() string { return "all" }
|
||||
func (lit *LevelDBAllIterator) Sorted() bool { return false }
|
||||
func (lit *AllIterator) Type() string { return "all" }
|
||||
func (lit *AllIterator) Sorted() bool { return false }
|
||||
|
||||
func (lit *LevelDBAllIterator) Optimize() (graph.Iterator, bool) {
|
||||
func (lit *AllIterator) Optimize() (graph.Iterator, bool) {
|
||||
return lit, false
|
||||
}
|
||||
|
||||
func (lit *LevelDBAllIterator) GetStats() *graph.IteratorStats {
|
||||
func (lit *AllIterator) GetStats() *graph.IteratorStats {
|
||||
s, _ := lit.Size()
|
||||
return &graph.IteratorStats{
|
||||
CheckCost: 1,
|
||||
|
|
|
|||
|
|
@ -16,30 +16,29 @@ package leveldb
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
_ "encoding/binary"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
leveldb_it "github.com/syndtr/goleveldb/leveldb/iterator"
|
||||
leveldb_opt "github.com/syndtr/goleveldb/leveldb/opt"
|
||||
"github.com/syndtr/goleveldb/leveldb/iterator"
|
||||
"github.com/syndtr/goleveldb/leveldb/opt"
|
||||
|
||||
"github.com/google/cayley/graph"
|
||||
)
|
||||
|
||||
type LevelDBIterator struct {
|
||||
type Iterator struct {
|
||||
graph.BaseIterator
|
||||
nextPrefix []byte
|
||||
checkId []byte
|
||||
dir string
|
||||
open bool
|
||||
it leveldb_it.Iterator
|
||||
ts *LevelDBTripleStore
|
||||
ro *leveldb_opt.ReadOptions
|
||||
it iterator.Iterator
|
||||
ts *TripleStore
|
||||
ro *opt.ReadOptions
|
||||
originalPrefix string
|
||||
}
|
||||
|
||||
func NewLevelDBIterator(prefix, dir string, value graph.TSVal, ts *LevelDBTripleStore) *LevelDBIterator {
|
||||
var it LevelDBIterator
|
||||
func NewIterator(prefix, dir string, value graph.TSVal, ts *TripleStore) *Iterator {
|
||||
var it Iterator
|
||||
graph.BaseIteratorInit(&it.BaseIterator)
|
||||
it.checkId = value.([]byte)
|
||||
it.dir = dir
|
||||
|
|
@ -47,7 +46,7 @@ func NewLevelDBIterator(prefix, dir string, value graph.TSVal, ts *LevelDBTriple
|
|||
it.nextPrefix = make([]byte, 0, 2+ts.hasher.Size())
|
||||
it.nextPrefix = append(it.nextPrefix, []byte(prefix)...)
|
||||
it.nextPrefix = append(it.nextPrefix, []byte(it.checkId[1:])...)
|
||||
it.ro = &leveldb_opt.ReadOptions{}
|
||||
it.ro = &opt.ReadOptions{}
|
||||
it.ro.DontFillCache = true
|
||||
it.it = ts.db.NewIterator(nil, it.ro)
|
||||
it.open = true
|
||||
|
|
@ -60,7 +59,7 @@ func NewLevelDBIterator(prefix, dir string, value graph.TSVal, ts *LevelDBTriple
|
|||
return &it
|
||||
}
|
||||
|
||||
func (lit *LevelDBIterator) Reset() {
|
||||
func (lit *Iterator) Reset() {
|
||||
if !lit.open {
|
||||
lit.it = lit.ts.db.NewIterator(nil, lit.ro)
|
||||
lit.open = true
|
||||
|
|
@ -72,20 +71,20 @@ func (lit *LevelDBIterator) Reset() {
|
|||
}
|
||||
}
|
||||
|
||||
func (lit *LevelDBIterator) Clone() graph.Iterator {
|
||||
out := NewLevelDBIterator(lit.originalPrefix, lit.dir, lit.checkId, lit.ts)
|
||||
func (lit *Iterator) Clone() graph.Iterator {
|
||||
out := NewIterator(lit.originalPrefix, lit.dir, lit.checkId, lit.ts)
|
||||
out.CopyTagsFrom(lit)
|
||||
return out
|
||||
}
|
||||
|
||||
func (lit *LevelDBIterator) Close() {
|
||||
func (lit *Iterator) Close() {
|
||||
if lit.open {
|
||||
lit.it.Release()
|
||||
lit.open = false
|
||||
}
|
||||
}
|
||||
|
||||
func (lit *LevelDBIterator) Next() (graph.TSVal, bool) {
|
||||
func (lit *Iterator) Next() (graph.TSVal, bool) {
|
||||
if lit.it == nil {
|
||||
lit.Last = nil
|
||||
return nil, false
|
||||
|
|
@ -114,7 +113,7 @@ func (lit *LevelDBIterator) Next() (graph.TSVal, bool) {
|
|||
return nil, false
|
||||
}
|
||||
|
||||
func GetPositionFromPrefix(prefix []byte, dir string, ts *LevelDBTripleStore) int {
|
||||
func GetPositionFromPrefix(prefix []byte, dir string, ts *TripleStore) int {
|
||||
if bytes.Equal(prefix, []byte("sp")) {
|
||||
switch dir {
|
||||
case "s":
|
||||
|
|
@ -166,7 +165,7 @@ func GetPositionFromPrefix(prefix []byte, dir string, ts *LevelDBTripleStore) in
|
|||
panic("Notreached")
|
||||
}
|
||||
|
||||
func (lit *LevelDBIterator) Check(v graph.TSVal) bool {
|
||||
func (lit *Iterator) Check(v graph.TSVal) bool {
|
||||
val := v.([]byte)
|
||||
if val[0] == 'z' {
|
||||
return false
|
||||
|
|
@ -186,23 +185,23 @@ func (lit *LevelDBIterator) Check(v graph.TSVal) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (lit *LevelDBIterator) Size() (int64, bool) {
|
||||
func (lit *Iterator) Size() (int64, bool) {
|
||||
return lit.ts.GetSizeFor(lit.checkId), true
|
||||
}
|
||||
|
||||
func (lit *LevelDBIterator) DebugString(indent int) string {
|
||||
func (lit *Iterator) DebugString(indent int) string {
|
||||
size, _ := lit.Size()
|
||||
return fmt.Sprintf("%s(%s %d tags: %v dir: %s size:%d %s)", strings.Repeat(" ", indent), lit.Type(), lit.GetUid(), lit.Tags(), lit.dir, size, lit.ts.GetNameFor(lit.checkId))
|
||||
}
|
||||
|
||||
func (lit *LevelDBIterator) Type() string { return "leveldb" }
|
||||
func (lit *LevelDBIterator) Sorted() bool { return false }
|
||||
func (lit *Iterator) Type() string { return "leveldb" }
|
||||
func (lit *Iterator) Sorted() bool { return false }
|
||||
|
||||
func (lit *LevelDBIterator) Optimize() (graph.Iterator, bool) {
|
||||
func (lit *Iterator) Optimize() (graph.Iterator, bool) {
|
||||
return lit, false
|
||||
}
|
||||
|
||||
func (lit *LevelDBIterator) GetStats() *graph.IteratorStats {
|
||||
func (lit *Iterator) GetStats() *graph.IteratorStats {
|
||||
s, _ := lit.Size()
|
||||
return &graph.IteratorStats{
|
||||
CheckCost: 1,
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ func TestCreateDatabase(t *testing.T) {
|
|||
ok := CreateNewLevelDB(tmpDir)
|
||||
So(ok, ShouldBeTrue)
|
||||
Convey("And has good defaults for a new database", func() {
|
||||
ts := NewDefaultLevelDBTripleStore(tmpDir, nil)
|
||||
ts := NewTripleStore(tmpDir, nil)
|
||||
So(ts, ShouldNotBeNil)
|
||||
So(ts.Size(), ShouldEqual, 0)
|
||||
ts.Close()
|
||||
|
|
@ -89,7 +89,7 @@ func TestCreateDatabase(t *testing.T) {
|
|||
Convey("Fails if it cannot create the database", func() {
|
||||
ok := CreateNewLevelDB("/dev/null/some terrible path")
|
||||
So(ok, ShouldBeFalse)
|
||||
So(func() { NewDefaultLevelDBTripleStore("/dev/null/some terrible path", nil) }, ShouldPanic)
|
||||
So(func() { NewTripleStore("/dev/null/some terrible path", nil) }, ShouldPanic)
|
||||
})
|
||||
|
||||
Reset(func() {
|
||||
|
|
@ -101,14 +101,14 @@ func TestCreateDatabase(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestLoadDatabase(t *testing.T) {
|
||||
var ts *LevelDBTripleStore
|
||||
var ts *TripleStore
|
||||
|
||||
Convey("Given a created database path", t, func() {
|
||||
tmpDir, _ := ioutil.TempDir(os.TempDir(), "cayley_test")
|
||||
t.Log(tmpDir)
|
||||
ok := CreateNewLevelDB(tmpDir)
|
||||
So(ok, ShouldBeTrue)
|
||||
ts = NewDefaultLevelDBTripleStore(tmpDir, nil)
|
||||
ts = NewTripleStore(tmpDir, nil)
|
||||
|
||||
Convey("Can load a single triple", func() {
|
||||
ts.AddTriple(graph.MakeTriple("Something", "points_to", "Something Else", "context"))
|
||||
|
|
@ -139,7 +139,7 @@ func TestLoadDatabase(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIterator(t *testing.T) {
|
||||
var ts *LevelDBTripleStore
|
||||
var ts *TripleStore
|
||||
|
||||
Convey("Given a prepared database", t, func() {
|
||||
tmpDir, _ := ioutil.TempDir(os.TempDir(), "cayley_test")
|
||||
|
|
@ -147,7 +147,7 @@ func TestIterator(t *testing.T) {
|
|||
defer os.RemoveAll(tmpDir)
|
||||
ok := CreateNewLevelDB(tmpDir)
|
||||
So(ok, ShouldBeTrue)
|
||||
ts = NewDefaultLevelDBTripleStore(tmpDir, nil)
|
||||
ts = NewTripleStore(tmpDir, nil)
|
||||
ts.AddTripleSet(makeTripleSet())
|
||||
var it graph.Iterator
|
||||
|
||||
|
|
@ -234,7 +234,7 @@ func TestIterator(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSetIterator(t *testing.T) {
|
||||
var ts *LevelDBTripleStore
|
||||
var ts *TripleStore
|
||||
var tmpDir string
|
||||
|
||||
Convey("Given a prepared database", t, func() {
|
||||
|
|
@ -243,7 +243,7 @@ func TestSetIterator(t *testing.T) {
|
|||
defer os.RemoveAll(tmpDir)
|
||||
ok := CreateNewLevelDB(tmpDir)
|
||||
So(ok, ShouldBeTrue)
|
||||
ts = NewDefaultLevelDBTripleStore(tmpDir, nil)
|
||||
ts = NewTripleStore(tmpDir, nil)
|
||||
ts.AddTripleSet(makeTripleSet())
|
||||
var it graph.Iterator
|
||||
|
||||
|
|
@ -383,7 +383,7 @@ func TestSetIterator(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestOptimize(t *testing.T) {
|
||||
var ts *LevelDBTripleStore
|
||||
var ts *TripleStore
|
||||
var lto graph.Iterator
|
||||
var tmpDir string
|
||||
|
||||
|
|
@ -393,7 +393,7 @@ func TestOptimize(t *testing.T) {
|
|||
defer os.RemoveAll(tmpDir)
|
||||
ok := CreateNewLevelDB(tmpDir)
|
||||
So(ok, ShouldBeTrue)
|
||||
ts = NewDefaultLevelDBTripleStore(tmpDir, nil)
|
||||
ts = NewTripleStore(tmpDir, nil)
|
||||
ts.AddTripleSet(makeTripleSet())
|
||||
|
||||
Convey("With an linksto-fixed pair", func() {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ import (
|
|||
const DefaultCacheSize = 2
|
||||
const DefaultWriteBufferSize = 20
|
||||
|
||||
type LevelDBTripleStore struct {
|
||||
type TripleStore struct {
|
||||
dbOpts *leveldb_opt.Options
|
||||
db *leveldb.DB
|
||||
path string
|
||||
|
|
@ -53,7 +53,7 @@ func CreateNewLevelDB(path string) bool {
|
|||
return false
|
||||
}
|
||||
defer db.Close()
|
||||
ts := &LevelDBTripleStore{}
|
||||
ts := &TripleStore{}
|
||||
ts.db = db
|
||||
ts.writeopts = &leveldb_opt.WriteOptions{
|
||||
Sync: true,
|
||||
|
|
@ -62,8 +62,8 @@ func CreateNewLevelDB(path string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func NewDefaultLevelDBTripleStore(path string, options graph.OptionsDict) *LevelDBTripleStore {
|
||||
var ts LevelDBTripleStore
|
||||
func NewTripleStore(path string, options graph.OptionsDict) *TripleStore {
|
||||
var ts TripleStore
|
||||
ts.path = path
|
||||
cache_size := DefaultCacheSize
|
||||
if val, ok := options.GetIntKey("cache_size_mb"); ok {
|
||||
|
|
@ -94,7 +94,7 @@ func NewDefaultLevelDBTripleStore(path string, options graph.OptionsDict) *Level
|
|||
return &ts
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) GetStats() string {
|
||||
func (ts *TripleStore) GetStats() string {
|
||||
out := ""
|
||||
stats, err := ts.db.GetProperty("leveldb.stats")
|
||||
if err == nil {
|
||||
|
|
@ -104,11 +104,11 @@ func (ts *LevelDBTripleStore) GetStats() string {
|
|||
return out
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) Size() int64 {
|
||||
func (ts *TripleStore) Size() int64 {
|
||||
return ts.size
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) createKeyFor(dir1, dir2, dir3 string, triple *graph.Triple) []byte {
|
||||
func (ts *TripleStore) createKeyFor(dir1, dir2, dir3 string, triple *graph.Triple) []byte {
|
||||
key := make([]byte, 0, 2+(ts.hasher.Size()*3))
|
||||
key = append(key, []byte(dir1+dir2)...)
|
||||
key = append(key, ts.convertStringToByteHash(triple.Get(dir1))...)
|
||||
|
|
@ -117,7 +117,7 @@ func (ts *LevelDBTripleStore) createKeyFor(dir1, dir2, dir3 string, triple *grap
|
|||
return key
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) createProvKeyFor(dir1, dir2, dir3 string, triple *graph.Triple) []byte {
|
||||
func (ts *TripleStore) createProvKeyFor(dir1, dir2, dir3 string, triple *graph.Triple) []byte {
|
||||
key := make([]byte, 0, 2+(ts.hasher.Size()*4))
|
||||
key = append(key, []byte("c"+dir1)...)
|
||||
key = append(key, ts.convertStringToByteHash(triple.Get("c"))...)
|
||||
|
|
@ -127,14 +127,14 @@ func (ts *LevelDBTripleStore) createProvKeyFor(dir1, dir2, dir3 string, triple *
|
|||
return key
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) createValueKeyFor(s string) []byte {
|
||||
func (ts *TripleStore) createValueKeyFor(s string) []byte {
|
||||
key := make([]byte, 0, 1+ts.hasher.Size())
|
||||
key = append(key, []byte("z")...)
|
||||
key = append(key, ts.convertStringToByteHash(s)...)
|
||||
return key
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) AddTriple(t *graph.Triple) {
|
||||
func (ts *TripleStore) AddTriple(t *graph.Triple) {
|
||||
batch := &leveldb.Batch{}
|
||||
ts.buildWrite(batch, t)
|
||||
err := ts.db.Write(batch, ts.writeopts)
|
||||
|
|
@ -145,7 +145,7 @@ func (ts *LevelDBTripleStore) AddTriple(t *graph.Triple) {
|
|||
ts.size++
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) RemoveTriple(t *graph.Triple) {
|
||||
func (ts *TripleStore) RemoveTriple(t *graph.Triple) {
|
||||
_, err := ts.db.Get(ts.createKeyFor("s", "p", "o", t), ts.readopts)
|
||||
if err != nil && err != leveldb.ErrNotFound {
|
||||
glog.Errorf("Couldn't access DB to confirm deletion")
|
||||
|
|
@ -174,7 +174,7 @@ func (ts *LevelDBTripleStore) RemoveTriple(t *graph.Triple) {
|
|||
ts.size--
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) buildTripleWrite(batch *leveldb.Batch, t *graph.Triple) {
|
||||
func (ts *TripleStore) buildTripleWrite(batch *leveldb.Batch, t *graph.Triple) {
|
||||
bytes, err := json.Marshal(*t)
|
||||
if err != nil {
|
||||
glog.Errorf("Couldn't write to buffer for triple %s\n %s\n", t.ToString(), err)
|
||||
|
|
@ -188,7 +188,7 @@ func (ts *LevelDBTripleStore) buildTripleWrite(batch *leveldb.Batch, t *graph.Tr
|
|||
}
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) buildWrite(batch *leveldb.Batch, t *graph.Triple) {
|
||||
func (ts *TripleStore) buildWrite(batch *leveldb.Batch, t *graph.Triple) {
|
||||
ts.buildTripleWrite(batch, t)
|
||||
ts.UpdateValueKeyBy(t.Get("s"), 1, nil)
|
||||
ts.UpdateValueKeyBy(t.Get("p"), 1, nil)
|
||||
|
|
@ -203,7 +203,7 @@ type ValueData struct {
|
|||
Size int64
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) UpdateValueKeyBy(name string, amount int, batch *leveldb.Batch) {
|
||||
func (ts *TripleStore) UpdateValueKeyBy(name string, amount int, batch *leveldb.Batch) {
|
||||
value := &ValueData{name, int64(amount)}
|
||||
key := ts.createValueKeyFor(name)
|
||||
b, err := ts.db.Get(key, ts.readopts)
|
||||
|
|
@ -249,7 +249,7 @@ func (ts *LevelDBTripleStore) UpdateValueKeyBy(name string, amount int, batch *l
|
|||
}
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) AddTripleSet(t_s []*graph.Triple) {
|
||||
func (ts *TripleStore) AddTripleSet(t_s []*graph.Triple) {
|
||||
batch := &leveldb.Batch{}
|
||||
newTs := len(t_s)
|
||||
resizeMap := make(map[string]int)
|
||||
|
|
@ -273,7 +273,7 @@ func (ts *LevelDBTripleStore) AddTripleSet(t_s []*graph.Triple) {
|
|||
ts.size += int64(newTs)
|
||||
}
|
||||
|
||||
func (ldbts *LevelDBTripleStore) Close() {
|
||||
func (ldbts *TripleStore) Close() {
|
||||
buf := new(bytes.Buffer)
|
||||
err := binary.Write(buf, binary.LittleEndian, ldbts.size)
|
||||
if err == nil {
|
||||
|
|
@ -288,7 +288,7 @@ func (ldbts *LevelDBTripleStore) Close() {
|
|||
ldbts.open = false
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) GetTriple(k graph.TSVal) *graph.Triple {
|
||||
func (ts *TripleStore) GetTriple(k graph.TSVal) *graph.Triple {
|
||||
var triple graph.Triple
|
||||
b, err := ts.db.Get(k.([]byte), ts.readopts)
|
||||
if err != nil && err != leveldb.ErrNotFound {
|
||||
|
|
@ -307,7 +307,7 @@ func (ts *LevelDBTripleStore) GetTriple(k graph.TSVal) *graph.Triple {
|
|||
return &triple
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) convertStringToByteHash(s string) []byte {
|
||||
func (ts *TripleStore) convertStringToByteHash(s string) []byte {
|
||||
ts.hasher.Reset()
|
||||
key := make([]byte, 0, ts.hasher.Size())
|
||||
ts.hasher.Write([]byte(s))
|
||||
|
|
@ -315,11 +315,11 @@ func (ts *LevelDBTripleStore) convertStringToByteHash(s string) []byte {
|
|||
return key
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) GetIdFor(s string) graph.TSVal {
|
||||
func (ts *TripleStore) GetIdFor(s string) graph.TSVal {
|
||||
return ts.createValueKeyFor(s)
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) getValueData(value_key []byte) ValueData {
|
||||
func (ts *TripleStore) getValueData(value_key []byte) ValueData {
|
||||
var out ValueData
|
||||
if glog.V(3) {
|
||||
glog.V(3).Infof("%s %v\n", string(value_key[0]), value_key)
|
||||
|
|
@ -339,7 +339,7 @@ func (ts *LevelDBTripleStore) getValueData(value_key []byte) ValueData {
|
|||
return out
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) GetNameFor(k graph.TSVal) string {
|
||||
func (ts *TripleStore) GetNameFor(k graph.TSVal) string {
|
||||
if k == nil {
|
||||
glog.V(2).Infoln("k was nil")
|
||||
return ""
|
||||
|
|
@ -347,14 +347,14 @@ func (ts *LevelDBTripleStore) GetNameFor(k graph.TSVal) string {
|
|||
return ts.getValueData(k.([]byte)).Name
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) GetSizeFor(k graph.TSVal) int64 {
|
||||
func (ts *TripleStore) GetSizeFor(k graph.TSVal) int64 {
|
||||
if k == nil {
|
||||
return 0
|
||||
}
|
||||
return int64(ts.getValueData(k.([]byte)).Size)
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) getSize() {
|
||||
func (ts *TripleStore) getSize() {
|
||||
var size int64
|
||||
b, err := ts.db.Get([]byte("__size"), ts.readopts)
|
||||
if err != nil && err != leveldb.ErrNotFound {
|
||||
|
|
@ -373,7 +373,7 @@ func (ts *LevelDBTripleStore) getSize() {
|
|||
ts.size = size
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) GetApproximateSizeForPrefix(pre []byte) (int64, error) {
|
||||
func (ts *TripleStore) GetApproximateSizeForPrefix(pre []byte) (int64, error) {
|
||||
limit := make([]byte, len(pre))
|
||||
copy(limit, pre)
|
||||
end := len(limit) - 1
|
||||
|
|
@ -388,29 +388,29 @@ func (ts *LevelDBTripleStore) GetApproximateSizeForPrefix(pre []byte) (int64, er
|
|||
return 0, nil
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) GetTripleIterator(dir string, val graph.TSVal) graph.Iterator {
|
||||
func (ts *TripleStore) GetTripleIterator(dir string, val graph.TSVal) graph.Iterator {
|
||||
switch dir {
|
||||
case "s":
|
||||
return NewLevelDBIterator("sp", "s", val, ts)
|
||||
return NewIterator("sp", "s", val, ts)
|
||||
case "p":
|
||||
return NewLevelDBIterator("po", "p", val, ts)
|
||||
return NewIterator("po", "p", val, ts)
|
||||
case "o":
|
||||
return NewLevelDBIterator("os", "o", val, ts)
|
||||
return NewIterator("os", "o", val, ts)
|
||||
case "c":
|
||||
return NewLevelDBIterator("cp", "c", val, ts)
|
||||
return NewIterator("cp", "c", val, ts)
|
||||
}
|
||||
panic("Notreached " + dir)
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) GetNodesAllIterator() graph.Iterator {
|
||||
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
|
||||
return NewLevelDBAllIterator("z", "v", ts)
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) GetTriplesAllIterator() graph.Iterator {
|
||||
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
|
||||
return NewLevelDBAllIterator("po", "p", ts)
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) GetTripleDirection(val graph.TSVal, direction string) graph.TSVal {
|
||||
func (ts *TripleStore) GetTripleDirection(val graph.TSVal, direction string) graph.TSVal {
|
||||
v := val.([]uint8)
|
||||
offset := GetPositionFromPrefix(v[0:2], direction, ts)
|
||||
if offset != -1 {
|
||||
|
|
@ -424,6 +424,6 @@ func compareBytes(a, b graph.TSVal) bool {
|
|||
return bytes.Equal(a.([]uint8), b.([]uint8))
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) MakeFixed() *graph.FixedIterator {
|
||||
func (ts *TripleStore) MakeFixed() *graph.FixedIterator {
|
||||
return graph.NewFixedIteratorWithCompare(compareBytes)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import (
|
|||
"github.com/google/cayley/graph"
|
||||
)
|
||||
|
||||
func (ts *LevelDBTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
|
||||
func (ts *TripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
|
||||
switch it.Type() {
|
||||
case "linksto":
|
||||
return ts.optimizeLinksTo(it.(*graph.LinksToIterator))
|
||||
|
|
@ -27,7 +27,7 @@ func (ts *LevelDBTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterato
|
|||
return it, false
|
||||
}
|
||||
|
||||
func (ts *LevelDBTripleStore) optimizeLinksTo(it *graph.LinksToIterator) (graph.Iterator, bool) {
|
||||
func (ts *TripleStore) optimizeLinksTo(it *graph.LinksToIterator) (graph.Iterator, bool) {
|
||||
l := it.GetSubIterators()
|
||||
if l.Len() != 1 {
|
||||
return it, false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue