AddParent() function to optimise the case where there is only one parent

Avoids creating and discarding a StringSet just to carry the
parameters, and makes the code more readable too.
This commit is contained in:
Bryan Boreham
2018-07-17 13:51:46 +00:00
parent 0d2409c72c
commit 5edc85822b
7 changed files with 14 additions and 18 deletions
+6
View File
@@ -152,6 +152,12 @@ func (n Node) WithLatestControl(control string, ts time.Time, data NodeControlDa
return n
}
// WithParent returns a fresh copy of n, with one parent added
func (n Node) WithParent(key, parent string) Node {
n.Parents = n.Parents.AddString(key, parent)
return n
}
// WithParents returns a fresh copy of n, with sets merged in.
func (n Node) WithParents(parents Sets) Node {
n.Parents = n.Parents.Merge(parents)