diff --git a/graph.go b/graph.go index b06dcbf..865de6a 100644 --- a/graph.go +++ b/graph.go @@ -1,20 +1,16 @@ package rdf type Graph struct { - triples map[*Triple]struct{} + triples []*Triple } func NewGraph(ts ...*Triple) *Graph { - triples := make(map[*Triple]struct{}) - for _, t := range ts { - triples[t] = struct{}{} - } - return &Graph{triples} + return &Graph{triples: ts} } func (g *Graph) Add(s, p, o Node) { t := &Triple{s, p, o} - g.triples[t] = struct{}{} + g.triples = append(g.triples, t) } // Find returns the first triple matching the given pattern. @@ -43,13 +39,18 @@ func (g *Graph) FindAll(s, p, o Node) []*Triple { } func (g *Graph) Remove(t *Triple) { - delete(g.triples, t) + for i, other := range g.triples { + if t.Equal(other) { + g.triples = append(g.triples[:i], g.triples[i+1:]...) + return + } + } } func (g *Graph) iter() chan *Triple { ch := make(chan *Triple) go func() { - for t := range g.triples { + for _, t := range g.triples { ch <- t } close(ch)