Skip to content

Commit

Permalink
graph: revert NewNodeID -> NewNode
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Jul 6, 2017
1 parent e1b3c53 commit 39b486f
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 26 deletions.
2 changes: 0 additions & 2 deletions graph/encoding/dot/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
type Builder interface {
graph.Graph
graph.Builder
// NewNode adds a new node with a unique node ID to the graph.
NewNode() graph.Node
// NewEdge adds a new edge from the source to the destination node to the
// graph, or returns the existing edge if already present.
NewEdge(from, to graph.Node) graph.Edge
Expand Down
6 changes: 3 additions & 3 deletions graph/encoding/dot/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func newDotDirectedGraph() *dotDirectedGraph {

// NewNode adds a new node with a unique node ID to the graph.
func (g *dotDirectedGraph) NewNode() graph.Node {
n := &dotNode{Node: simple.Node(g.NewNodeID())}
n := &dotNode{Node: g.DirectedGraph.NewNode()}
g.AddNode(n)
return n
}
Expand Down Expand Up @@ -157,7 +157,7 @@ func newDotUndirectedGraph() *dotUndirectedGraph {

// NewNode adds a new node with a unique node ID to the graph.
func (g *dotUndirectedGraph) NewNode() graph.Node {
n := &dotNode{Node: simple.Node(g.NewNodeID())}
n := &dotNode{Node: g.UndirectedGraph.NewNode()}
g.AddNode(n)
return n
}
Expand Down Expand Up @@ -186,7 +186,7 @@ func (g *dotUndirectedGraph) DOTUnmarshalerAttrs() (graph, node, edge Unmarshale
// dotNode extends simple.Node with a label field to test round-trip encoding
// and decoding of node DOT label attributes.
type dotNode struct {
simple.Node
graph.Node
dotID string
// Node label.
Label string
Expand Down
5 changes: 3 additions & 2 deletions graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ type Weighter interface {

// NodeAdder is an interface for adding arbitrary nodes to a graph.
type NodeAdder interface {
// NewNodeID returns a new unique arbitrary ID.
NewNodeID() int64
// NewNode returns a new Node with a unique
// arbitrary ID.
NewNode() Node

// Adds a node to the graph. AddNode panics if
// the added node ID matches an existing node ID.
Expand Down
4 changes: 2 additions & 2 deletions graph/graphs/gen/duplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ func Duplication(dst UndirectedMutator, n int, delta, alpha, sigma float64, src
sort.Sort(ordered.ByID(nodes))
if len(nodes) == 0 {
n--
u := simple.Node(dst.NewNodeID())
u := dst.NewNode()
dst.AddNode(u)
nodes = append(nodes, u)
}
for i := 0; i < n; i++ {
u := nodes[rndN(len(nodes))]
d := simple.Node(dst.NewNodeID())
d := dst.NewNode()

// Add the duplicate node.
dst.AddNode(d)
Expand Down
10 changes: 5 additions & 5 deletions graph/simple/directed.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ func NewDirectedGraph(self, absent float64) *DirectedGraph {
}
}

// NewNodeID returns a new unique ID for a node to be added to g. The returned ID does
// not become a valid ID in g until it is added to g.
func (g *DirectedGraph) NewNodeID() int64 {
// NewNode returns a new unique Node to be added to g. The Node's ID does
// not become valid in g until the Node is added to g.
func (g *DirectedGraph) NewNode() graph.Node {
if len(g.nodes) == 0 {
return 0
return Node(0)
}
if int64(len(g.nodes)) == maxInt {
panic("simple: cannot allocate node: no slot")
}
return g.nodeIDs.newID()
return Node(g.nodeIDs.newID())
}

// AddNode adds n to the graph. It panics if the added node ID matches an existing node ID.
Expand Down
6 changes: 3 additions & 3 deletions graph/simple/directed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ func TestIssue123DirectedGraph(t *testing.T) {
}()
g := NewDirectedGraph(0, math.Inf(1))

n0 := Node(g.NewNodeID())
n0 := g.NewNode()
g.AddNode(n0)

n1 := Node(g.NewNodeID())
n1 := g.NewNode()
g.AddNode(n1)

g.RemoveNode(n0)

n2 := Node(g.NewNodeID())
n2 := g.NewNode()
g.AddNode(n2)
}
10 changes: 5 additions & 5 deletions graph/simple/undirected.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ func NewUndirectedGraph(self, absent float64) *UndirectedGraph {
}
}

// NewNodeID returns a new unique ID for a node to be added to g. The returned ID does
// not become a valid ID in g until it is added to g.
func (g *UndirectedGraph) NewNodeID() int64 {
// NewNode returns a new unique Node to be added to g. The Node's ID does
// not become valid in g until the Node is added to g.
func (g *UndirectedGraph) NewNode() graph.Node {
if len(g.nodes) == 0 {
return 0
return Node(0)
}
if int64(len(g.nodes)) == maxInt {
panic("simple: cannot allocate node: no slot")
}
return g.nodeIDs.newID()
return Node(g.nodeIDs.newID())
}

// AddNode adds n to the graph. It panics if the added node ID matches an existing node ID.
Expand Down
8 changes: 4 additions & 4 deletions graph/simple/undirected_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestMaxID(t *testing.T) {
delete(nodes, Node(0))
g.RemoveNode(Node(2))
delete(nodes, Node(2))
n := Node(g.NewNodeID())
n := g.NewNode()
g.AddNode(n)
if !g.Has(n) {
t.Error("added node does not exist in graph")
Expand All @@ -50,14 +50,14 @@ func TestIssue123UndirectedGraph(t *testing.T) {
}()
g := NewUndirectedGraph(0, math.Inf(1))

n0 := Node(g.NewNodeID())
n0 := g.NewNode()
g.AddNode(n0)

n1 := Node(g.NewNodeID())
n1 := g.NewNode()
g.AddNode(n1)

g.RemoveNode(n0)

n2 := Node(g.NewNodeID())
n2 := g.NewNode()
g.AddNode(n2)
}

0 comments on commit 39b486f

Please sign in to comment.