Key/Keyer

This commit is contained in:
Barak Michener 2014-08-06 16:59:46 -04:00
parent 408103b406
commit b74cb142f0
3 changed files with 8 additions and 8 deletions

View file

@ -32,8 +32,8 @@ type result struct {
tags map[string]graph.Value
}
type hasher interface {
Hasher() interface{}
type Keyer interface {
Key() interface{}
}
type Materialize struct {
@ -205,8 +205,8 @@ func (it *Materialize) Contains(v graph.Value) bool {
return it.subIt.Contains(v)
}
key := v
if h, ok := v.(hasher); ok {
key = h.Hasher()
if h, ok := v.(Keyer); ok {
key = h.Key()
}
if i, ok := it.containsMap[key]; ok {
it.index = i
@ -246,8 +246,8 @@ func (it *Materialize) materializeSet() {
break
}
val := id
if h, ok := id.(hasher); ok {
val = h.Hasher()
if h, ok := id.(Keyer); ok {
val = h.Key()
}
if _, ok := it.containsMap[val]; !ok {
it.containsMap[val] = len(it.values)

View file

@ -44,7 +44,7 @@ const (
type Token []byte
func (t Token) Hasher() interface{} {
func (t Token) Key() interface{} {
return string(t)
}

View file

@ -37,7 +37,7 @@ import (
// pointers to structs, or merely triples, or whatever works best for the
// 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.
type Value interface{}