rewrite and simplification

This commit is contained in:
pippellia-btc
2025-05-21 16:10:29 +02:00
commit 17f692a5f4
9 changed files with 1014 additions and 0 deletions

31
pkg/graph/graph.go Normal file
View File

@@ -0,0 +1,31 @@
package graph
type ID string
// Delta represent the changes a Node made to its follow list.
// It Removed some nodes, and Added some others.
// This means the old follow list is Removed + Common, while the new is Common + Added
type Delta struct {
Node ID
Removed []ID
Common []ID
Added []ID
}
func (d Delta) Old() []ID {
return append(d.Common, d.Removed...)
}
func (d Delta) New() []ID {
return append(d.Common, d.Added...)
}
// Inverse of the delta. If a delta and it's inverse are applied, the graph returns to its original state.
func (d Delta) Inverse() Delta {
return Delta{
Node: d.Node,
Common: d.Common,
Removed: d.Added,
Added: d.Removed,
}
}