Use NumNodes/NumLinks

This commit is contained in:
Ivan Danyliuk 2018-10-24 15:13:55 +02:00
parent 10702e39b7
commit 7f4f201964
No known key found for this signature in database
GPG Key ID: 97ED33CE024E1DBF
6 changed files with 8 additions and 12 deletions

View File

@ -27,7 +27,7 @@ func simulationHandler(w http.ResponseWriter, r *http.Request) {
}
defer r.Body.Close()
log.Printf("Loaded graph with %d nodes", len(data.Nodes()))
log.Printf("Loaded graph with %d nodes", data.NumNodes())
sim := NewSimulation(data)
sim.Start()
defer sim.Stop()

View File

@ -33,7 +33,7 @@ func main() {
sim.WriteOutputToFile(*output)
// stats
ss := stats.Analyze(sim.plog, len(data.Nodes()), len(data.Links()))
ss := stats.Analyze(sim.plog, data.NumNodes(), data.NumLinks())
ss.PrintVerbose()
log.Printf("Written propagation data into %s", *output)

View File

@ -37,6 +37,6 @@ func main() {
log.Fatalf("Parsing propagation log failed: %v", err)
}
ss := stats.Analyze(plog, len(data.Nodes()), len(data.Links()))
ss := stats.Analyze(plog, data.NumNodes(), data.NumLinks())
ss.PrintVerbose()
}

View File

@ -28,7 +28,7 @@ type Message struct {
// NewSimulator initializes new simulator for the given graph data.
func NewSimulator(data *graph.Graph, N int, delay time.Duration) *Simulator {
nodeCount := len(data.Nodes())
nodeCount := data.NumNodes()
sim := &Simulator{
data: data,
delay: delay,

View File

@ -39,7 +39,7 @@ func NewSimulator(data *graph.Graph) *Simulator {
MinimumAcceptedPOW: 0.001,
}
whispers := make(map[enode.ID]*whisper.Whisper, len(data.Nodes()))
whispers := make(map[enode.ID]*whisper.Whisper, data.NumNodes())
services := map[string]adapters.ServiceFunc{
"shh": func(ctx *adapters.ServiceContext) (node.Service, error) {
return whispers[ctx.Config.ID], nil
@ -51,15 +51,13 @@ func NewSimulator(data *graph.Graph) *Simulator {
DefaultService: "shh",
})
nodes := data.Nodes()
nodeCount := len(nodes)
sim := &Simulator{
data: data,
network: network,
}
log.Println("Creating nodes...")
for i := 0; i < nodeCount; i++ {
for i := 0; i < data.NumNodes(); i++ {
node, err := sim.network.NewNodeWithConfig(nodeConfig(i))
if err != nil {
log.Fatal("[ERROR] Can't start node: ", err)

View File

@ -41,7 +41,7 @@ func TestAnalyze(t *testing.T) {
},
}
stats := Analyze(plog, len(g.Nodes()), len(g.Links()))
stats := Analyze(plog, g.NumNodes(), g.NumLinks())
expected := []struct {
name string
@ -77,9 +77,7 @@ func BenchmarkAnalyze(b *testing.B) {
},
}
nodeCount := len(g.Nodes())
linksCount := len(g.Links())
for i := 0; i < b.N; i++ {
Analyze(plog, nodeCount, linksCount)
Analyze(plog, g.NumNodes(), g.NumLinks())
}
}