Convert to Prefix/String in graph.Triple

This commit is contained in:
Barak Michener 2014-07-02 19:56:16 -04:00
parent 1f67913ed9
commit 7b87e08e89
2 changed files with 20 additions and 3 deletions

View file

@ -114,7 +114,7 @@ func (ts *TripleStore) Size() int64 {
func (ts *TripleStore) createKeyFor(d [3]graph.Direction, triple *graph.Triple) []byte {
key := make([]byte, 0, 2+(ts.hasher.Size()*3))
// TODO(kortschak) Remove dependence on String() method.
key = append(key, []byte(d[0].String()+d[1].String())...)
key = append(key, []byte(d[0].Prefix()+d[1].Prefix())...)
key = append(key, ts.convertStringToByteHash(triple.Get(d[0]))...)
key = append(key, ts.convertStringToByteHash(triple.Get(d[1]))...)
key = append(key, ts.convertStringToByteHash(triple.Get(d[2]))...)
@ -124,7 +124,7 @@ func (ts *TripleStore) createKeyFor(d [3]graph.Direction, triple *graph.Triple)
func (ts *TripleStore) createProvKeyFor(d [3]graph.Direction, triple *graph.Triple) []byte {
key := make([]byte, 0, 2+(ts.hasher.Size()*4))
// TODO(kortschak) Remove dependence on String() method.
key = append(key, []byte(graph.Provenance.String()+d[0].String())...)
key = append(key, []byte(graph.Provenance.Prefix()+d[0].Prefix())...)
key = append(key, ts.convertStringToByteHash(triple.Get(graph.Provenance))...)
key = append(key, ts.convertStringToByteHash(triple.Get(d[0]))...)
key = append(key, ts.convertStringToByteHash(triple.Get(d[1]))...)

View file

@ -60,7 +60,7 @@ const (
Provenance
)
func (d Direction) String() string {
func (d Direction) Prefix() string {
switch d {
case Any:
return "a"
@ -77,6 +77,23 @@ func (d Direction) String() string {
}
}
func (d Direction) String() string {
switch d {
case Any:
return "any"
case Subject:
return "subject"
case Predicate:
return "predicate"
case Provenance:
return "provenance"
case Object:
return "object"
default:
return fmt.Sprint("illegal direction:", byte(d))
}
}
// TODO(kortschak) Consider writing methods onto the concrete type
// instead of the pointer. This needs benchmarking to make the decision.