mirror of
https://github.com/aljazceru/crawler_v2.git
synced 2025-12-17 07:24:21 +01:00
renamed to simple walker
This commit is contained in:
@@ -11,23 +11,23 @@ type Walker interface {
|
|||||||
Follows(ctx context.Context, node graph.ID) ([]graph.ID, error)
|
Follows(ctx context.Context, node graph.ID) ([]graph.ID, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type MapWalker struct {
|
type SimpleWalker struct {
|
||||||
follows map[graph.ID][]graph.ID
|
follows map[graph.ID][]graph.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWalker(m map[graph.ID][]graph.ID) *MapWalker {
|
func NewSimpleWalker(m map[graph.ID][]graph.ID) *SimpleWalker {
|
||||||
return &MapWalker{follows: m}
|
return &SimpleWalker{follows: m}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MapWalker) Follows(ctx context.Context, node graph.ID) ([]graph.ID, error) {
|
func (w *SimpleWalker) Follows(ctx context.Context, node graph.ID) ([]graph.ID, error) {
|
||||||
return m.follows[node], nil
|
return w.follows[node], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MapWalker) Update(ctx context.Context, delta graph.Delta) {
|
func (w *SimpleWalker) Update(ctx context.Context, delta graph.Delta) {
|
||||||
m.follows[delta.Node] = delta.New()
|
w.follows[delta.Node] = delta.New()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCyclicWalker(n int) *MapWalker {
|
func NewCyclicWalker(n int) *SimpleWalker {
|
||||||
follows := make(map[graph.ID][]graph.ID, n)
|
follows := make(map[graph.ID][]graph.ID, n)
|
||||||
for i := range n {
|
for i := range n {
|
||||||
node := graph.ID(strconv.Itoa(i))
|
node := graph.ID(strconv.Itoa(i))
|
||||||
@@ -35,18 +35,18 @@ func NewCyclicWalker(n int) *MapWalker {
|
|||||||
follows[node] = []graph.ID{next}
|
follows[node] = []graph.ID{next}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &MapWalker{follows: follows}
|
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.
|
||||||
type cachedWalker struct {
|
type CachedWalker struct {
|
||||||
follows map[graph.ID][]graph.ID
|
follows map[graph.ID][]graph.ID
|
||||||
fallback Walker
|
fallback Walker
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCachedWalker(nodes []graph.ID, follows [][]graph.ID, fallback Walker) *cachedWalker {
|
func NewCachedWalker(nodes []graph.ID, follows [][]graph.ID, fallback Walker) *CachedWalker {
|
||||||
w := cachedWalker{
|
w := CachedWalker{
|
||||||
follows: make(map[graph.ID][]graph.ID, len(nodes)),
|
follows: make(map[graph.ID][]graph.ID, len(nodes)),
|
||||||
fallback: fallback,
|
fallback: fallback,
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ func NewCachedWalker(nodes []graph.ID, follows [][]graph.ID, fallback Walker) *c
|
|||||||
return &w
|
return &w
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *cachedWalker) Follows(ctx context.Context, node graph.ID) ([]graph.ID, error) {
|
func (w *CachedWalker) Follows(ctx context.Context, node graph.ID) ([]graph.ID, error) {
|
||||||
follows, exists := w.follows[node]
|
follows, exists := w.follows[node]
|
||||||
if !exists {
|
if !exists {
|
||||||
var err error
|
var err error
|
||||||
|
|||||||
@@ -102,7 +102,8 @@ func TestToRemove(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateRemove(t *testing.T) {
|
func TestUpdateRemove(t *testing.T) {
|
||||||
walker := NewWalker(map[graph.ID][]graph.ID{
|
walker := NewSimpleWalker(
|
||||||
|
map[graph.ID][]graph.ID{
|
||||||
"0": {"3"},
|
"0": {"3"},
|
||||||
"1": {"2"},
|
"1": {"2"},
|
||||||
"2": {"0"},
|
"2": {"0"},
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Setup struct {
|
type Setup struct {
|
||||||
walker *walks.MapWalker
|
walker *walks.SimpleWalker
|
||||||
deltas []graph.Delta
|
deltas []graph.Delta
|
||||||
|
|
||||||
nodes []graph.ID
|
nodes []graph.ID
|
||||||
@@ -54,7 +54,7 @@ func Dandlings(n int) Setup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Setup{
|
return Setup{
|
||||||
walker: walks.NewWalker(make(map[graph.ID][]graph.ID)),
|
walker: walks.NewSimpleWalker(make(map[graph.ID][]graph.ID)),
|
||||||
deltas: deltas,
|
deltas: deltas,
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
global: global,
|
global: global,
|
||||||
@@ -93,7 +93,8 @@ func Cyclic(n int) Setup {
|
|||||||
var Triangle = Cyclic(3)
|
var Triangle = Cyclic(3)
|
||||||
|
|
||||||
var Acyclic1 = Setup{
|
var Acyclic1 = Setup{
|
||||||
walker: walks.NewWalker(map[graph.ID][]graph.ID{
|
walker: walks.NewSimpleWalker(
|
||||||
|
map[graph.ID][]graph.ID{
|
||||||
"0": {"1", "2"},
|
"0": {"1", "2"},
|
||||||
"1": {},
|
"1": {},
|
||||||
"2": {"3"},
|
"2": {"3"},
|
||||||
@@ -136,7 +137,8 @@ var Acyclic1 = Setup{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var Acyclic2 = Setup{
|
var Acyclic2 = Setup{
|
||||||
walker: walks.NewWalker(map[graph.ID][]graph.ID{
|
walker: walks.NewSimpleWalker(
|
||||||
|
map[graph.ID][]graph.ID{
|
||||||
"0": {"1", "2"},
|
"0": {"1", "2"},
|
||||||
"1": {},
|
"1": {},
|
||||||
"2": {},
|
"2": {},
|
||||||
@@ -167,7 +169,8 @@ var Acyclic2 = Setup{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var Acyclic3 = Setup{
|
var Acyclic3 = Setup{
|
||||||
walker: walks.NewWalker(map[graph.ID][]graph.ID{
|
walker: walks.NewSimpleWalker(
|
||||||
|
map[graph.ID][]graph.ID{
|
||||||
"0": {"1", "2"},
|
"0": {"1", "2"},
|
||||||
"1": {},
|
"1": {},
|
||||||
"2": {},
|
"2": {},
|
||||||
@@ -190,7 +193,8 @@ var Acyclic3 = Setup{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var Acyclic4 = Setup{
|
var Acyclic4 = Setup{
|
||||||
walker: walks.NewWalker(map[graph.ID][]graph.ID{
|
walker: walks.NewSimpleWalker(
|
||||||
|
map[graph.ID][]graph.ID{
|
||||||
"0": {"1", "2"},
|
"0": {"1", "2"},
|
||||||
"1": {},
|
"1": {},
|
||||||
"2": {},
|
"2": {},
|
||||||
@@ -218,7 +222,8 @@ var Acyclic4 = Setup{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var Acyclic5 = Setup{
|
var Acyclic5 = Setup{
|
||||||
walker: walks.NewWalker(map[graph.ID][]graph.ID{
|
walker: walks.NewSimpleWalker(
|
||||||
|
map[graph.ID][]graph.ID{
|
||||||
"0": {"3"},
|
"0": {"3"},
|
||||||
"1": {"0"},
|
"1": {"0"},
|
||||||
"2": {},
|
"2": {},
|
||||||
@@ -246,7 +251,8 @@ var Acyclic5 = Setup{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var Acyclic6 = Setup{
|
var Acyclic6 = Setup{
|
||||||
walker: walks.NewWalker(map[graph.ID][]graph.ID{
|
walker: walks.NewSimpleWalker(
|
||||||
|
map[graph.ID][]graph.ID{
|
||||||
"0": {"4"},
|
"0": {"4"},
|
||||||
"1": {"0"},
|
"1": {"0"},
|
||||||
"2": {},
|
"2": {},
|
||||||
@@ -290,7 +296,7 @@ var Acyclic6 = Setup{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var Acyclic7 = Setup{
|
var Acyclic7 = Setup{
|
||||||
walker: walks.NewWalker(map[graph.ID][]graph.ID{
|
walker: walks.NewSimpleWalker(map[graph.ID][]graph.ID{
|
||||||
"0": {"1", "2", "3"},
|
"0": {"1", "2", "3"},
|
||||||
"1": {},
|
"1": {},
|
||||||
"2": {},
|
"2": {},
|
||||||
|
|||||||
Reference in New Issue
Block a user