/
vertex.go
53 lines (45 loc) · 1.08 KB
/
vertex.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package pregol
import "fmt"
type ResultMsg struct {
sendId int
halt bool
msg map[int]float64
}
type Vertex struct {
Id int
flag bool
Val float64
InMsg []float64
outMsg map[int]float64
OutEdges []edgeReader
NumVertices float64
}
type UDF func(vertex *Vertex, superstep int) (bool, map[int]float64)
func (v *Vertex) SetInEdge(newVal []float64) {
fmt.Println(v.InMsg)
//v.InMsg = append(v.InMsg, newVal...)
for _, i := range newVal {
v.InMsg = append(v.InMsg, i)
}
//fmt.Println("in edge updated in setinEdge: ", v.InMsg)
}
func (v *Vertex) Compute(udf UDF, superstep int) ResultMsg {
v.outMsg = make(map[int]float64)
if len(v.InMsg) != 0 {
v.flag, v.outMsg = udf(v, superstep)
v.InMsg = make([]float64, 0)
return ResultMsg{v.Id, false, v.outMsg}
} else {
if v.flag {
return v.VoteToHalt()
} else {
v.flag, v.outMsg = udf(v, superstep)
v.InMsg = make([]float64, 0)
return ResultMsg{v.Id, false, v.outMsg}
}
}
}
func (v *Vertex) VoteToHalt() ResultMsg {
var m map[int]float64
return ResultMsg{v.Id, true, m}
}