mirror of
https://github.com/aljazceru/crawler_v2.git
synced 2025-12-17 07:24:21 +01:00
moved simple walker to bottom of file
This commit is contained in:
@@ -14,33 +14,6 @@ type Walker interface {
|
|||||||
Follows(ctx context.Context, node graph.ID) ([]graph.ID, error)
|
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
|
// CachedWalker is a [Walker] with optional fallback that stores follow relationships
|
||||||
// in a compact format (uint32) for reduced memory footprint.
|
// in a compact format (uint32) for reduced memory footprint.
|
||||||
// If its size grows larger than capacity, the least recently used (LRU) key is evicted.
|
// 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
|
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}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user