Merge pull request #186 from panamafrancis/primarykeys

Implementation of the PrimaryKey type
This commit is contained in:
Barak Michener 2014-12-28 14:05:58 -08:00
commit 9088fe376b
11 changed files with 135 additions and 44 deletions

View file

@ -168,6 +168,12 @@ func TestLoadDatabase(t *testing.T) {
t.Errorf("Could not convert from generic to LevelDB QuadStore")
}
//Test horizon
horizon := qs.Horizon()
if horizon.Int() != 1 {
t.Errorf("Unexpected horizon value, got:%d expect:1", horizon.Int())
}
w.AddQuadSet(makeQuadSet())
if s := qs.Size(); s != 11 {
t.Errorf("Unexpected quadstore size, got:%d expect:11", s)
@ -175,6 +181,10 @@ func TestLoadDatabase(t *testing.T) {
if s := ts2.SizeOf(qs.ValueOf("B")); s != 5 {
t.Errorf("Unexpected quadstore size, got:%d expect:5", s)
}
horizon = qs.Horizon()
if horizon.Int() != 12 {
t.Errorf("Unexpected horizon value, got:%d expect:12", horizon.Int())
}
w.RemoveQuad(quad.Quad{
Subject: "A",

View file

@ -31,6 +31,7 @@ import (
"github.com/google/cayley/graph"
"github.com/google/cayley/graph/iterator"
"github.com/google/cayley/keys"
"github.com/google/cayley/quad"
)
@ -134,8 +135,8 @@ func (qs *QuadStore) Size() int64 {
return qs.size
}
func (qs *QuadStore) Horizon() int64 {
return qs.horizon
func (qs *QuadStore) Horizon() graph.PrimaryKey {
return keys.NewSequentialKey(qs.horizon)
}
func hashOf(s string) []byte {
@ -189,7 +190,7 @@ func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta) error {
return err
}
batch.Put(keyFor(d), bytes)
err = qs.buildQuadWrite(batch, d.Quad, d.ID, d.Action == graph.Add)
err = qs.buildQuadWrite(batch, d.Quad, d.ID.Int(), d.Action == graph.Add)
if err != nil {
return err
}
@ -204,7 +205,7 @@ func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta) error {
resizeMap[d.Quad.Label] += delta
}
sizeChange += delta
qs.horizon = d.ID
qs.horizon = d.ID.Int()
}
for k, v := range resizeMap {
if v != 0 {
@ -226,7 +227,7 @@ func (qs *QuadStore) ApplyDeltas(deltas []graph.Delta) error {
func keyFor(d graph.Delta) []byte {
key := make([]byte, 0, 19)
key = append(key, 'd')
key = append(key, []byte(fmt.Sprintf("%018x", d.ID))...)
key = append(key, []byte(fmt.Sprintf("%018x", d.ID.Int()))...)
return key
}