moved simple walker to bottom of file

This commit is contained in:
pippellia-btc
2025-06-03 15:42:22 +02:00
parent 64b4eda9a6
commit f9daea9579

View File

@@ -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}
}