Skip to content

Commit 6a13f82

Browse files
committed
Add documentation for edge weights. Closes #14
1 parent ed4697f commit 6a13f82

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,26 @@ Removes the specified node. Returns *graph* to support method chaining. The argu
116116

117117
### Adding and Removing Edges
118118

119-
<a name="add-edge" href="#add-edge">#</a> <i>graph</i>.<b>addEdge</b>(<i>u</i>, <i>v</i>)
119+
<a name="add-edge" href="#add-edge">#</a> <i>graph</i>.<b>addEdge</b>(<i>u</i>, <i>v</i>[,<i>weight</i>])
120120

121121
Adds an edge from node *u* to node *v*. Returns *graph* to support method chaining. The arguments *u* and *v* are string identifiers for nodes. This function also adds *u* and *v* as nodes if they were not already added.
122122

123+
The last argument *weight* (optional) specifies the weight of this edge.
124+
123125
<a name="remove-edge" href="#remove-edge">#</a> <i>graph</i>.<b>removeEdge</b>(<i>u</i>, <i>v</i>)
124126

125127
Removes the edge from node *u* to node *v*. Returns *graph* to support method chaining. The arguments *u* and *v* are string identifiers for nodes. This function does not remove the nodes *u* and *v*. Does nothing if the edge does not exist.
126128

129+
### Working with Edge Weights
130+
131+
<a name="set-edge-weight" href="#set-edge-weight">#</a> <i>graph</i>.<b>setEdgeWeight</b>(<i>u</i>, <i>v</i>, <i>weight</i>)
132+
133+
Sets the *weight* (a number) of the edge from node *u* to node *v*.
134+
135+
<a name="get-edge-weight" href="#get-edge-weight">#</a> <i>graph</i>.<b>getEdgeWeight</b>(<i>u</i>, <i>v</i>, <i>weight</i>)
136+
137+
Gets the *weight* of the edge from node *u* to node *v*. If no weight was previously set on this edge, then the value 1 is returned.
138+
127139
### Querying the Graph
128140

129141
<a name="nodes" href="#nodes">#</a> <i>graph</i>.<b>nodes</b>()

0 commit comments

Comments
 (0)