Merge pull request #51 from barakmich/prefix_string
Prefix vs String for graph.Direction
This commit is contained in:
commit
70f622aefe
2 changed files with 24 additions and 7 deletions
|
|
@ -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]))...)
|
||||
|
|
|
|||
|
|
@ -60,18 +60,35 @@ const (
|
|||
Provenance
|
||||
)
|
||||
|
||||
func (d Direction) Prefix() byte {
|
||||
switch d {
|
||||
case Any:
|
||||
return 'a'
|
||||
case Subject:
|
||||
return 's'
|
||||
case Predicate:
|
||||
return 'p'
|
||||
case Provenance:
|
||||
return 'c'
|
||||
case Object:
|
||||
return 'o'
|
||||
default:
|
||||
return '\x00'
|
||||
}
|
||||
}
|
||||
|
||||
func (d Direction) String() string {
|
||||
switch d {
|
||||
case Any:
|
||||
return "a"
|
||||
return "any"
|
||||
case Subject:
|
||||
return "s"
|
||||
return "subject"
|
||||
case Predicate:
|
||||
return "p"
|
||||
return "predicate"
|
||||
case Provenance:
|
||||
return "c"
|
||||
return "provenance"
|
||||
case Object:
|
||||
return "o"
|
||||
return "object"
|
||||
default:
|
||||
return fmt.Sprint("illegal direction:", byte(d))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue