Canonicalise leveldb receiver names

Also remove redundant LevelDB infix missed previously.
This commit is contained in:
kortschak 2014-06-28 21:43:59 +09:30
parent 60d5c60817
commit b1ad887c78
3 changed files with 90 additions and 90 deletions

View file

@ -35,7 +35,7 @@ type AllIterator struct {
ro *opt.ReadOptions
}
func NewLevelDBAllIterator(prefix, dir string, ts *TripleStore) *AllIterator {
func NewAllIterator(prefix, dir string, ts *TripleStore) *AllIterator {
var it AllIterator
graph.BaseIteratorInit(&it.BaseIterator)
it.ro = &opt.ReadOptions{}
@ -53,46 +53,46 @@ func NewLevelDBAllIterator(prefix, dir string, ts *TripleStore) *AllIterator {
return &it
}
func (a *AllIterator) Reset() {
if !a.open {
a.it = a.ts.db.NewIterator(nil, a.ro)
a.open = true
func (it *AllIterator) Reset() {
if !it.open {
it.it = it.ts.db.NewIterator(nil, it.ro)
it.open = true
}
a.it.Seek(a.prefix)
if !a.it.Valid() {
a.open = false
a.it.Release()
it.it.Seek(it.prefix)
if !it.it.Valid() {
it.open = false
it.it.Release()
}
}
func (a *AllIterator) Clone() graph.Iterator {
out := NewLevelDBAllIterator(string(a.prefix), a.dir, a.ts)
out.CopyTagsFrom(a)
func (it *AllIterator) Clone() graph.Iterator {
out := NewAllIterator(string(it.prefix), it.dir, it.ts)
out.CopyTagsFrom(it)
return out
}
func (a *AllIterator) Next() (graph.TSVal, bool) {
if !a.open {
a.Last = nil
func (it *AllIterator) Next() (graph.TSVal, bool) {
if !it.open {
it.Last = nil
return nil, false
}
var out []byte
out = make([]byte, len(a.it.Key()))
copy(out, a.it.Key())
a.it.Next()
if !a.it.Valid() {
a.Close()
out = make([]byte, len(it.it.Key()))
copy(out, it.it.Key())
it.it.Next()
if !it.it.Valid() {
it.Close()
}
if !bytes.HasPrefix(out, a.prefix) {
a.Close()
if !bytes.HasPrefix(out, it.prefix) {
it.Close()
return nil, false
}
a.Last = out
it.Last = out
return out, true
}
func (a *AllIterator) Check(v graph.TSVal) bool {
a.Last = v
func (it *AllIterator) Check(v graph.TSVal) bool {
it.Last = v
return true
}
@ -103,8 +103,8 @@ func (lit *AllIterator) Close() {
}
}
func (a *AllIterator) Size() (int64, bool) {
size, err := a.ts.GetApproximateSizeForPrefix(a.prefix)
func (it *AllIterator) Size() (int64, bool) {
size, err := it.ts.GetApproximateSizeForPrefix(it.prefix)
if err == nil {
return size, false
}
@ -112,20 +112,20 @@ func (a *AllIterator) Size() (int64, bool) {
return int64(^uint64(0) >> 1), false
}
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 (it *AllIterator) DebugString(indent int) string {
size, _ := it.Size()
return fmt.Sprintf("%s(%s tags: %v leveldb size:%d %s %p)", strings.Repeat(" ", indent), it.Type(), it.Tags(), size, it.dir, it)
}
func (lit *AllIterator) Type() string { return "all" }
func (lit *AllIterator) Sorted() bool { return false }
func (it *AllIterator) Type() string { return "all" }
func (it *AllIterator) Sorted() bool { return false }
func (lit *AllIterator) Optimize() (graph.Iterator, bool) {
return lit, false
func (it *AllIterator) Optimize() (graph.Iterator, bool) {
return it, false
}
func (lit *AllIterator) GetStats() *graph.IteratorStats {
s, _ := lit.Size()
func (it *AllIterator) GetStats() *graph.IteratorStats {
s, _ := it.Size()
return &graph.IteratorStats{
CheckCost: 1,
NextCost: 2,

View file

@ -59,57 +59,57 @@ func NewIterator(prefix, dir string, value graph.TSVal, ts *TripleStore) *Iterat
return &it
}
func (lit *Iterator) Reset() {
if !lit.open {
lit.it = lit.ts.db.NewIterator(nil, lit.ro)
lit.open = true
func (it *Iterator) Reset() {
if !it.open {
it.it = it.ts.db.NewIterator(nil, it.ro)
it.open = true
}
ok := lit.it.Seek(lit.nextPrefix)
ok := it.it.Seek(it.nextPrefix)
if !ok {
lit.open = false
lit.it.Release()
it.open = false
it.it.Release()
}
}
func (lit *Iterator) Clone() graph.Iterator {
out := NewIterator(lit.originalPrefix, lit.dir, lit.checkId, lit.ts)
out.CopyTagsFrom(lit)
func (it *Iterator) Clone() graph.Iterator {
out := NewIterator(it.originalPrefix, it.dir, it.checkId, it.ts)
out.CopyTagsFrom(it)
return out
}
func (lit *Iterator) Close() {
if lit.open {
lit.it.Release()
lit.open = false
func (it *Iterator) Close() {
if it.open {
it.it.Release()
it.open = false
}
}
func (lit *Iterator) Next() (graph.TSVal, bool) {
if lit.it == nil {
lit.Last = nil
func (it *Iterator) Next() (graph.TSVal, bool) {
if it.it == nil {
it.Last = nil
return nil, false
}
if !lit.open {
lit.Last = nil
if !it.open {
it.Last = nil
return nil, false
}
if !lit.it.Valid() {
lit.Last = nil
lit.Close()
if !it.it.Valid() {
it.Last = nil
it.Close()
return nil, false
}
if bytes.HasPrefix(lit.it.Key(), lit.nextPrefix) {
out := make([]byte, len(lit.it.Key()))
copy(out, lit.it.Key())
lit.Last = out
ok := lit.it.Next()
if bytes.HasPrefix(it.it.Key(), it.nextPrefix) {
out := make([]byte, len(it.it.Key()))
copy(out, it.it.Key())
it.Last = out
ok := it.it.Next()
if !ok {
lit.Close()
it.Close()
}
return out, true
}
lit.Close()
lit.Last = nil
it.Close()
it.Last = nil
return nil, false
}
@ -165,44 +165,44 @@ func GetPositionFromPrefix(prefix []byte, dir string, ts *TripleStore) int {
panic("Notreached")
}
func (lit *Iterator) Check(v graph.TSVal) bool {
func (it *Iterator) Check(v graph.TSVal) bool {
val := v.([]byte)
if val[0] == 'z' {
return false
}
offset := GetPositionFromPrefix(val[0:2], lit.dir, lit.ts)
offset := GetPositionFromPrefix(val[0:2], it.dir, it.ts)
if offset != -1 {
if bytes.HasPrefix(val[offset:], lit.checkId[1:]) {
if bytes.HasPrefix(val[offset:], it.checkId[1:]) {
return true
}
} else {
nameForDir := lit.ts.GetTriple(v).Get(lit.dir)
hashForDir := lit.ts.GetIdFor(nameForDir).([]byte)
if bytes.Equal(hashForDir, lit.checkId) {
nameForDir := it.ts.GetTriple(v).Get(it.dir)
hashForDir := it.ts.GetIdFor(nameForDir).([]byte)
if bytes.Equal(hashForDir, it.checkId) {
return true
}
}
return false
}
func (lit *Iterator) Size() (int64, bool) {
return lit.ts.GetSizeFor(lit.checkId), true
func (it *Iterator) Size() (int64, bool) {
return it.ts.GetSizeFor(it.checkId), true
}
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 (it *Iterator) DebugString(indent int) string {
size, _ := it.Size()
return fmt.Sprintf("%s(%s %d tags: %v dir: %s size:%d %s)", strings.Repeat(" ", indent), it.Type(), it.GetUid(), it.Tags(), it.dir, size, it.ts.GetNameFor(it.checkId))
}
func (lit *Iterator) Type() string { return "leveldb" }
func (lit *Iterator) Sorted() bool { return false }
func (it *Iterator) Type() string { return "leveldb" }
func (it *Iterator) Sorted() bool { return false }
func (lit *Iterator) Optimize() (graph.Iterator, bool) {
return lit, false
func (it *Iterator) Optimize() (graph.Iterator, bool) {
return it, false
}
func (lit *Iterator) GetStats() *graph.IteratorStats {
s, _ := lit.Size()
func (it *Iterator) GetStats() *graph.IteratorStats {
s, _ := it.Size()
return &graph.IteratorStats{
CheckCost: 1,
NextCost: 2,

View file

@ -273,19 +273,19 @@ func (ts *TripleStore) AddTripleSet(t_s []*graph.Triple) {
ts.size += int64(newTs)
}
func (ldbts *TripleStore) Close() {
func (ts *TripleStore) Close() {
buf := new(bytes.Buffer)
err := binary.Write(buf, binary.LittleEndian, ldbts.size)
err := binary.Write(buf, binary.LittleEndian, ts.size)
if err == nil {
werr := ldbts.db.Put([]byte("__size"), buf.Bytes(), ldbts.writeopts)
werr := ts.db.Put([]byte("__size"), buf.Bytes(), ts.writeopts)
if werr != nil {
glog.Errorf("Couldn't write size before closing!")
}
} else {
glog.Errorf("Couldn't convert size before closing!")
}
ldbts.db.Close()
ldbts.open = false
ts.db.Close()
ts.open = false
}
func (ts *TripleStore) GetTriple(k graph.TSVal) *graph.Triple {
@ -403,11 +403,11 @@ func (ts *TripleStore) GetTripleIterator(dir string, val graph.TSVal) graph.Iter
}
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
return NewLevelDBAllIterator("z", "v", ts)
return NewAllIterator("z", "v", ts)
}
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
return NewLevelDBAllIterator("po", "p", ts)
return NewAllIterator("po", "p", ts)
}
func (ts *TripleStore) GetTripleDirection(val graph.TSVal, direction string) graph.TSVal {