-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
edge.go
52 lines (41 loc) · 1.38 KB
/
edge.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
package data
import (
"fmt"
"strings"
)
// TODO -- would like to move this to db/store package and make it internal
// Edge is used to describe the relationship
// between two nodes
type Edge struct {
ID string `json:"id"`
Up string `json:"up"`
Down string `json:"down"`
Points Points `json:"points"`
Hash uint32 `json:"hash"`
Type string `json:"type"`
}
func (e Edge) String() string {
ret := fmt.Sprintf("EDGE: %v\n", e.ID)
ret += fmt.Sprintf(" - Up: %v\n", e.Up)
ret += fmt.Sprintf(" - Down: %v\n", e.Down)
ret += fmt.Sprintf(" - Hash: 0x%x\n", e.Hash)
for _, p := range e.Points {
ret += fmt.Sprintf(" - Point: %v\n", p)
}
return ret
}
// IsTombstone returns true of edge points to a deleted node
func (e *Edge) IsTombstone() bool {
tombstone, _ := e.Points.ValueBool(PointTypeTombstone, "")
return tombstone
}
// ByEdgeID implements sort interface for NodeEdge by ID
type ByEdgeID []*Edge
func (a ByEdgeID) Len() int { return len(a) }
func (a ByEdgeID) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByEdgeID) Less(i, j int) bool { return strings.Compare(a[i].ID, a[j].ID) < 0 }
// ByHash implements sort interface for NodeEdge by Hash
type ByHash []*Edge
func (a ByHash) Len() int { return len(a) }
func (a ByHash) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByHash) Less(i, j int) bool { return a[i].Hash < a[j].Hash }