Make hashOf a function
This commit is contained in:
parent
d8866478df
commit
a22eb42482
3 changed files with 36 additions and 36 deletions
|
|
@ -136,18 +136,28 @@ func bucketFor(d [4]quad.Direction) []byte {
|
||||||
return []byte{d[0].Prefix(), d[1].Prefix(), d[2].Prefix(), d[3].Prefix()}
|
return []byte{d[0].Prefix(), d[1].Prefix(), d[2].Prefix(), d[3].Prefix()}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hashOf(s string) []byte {
|
||||||
|
h := hashPool.Get().(hash.Hash)
|
||||||
|
h.Reset()
|
||||||
|
defer hashPool.Put(h)
|
||||||
|
key := make([]byte, 0, hashSize)
|
||||||
|
h.Write([]byte(s))
|
||||||
|
key = h.Sum(key)
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
|
||||||
func (qs *QuadStore) createKeyFor(d [4]quad.Direction, q quad.Quad) []byte {
|
func (qs *QuadStore) createKeyFor(d [4]quad.Direction, q quad.Quad) []byte {
|
||||||
key := make([]byte, 0, (hashSize * 4))
|
key := make([]byte, 0, (hashSize * 4))
|
||||||
key = append(key, qs.hashOf(q.Get(d[0]))...)
|
key = append(key, hashOf(q.Get(d[0]))...)
|
||||||
key = append(key, qs.hashOf(q.Get(d[1]))...)
|
key = append(key, hashOf(q.Get(d[1]))...)
|
||||||
key = append(key, qs.hashOf(q.Get(d[2]))...)
|
key = append(key, hashOf(q.Get(d[2]))...)
|
||||||
key = append(key, qs.hashOf(q.Get(d[3]))...)
|
key = append(key, hashOf(q.Get(d[3]))...)
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *QuadStore) createValueKeyFor(s string) []byte {
|
func (qs *QuadStore) createValueKeyFor(s string) []byte {
|
||||||
key := make([]byte, 0, hashSize)
|
key := make([]byte, 0, hashSize)
|
||||||
key = append(key, qs.hashOf(s)...)
|
key = append(key, hashOf(s)...)
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -379,16 +389,6 @@ func (qs *QuadStore) Quad(k graph.Value) quad.Quad {
|
||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *QuadStore) hashOf(s string) []byte {
|
|
||||||
h := hashPool.Get().(hash.Hash)
|
|
||||||
h.Reset()
|
|
||||||
defer hashPool.Put(h)
|
|
||||||
key := make([]byte, 0, hashSize)
|
|
||||||
h.Write([]byte(s))
|
|
||||||
key = h.Sum(key)
|
|
||||||
return key
|
|
||||||
}
|
|
||||||
|
|
||||||
func (qs *QuadStore) ValueOf(s string) graph.Value {
|
func (qs *QuadStore) ValueOf(s string) graph.Value {
|
||||||
return &Token{
|
return &Token{
|
||||||
bucket: nodeBucket,
|
bucket: nodeBucket,
|
||||||
|
|
|
||||||
|
|
@ -146,21 +146,31 @@ func (qa *QuadStore) createDeltaKeyFor(d graph.Delta) []byte {
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hashOf(s string) []byte {
|
||||||
|
h := hashPool.Get().(hash.Hash)
|
||||||
|
h.Reset()
|
||||||
|
defer hashPool.Put(h)
|
||||||
|
key := make([]byte, 0, hashSize)
|
||||||
|
h.Write([]byte(s))
|
||||||
|
key = h.Sum(key)
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
|
||||||
func (qs *QuadStore) createKeyFor(d [4]quad.Direction, q quad.Quad) []byte {
|
func (qs *QuadStore) createKeyFor(d [4]quad.Direction, q quad.Quad) []byte {
|
||||||
key := make([]byte, 0, 2+(hashSize*3))
|
key := make([]byte, 0, 2+(hashSize*3))
|
||||||
// TODO(kortschak) Remove dependence on String() method.
|
// TODO(kortschak) Remove dependence on String() method.
|
||||||
key = append(key, []byte{d[0].Prefix(), d[1].Prefix()}...)
|
key = append(key, []byte{d[0].Prefix(), d[1].Prefix()}...)
|
||||||
key = append(key, qs.hashOf(q.Get(d[0]))...)
|
key = append(key, hashOf(q.Get(d[0]))...)
|
||||||
key = append(key, qs.hashOf(q.Get(d[1]))...)
|
key = append(key, hashOf(q.Get(d[1]))...)
|
||||||
key = append(key, qs.hashOf(q.Get(d[2]))...)
|
key = append(key, hashOf(q.Get(d[2]))...)
|
||||||
key = append(key, qs.hashOf(q.Get(d[3]))...)
|
key = append(key, hashOf(q.Get(d[3]))...)
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *QuadStore) createValueKeyFor(s string) []byte {
|
func (qs *QuadStore) createValueKeyFor(s string) []byte {
|
||||||
key := make([]byte, 0, 1+hashSize)
|
key := make([]byte, 0, 1+hashSize)
|
||||||
key = append(key, []byte("z")...)
|
key = append(key, []byte("z")...)
|
||||||
key = append(key, qs.hashOf(s)...)
|
key = append(key, hashOf(s)...)
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -347,16 +357,6 @@ func (qs *QuadStore) Quad(k graph.Value) quad.Quad {
|
||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *QuadStore) hashOf(s string) []byte {
|
|
||||||
h := hashPool.Get().(hash.Hash)
|
|
||||||
h.Reset()
|
|
||||||
defer hashPool.Put(h)
|
|
||||||
key := make([]byte, 0, hashSize)
|
|
||||||
h.Write([]byte(s))
|
|
||||||
key = h.Sum(key)
|
|
||||||
return key
|
|
||||||
}
|
|
||||||
|
|
||||||
func (qs *QuadStore) ValueOf(s string) graph.Value {
|
func (qs *QuadStore) ValueOf(s string) graph.Value {
|
||||||
return Token(qs.createValueKeyFor(s))
|
return Token(qs.createValueKeyFor(s))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,14 +102,14 @@ func newQuadStore(addr string, options graph.Options) (graph.QuadStore, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *QuadStore) getIdForQuad(t quad.Quad) string {
|
func (qs *QuadStore) getIdForQuad(t quad.Quad) string {
|
||||||
id := qs.hashOf(t.Subject)
|
id := hashOf(t.Subject)
|
||||||
id += qs.hashOf(t.Predicate)
|
id += hashOf(t.Predicate)
|
||||||
id += qs.hashOf(t.Object)
|
id += hashOf(t.Object)
|
||||||
id += qs.hashOf(t.Label)
|
id += hashOf(t.Label)
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *QuadStore) hashOf(s string) string {
|
func hashOf(s string) string {
|
||||||
h := hashPool.Get().(hash.Hash)
|
h := hashPool.Get().(hash.Hash)
|
||||||
h.Reset()
|
h.Reset()
|
||||||
defer hashPool.Put(h)
|
defer hashPool.Put(h)
|
||||||
|
|
@ -288,7 +288,7 @@ func (qs *QuadStore) QuadsAllIterator() graph.Iterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *QuadStore) ValueOf(s string) graph.Value {
|
func (qs *QuadStore) ValueOf(s string) graph.Value {
|
||||||
return qs.hashOf(s)
|
return hashOf(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *QuadStore) NameOf(v graph.Value) string {
|
func (qs *QuadStore) NameOf(v graph.Value) string {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue