github.com/simpleiot/simpleiot@v0.18.3/data/edge.go (about) 1 package data 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 // TODO -- would like to move this to db/store package and make it internal 9 10 // Edge is used to describe the relationship 11 // between two nodes 12 type Edge struct { 13 ID string `json:"id"` 14 Up string `json:"up"` 15 Down string `json:"down"` 16 Points Points `json:"points"` 17 Hash uint32 `json:"hash"` 18 Type string `json:"type"` 19 } 20 21 func (e Edge) String() string { 22 ret := fmt.Sprintf("EDGE: %v\n", e.ID) 23 ret += fmt.Sprintf(" - Up: %v\n", e.Up) 24 ret += fmt.Sprintf(" - Down: %v\n", e.Down) 25 ret += fmt.Sprintf(" - Hash: 0x%x\n", e.Hash) 26 27 for _, p := range e.Points { 28 ret += fmt.Sprintf(" - Point: %v\n", p) 29 } 30 31 return ret 32 } 33 34 // IsTombstone returns true of edge points to a deleted node 35 func (e *Edge) IsTombstone() bool { 36 tombstone, _ := e.Points.ValueBool(PointTypeTombstone, "") 37 return tombstone 38 } 39 40 // ByEdgeID implements sort interface for NodeEdge by ID 41 type ByEdgeID []*Edge 42 43 func (a ByEdgeID) Len() int { return len(a) } 44 func (a ByEdgeID) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 45 func (a ByEdgeID) Less(i, j int) bool { return strings.Compare(a[i].ID, a[j].ID) < 0 } 46 47 // ByHash implements sort interface for NodeEdge by Hash 48 type ByHash []*Edge 49 50 func (a ByHash) Len() int { return len(a) } 51 func (a ByHash) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 52 func (a ByHash) Less(i, j int) bool { return a[i].Hash < a[j].Hash }