Reduce TripleStore interface names
This commit is contained in:
parent
8576f66d20
commit
b89d4f392c
29 changed files with 156 additions and 156 deletions
|
|
@ -177,8 +177,8 @@ func (it *Iterator) Check(v graph.TSVal) bool {
|
|||
return true
|
||||
}
|
||||
} else {
|
||||
nameForDir := it.ts.GetTriple(v).Get(it.dir)
|
||||
hashForDir := it.ts.GetIdFor(nameForDir).([]byte)
|
||||
nameForDir := it.ts.Triple(v).Get(it.dir)
|
||||
hashForDir := it.ts.ValueOf(nameForDir).([]byte)
|
||||
if bytes.Equal(hashForDir, it.checkId) {
|
||||
return true
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ func (it *Iterator) Size() (int64, bool) {
|
|||
|
||||
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.UID(), it.Tags(), it.dir, size, it.ts.GetNameFor(it.checkId))
|
||||
return fmt.Sprintf("%s(%s %d tags: %v dir: %s size:%d %s)", strings.Repeat(" ", indent), it.Type(), it.UID(), it.Tags(), it.dir, size, it.ts.NameOf(it.checkId))
|
||||
}
|
||||
|
||||
func (it *Iterator) Type() string { return "leveldb" }
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ func extractTripleFromIterator(ts graph.TripleStore, it graph.Iterator) []string
|
|||
if !ok {
|
||||
break
|
||||
}
|
||||
output = append(output, ts.GetTriple(val).String())
|
||||
output = append(output, ts.Triple(val).String())
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ func extractValuesFromIterator(ts graph.TripleStore, it graph.Iterator) []string
|
|||
if !ok {
|
||||
break
|
||||
}
|
||||
output = append(output, ts.GetNameFor(val))
|
||||
output = append(output, ts.NameOf(val))
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
|
@ -113,7 +113,7 @@ func TestLoadDatabase(t *testing.T) {
|
|||
|
||||
Convey("Can load a single triple", func() {
|
||||
ts.AddTriple(&graph.Triple{"Something", "points_to", "Something Else", "context"})
|
||||
So(ts.GetNameFor(ts.GetIdFor("Something")), ShouldEqual, "Something")
|
||||
So(ts.NameOf(ts.ValueOf("Something")), ShouldEqual, "Something")
|
||||
So(ts.Size(), ShouldEqual, 1)
|
||||
})
|
||||
|
||||
|
|
@ -121,12 +121,12 @@ func TestLoadDatabase(t *testing.T) {
|
|||
|
||||
ts.AddTripleSet(makeTripleSet())
|
||||
So(ts.Size(), ShouldEqual, 11)
|
||||
So(ts.GetSizeFor(ts.GetIdFor("B")), ShouldEqual, 5)
|
||||
So(ts.GetSizeFor(ts.ValueOf("B")), ShouldEqual, 5)
|
||||
|
||||
Convey("Can delete triples", func() {
|
||||
ts.RemoveTriple(&graph.Triple{"A", "follows", "B", ""})
|
||||
So(ts.Size(), ShouldEqual, 10)
|
||||
So(ts.GetSizeFor(ts.GetIdFor("B")), ShouldEqual, 4)
|
||||
So(ts.GetSizeFor(ts.ValueOf("B")), ShouldEqual, 4)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ func TestIterator(t *testing.T) {
|
|||
var it graph.Iterator
|
||||
|
||||
Convey("Can create an all iterator for nodes", func() {
|
||||
it = ts.GetNodesAllIterator()
|
||||
it = ts.NodesAllIterator()
|
||||
So(it, ShouldNotBeNil)
|
||||
|
||||
Convey("Has basics", func() {
|
||||
|
|
@ -192,9 +192,9 @@ func TestIterator(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Contains a couple nodes", func() {
|
||||
So(it.Check(ts.GetIdFor("A")), ShouldBeTrue)
|
||||
So(it.Check(ts.GetIdFor("cool")), ShouldBeTrue)
|
||||
//So(it.Check(ts.GetIdFor("baller")), ShouldBeFalse)
|
||||
So(it.Check(ts.ValueOf("A")), ShouldBeTrue)
|
||||
So(it.Check(ts.ValueOf("cool")), ShouldBeTrue)
|
||||
//So(it.Check(ts.ValueOf("baller")), ShouldBeFalse)
|
||||
})
|
||||
|
||||
Reset(func() {
|
||||
|
|
@ -203,7 +203,7 @@ func TestIterator(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Can create an all iterator for edges", func() {
|
||||
it := ts.GetTriplesAllIterator()
|
||||
it := ts.TriplesAllIterator()
|
||||
So(it, ShouldNotBeNil)
|
||||
Convey("Has basics", func() {
|
||||
size, accurate := it.Size()
|
||||
|
|
@ -217,7 +217,7 @@ func TestIterator(t *testing.T) {
|
|||
|
||||
Convey("Iterates an edge", func() {
|
||||
edge_val, _ := it.Next()
|
||||
triple := ts.GetTriple(edge_val)
|
||||
triple := ts.Triple(edge_val)
|
||||
set := makeTripleSet()
|
||||
var string_set []string
|
||||
for _, t := range set {
|
||||
|
|
@ -249,7 +249,7 @@ func TestSetIterator(t *testing.T) {
|
|||
var it graph.Iterator
|
||||
|
||||
Convey("Can create a subject iterator", func() {
|
||||
it = ts.GetTripleIterator(graph.Subject, ts.GetIdFor("C"))
|
||||
it = ts.TripleIterator(graph.Subject, ts.ValueOf("C"))
|
||||
|
||||
Convey("Containing the right things", func() {
|
||||
expected := []string{
|
||||
|
|
@ -264,7 +264,7 @@ func TestSetIterator(t *testing.T) {
|
|||
|
||||
Convey("And checkable", func() {
|
||||
and := iterator.NewAnd()
|
||||
and.AddSubIterator(ts.GetTriplesAllIterator())
|
||||
and.AddSubIterator(ts.TriplesAllIterator())
|
||||
and.AddSubIterator(it)
|
||||
|
||||
expected := []string{
|
||||
|
|
@ -283,7 +283,7 @@ func TestSetIterator(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Can create an object iterator", func() {
|
||||
it = ts.GetTripleIterator(graph.Object, ts.GetIdFor("F"))
|
||||
it = ts.TripleIterator(graph.Object, ts.ValueOf("F"))
|
||||
|
||||
Convey("Containing the right things", func() {
|
||||
expected := []string{
|
||||
|
|
@ -298,7 +298,7 @@ func TestSetIterator(t *testing.T) {
|
|||
|
||||
Convey("Mutually and-checkable", func() {
|
||||
and := iterator.NewAnd()
|
||||
and.AddSubIterator(ts.GetTripleIterator(graph.Subject, ts.GetIdFor("B")))
|
||||
and.AddSubIterator(ts.TripleIterator(graph.Subject, ts.ValueOf("B")))
|
||||
and.AddSubIterator(it)
|
||||
|
||||
expected := []string{
|
||||
|
|
@ -313,7 +313,7 @@ func TestSetIterator(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Can create a predicate iterator", func() {
|
||||
it = ts.GetTripleIterator(graph.Predicate, ts.GetIdFor("status"))
|
||||
it = ts.TripleIterator(graph.Predicate, ts.ValueOf("status"))
|
||||
|
||||
Convey("Containing the right things", func() {
|
||||
expected := []string{
|
||||
|
|
@ -330,7 +330,7 @@ func TestSetIterator(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Can create a provenance iterator", func() {
|
||||
it = ts.GetTripleIterator(graph.Provenance, ts.GetIdFor("status_graph"))
|
||||
it = ts.TripleIterator(graph.Provenance, ts.ValueOf("status_graph"))
|
||||
|
||||
Convey("Containing the right things", func() {
|
||||
expected := []string{
|
||||
|
|
@ -347,7 +347,7 @@ func TestSetIterator(t *testing.T) {
|
|||
Convey("Can be cross-checked", func() {
|
||||
and := iterator.NewAnd()
|
||||
// Order is important
|
||||
and.AddSubIterator(ts.GetTripleIterator(graph.Subject, ts.GetIdFor("B")))
|
||||
and.AddSubIterator(ts.TripleIterator(graph.Subject, ts.ValueOf("B")))
|
||||
and.AddSubIterator(it)
|
||||
|
||||
expected := []string{
|
||||
|
|
@ -361,7 +361,7 @@ func TestSetIterator(t *testing.T) {
|
|||
and := iterator.NewAnd()
|
||||
// Order is important
|
||||
and.AddSubIterator(it)
|
||||
and.AddSubIterator(ts.GetTripleIterator(graph.Subject, ts.GetIdFor("B")))
|
||||
and.AddSubIterator(ts.TripleIterator(graph.Subject, ts.ValueOf("B")))
|
||||
|
||||
expected := []string{
|
||||
(&graph.Triple{"B", "status", "cool", "status_graph"}).String(),
|
||||
|
|
@ -399,7 +399,7 @@ func TestOptimize(t *testing.T) {
|
|||
|
||||
Convey("With an linksto-fixed pair", func() {
|
||||
fixed := ts.FixedIterator()
|
||||
fixed.AddValue(ts.GetIdFor("F"))
|
||||
fixed.AddValue(ts.ValueOf("F"))
|
||||
fixed.AddTag("internal")
|
||||
lto = iterator.NewLinksTo(ts, fixed, graph.Object)
|
||||
|
||||
|
|
|
|||
|
|
@ -65,11 +65,11 @@ func CreateNewLevelDB(path string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func NewTripleStore(path string, options graph.OptionsDict) *TripleStore {
|
||||
func NewTripleStore(path string, options graph.Options) *TripleStore {
|
||||
var ts TripleStore
|
||||
ts.path = path
|
||||
cache_size := DefaultCacheSize
|
||||
if val, ok := options.GetIntKey("cache_size_mb"); ok {
|
||||
if val, ok := options.IntKey("cache_size_mb"); ok {
|
||||
cache_size = val
|
||||
}
|
||||
ts.dbOpts = &opt.Options{
|
||||
|
|
@ -78,7 +78,7 @@ func NewTripleStore(path string, options graph.OptionsDict) *TripleStore {
|
|||
ts.dbOpts.ErrorIfMissing = true
|
||||
|
||||
write_buffer_mb := DefaultWriteBufferSize
|
||||
if val, ok := options.GetIntKey("write_buffer_mb"); ok {
|
||||
if val, ok := options.IntKey("write_buffer_mb"); ok {
|
||||
write_buffer_mb = val
|
||||
}
|
||||
ts.dbOpts.WriteBuffer = write_buffer_mb * opt.MiB
|
||||
|
|
@ -301,7 +301,7 @@ func (ts *TripleStore) Close() {
|
|||
ts.open = false
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetTriple(k graph.TSVal) *graph.Triple {
|
||||
func (ts *TripleStore) Triple(k graph.TSVal) *graph.Triple {
|
||||
var triple graph.Triple
|
||||
b, err := ts.db.Get(k.([]byte), ts.readopts)
|
||||
if err != nil && err != leveldb.ErrNotFound {
|
||||
|
|
@ -328,7 +328,7 @@ func (ts *TripleStore) convertStringToByteHash(s string) []byte {
|
|||
return key
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetIdFor(s string) graph.TSVal {
|
||||
func (ts *TripleStore) ValueOf(s string) graph.TSVal {
|
||||
return ts.createValueKeyFor(s)
|
||||
}
|
||||
|
||||
|
|
@ -352,7 +352,7 @@ func (ts *TripleStore) getValueData(value_key []byte) ValueData {
|
|||
return out
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetNameFor(k graph.TSVal) string {
|
||||
func (ts *TripleStore) NameOf(k graph.TSVal) string {
|
||||
if k == nil {
|
||||
glog.V(2).Infoln("k was nil")
|
||||
return ""
|
||||
|
|
@ -401,7 +401,7 @@ func (ts *TripleStore) GetApproximateSizeForPrefix(pre []byte) (int64, error) {
|
|||
return 0, nil
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetTripleIterator(d graph.Direction, val graph.TSVal) graph.Iterator {
|
||||
func (ts *TripleStore) TripleIterator(d graph.Direction, val graph.TSVal) graph.Iterator {
|
||||
var prefix string
|
||||
switch d {
|
||||
case graph.Subject:
|
||||
|
|
@ -418,21 +418,21 @@ func (ts *TripleStore) GetTripleIterator(d graph.Direction, val graph.TSVal) gra
|
|||
return NewIterator(prefix, d, val, ts)
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
|
||||
func (ts *TripleStore) NodesAllIterator() graph.Iterator {
|
||||
return NewAllIterator("z", graph.Any, ts)
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
|
||||
func (ts *TripleStore) TriplesAllIterator() graph.Iterator {
|
||||
return NewAllIterator("po", graph.Predicate, ts)
|
||||
}
|
||||
|
||||
func (ts *TripleStore) GetTripleDirection(val graph.TSVal, d graph.Direction) graph.TSVal {
|
||||
func (ts *TripleStore) TripleDirection(val graph.TSVal, d graph.Direction) graph.TSVal {
|
||||
v := val.([]uint8)
|
||||
offset := GetPositionFromPrefix(v[0:2], d, ts)
|
||||
if offset != -1 {
|
||||
return append([]byte("z"), v[offset:offset+ts.hasher.Size()]...)
|
||||
} else {
|
||||
return ts.GetTriple(val).Get(d)
|
||||
return ts.Triple(val).Get(d)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ func (ts *TripleStore) optimizeLinksTo(it *iterator.LinksTo) (graph.Iterator, bo
|
|||
if !ok {
|
||||
panic("Sizes lie")
|
||||
}
|
||||
newIt := ts.GetTripleIterator(it.Direction(), val)
|
||||
newIt := ts.TripleIterator(it.Direction(), val)
|
||||
newIt.CopyTagsFrom(it)
|
||||
for _, tag := range primary.Tags() {
|
||||
newIt.AddFixedTag(tag, val)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue