mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 06:05:06 +03:00
work-in-progress on a new sim
This commit is contained in:
parent
78b5f88e4b
commit
9c818c6278
5 changed files with 168 additions and 1 deletions
41
cmd/yggdrasilsim/store.go
Normal file
41
cmd/yggdrasilsim/store.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package main
|
||||
|
||||
type nodeStore map[int]*simNode
|
||||
|
||||
func makeStoreSingle() nodeStore {
|
||||
s := make(nodeStore)
|
||||
s[0] = newNode(0)
|
||||
return s
|
||||
}
|
||||
|
||||
func linkNodes(a *simNode, b *simNode) {
|
||||
la := a.core.NewSimlink()
|
||||
lb := b.core.NewSimlink()
|
||||
la.SetDestination(lb)
|
||||
lb.SetDestination(la)
|
||||
la.Start()
|
||||
lb.Start()
|
||||
}
|
||||
|
||||
func makeStoreSquareGrid(sideLength int) nodeStore {
|
||||
store := make(nodeStore)
|
||||
nNodes := sideLength * sideLength
|
||||
idxs := make([]int, 0, nNodes)
|
||||
// TODO shuffle nodeIDs
|
||||
for idx := 1; idx <= nNodes; idx++ {
|
||||
idxs = append(idxs, idx)
|
||||
}
|
||||
for _, idx := range idxs {
|
||||
n := newNode(idx)
|
||||
store[idx] = n
|
||||
}
|
||||
for idx := 0; idx < nNodes; idx++ {
|
||||
if (idx % sideLength) != 0 {
|
||||
linkNodes(store[idxs[idx]], store[idxs[idx-1]])
|
||||
}
|
||||
if idx >= sideLength {
|
||||
linkNodes(store[idxs[idx]], store[idxs[idx-sideLength]])
|
||||
}
|
||||
}
|
||||
return store
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue