Key/Keyer
This commit is contained in:
parent
408103b406
commit
b74cb142f0
3 changed files with 8 additions and 8 deletions
|
|
@ -32,8 +32,8 @@ type result struct {
|
||||||
tags map[string]graph.Value
|
tags map[string]graph.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
type hasher interface {
|
type Keyer interface {
|
||||||
Hasher() interface{}
|
Key() interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Materialize struct {
|
type Materialize struct {
|
||||||
|
|
@ -205,8 +205,8 @@ func (it *Materialize) Contains(v graph.Value) bool {
|
||||||
return it.subIt.Contains(v)
|
return it.subIt.Contains(v)
|
||||||
}
|
}
|
||||||
key := v
|
key := v
|
||||||
if h, ok := v.(hasher); ok {
|
if h, ok := v.(Keyer); ok {
|
||||||
key = h.Hasher()
|
key = h.Key()
|
||||||
}
|
}
|
||||||
if i, ok := it.containsMap[key]; ok {
|
if i, ok := it.containsMap[key]; ok {
|
||||||
it.index = i
|
it.index = i
|
||||||
|
|
@ -246,8 +246,8 @@ func (it *Materialize) materializeSet() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
val := id
|
val := id
|
||||||
if h, ok := id.(hasher); ok {
|
if h, ok := id.(Keyer); ok {
|
||||||
val = h.Hasher()
|
val = h.Key()
|
||||||
}
|
}
|
||||||
if _, ok := it.containsMap[val]; !ok {
|
if _, ok := it.containsMap[val]; !ok {
|
||||||
it.containsMap[val] = len(it.values)
|
it.containsMap[val] = len(it.values)
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ const (
|
||||||
|
|
||||||
type Token []byte
|
type Token []byte
|
||||||
|
|
||||||
func (t Token) Hasher() interface{} {
|
func (t Token) Key() interface{} {
|
||||||
return string(t)
|
return string(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ import (
|
||||||
// pointers to structs, or merely triples, or whatever works best for the
|
// pointers to structs, or merely triples, or whatever works best for the
|
||||||
// backing store.
|
// backing store.
|
||||||
//
|
//
|
||||||
// These must be comparable, or implement a `Hasher() interface{}` function
|
// These must be comparable, or implement a `Key() interface{}` function
|
||||||
// so that they may be stored in maps.
|
// so that they may be stored in maps.
|
||||||
type Value interface{}
|
type Value interface{}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue