diff --git a/pkg/walks/walker.go b/pkg/walks/walker.go index 80c05e2..9235362 100644 --- a/pkg/walks/walker.go +++ b/pkg/walks/walker.go @@ -14,33 +14,6 @@ type Walker interface { Follows(ctx context.Context, node graph.ID) ([]graph.ID, error) } -type SimpleWalker struct { - follows map[graph.ID][]graph.ID -} - -func NewSimpleWalker(m map[graph.ID][]graph.ID) *SimpleWalker { - return &SimpleWalker{follows: m} -} - -func (w *SimpleWalker) Follows(ctx context.Context, node graph.ID) ([]graph.ID, error) { - return w.follows[node], nil -} - -func (w *SimpleWalker) Update(ctx context.Context, delta graph.Delta) { - w.follows[delta.Node] = delta.New() -} - -func NewCyclicWalker(n int) *SimpleWalker { - follows := make(map[graph.ID][]graph.ID, n) - for i := range n { - node := graph.ID(strconv.Itoa(i)) - next := graph.ID(strconv.Itoa((i + 1) % n)) - follows[node] = []graph.ID{next} - } - - return &SimpleWalker{follows: follows} -} - // CachedWalker is a [Walker] with optional fallback that stores follow relationships // in a compact format (uint32) for reduced memory footprint. // If its size grows larger than capacity, the least recently used (LRU) key is evicted. @@ -201,3 +174,30 @@ func nodes(IDs []uint32) []graph.ID { } return nodes } + +type SimpleWalker struct { + follows map[graph.ID][]graph.ID +} + +func NewSimpleWalker(m map[graph.ID][]graph.ID) *SimpleWalker { + return &SimpleWalker{follows: m} +} + +func (w *SimpleWalker) Follows(ctx context.Context, node graph.ID) ([]graph.ID, error) { + return w.follows[node], nil +} + +func (w *SimpleWalker) Update(ctx context.Context, delta graph.Delta) { + w.follows[delta.Node] = delta.New() +} + +func NewCyclicWalker(n int) *SimpleWalker { + follows := make(map[graph.ID][]graph.ID, n) + for i := range n { + node := graph.ID(strconv.Itoa(i)) + next := graph.ID(strconv.Itoa((i + 1) % n)) + follows[node] = []graph.ID{next} + } + + return &SimpleWalker{follows: follows} +}