summaryrefslogtreecommitdiff
path: root/sortNew.go
diff options
context:
space:
mode:
Diffstat (limited to 'sortNew.go')
-rw-r--r--sortNew.go41
1 files changed, 20 insertions, 21 deletions
diff --git a/sortNew.go b/sortNew.go
index 7ed81dd..9f6a829 100644
--- a/sortNew.go
+++ b/sortNew.go
@@ -30,28 +30,27 @@ func (msg *MsgName) simpleAppend(w io.Writer, FRUIT, APPLES, APPLE string) {
fmt.Fprintln(w, "")
}
-func (msg *MsgName) insertByColors(w io.Writer, FRUIT, APPLES, APPLE string, COLORS []string) {
+func (msg *MsgName) insertByColor(w io.Writer, FRUIT, APPLES, APPLE string, COLOR string) {
LOCK := msg.getLockname("x")
- for _, COLOR := range COLORS {
- fmt.Fprintln(w, "// TESTING")
- fmt.Fprintln(w, "// returns an "+APPLE+" if "+COLOR+" matches, otherwise create")
- fmt.Fprintln(w, "func (x *"+FRUIT+") InsertBy"+COLOR+" (y string) "+APPLE+" {")
- fmt.Fprintln(w, " "+LOCK+".Lock()")
- fmt.Fprintln(w, " defer "+LOCK+".Unlock()")
- fmt.Fprintln(w, "")
- fmt.Fprintln(w, " for _, p := range x."+APPLES+" {")
- fmt.Fprintln(w, " if p."+COLOR+" == "+COLOR+" {")
- fmt.Fprintln(w, " return p")
- fmt.Fprintln(w, " }")
- fmt.Fprintln(w, " }")
- fmt.Fprintln(w, "")
- fmt.Fprintln(w, " z := new("+APPLE+")")
- fmt.Fprintln(w, " z."+COLOR+" := y")
- fmt.Fprintln(w, " x."+APPLES+" = append(x."+APPLES+", z)")
- fmt.Fprintln(w, " return true")
- fmt.Fprintln(w, "}")
- fmt.Fprintln(w, "")
- }
+
+ fmt.Fprintln(w, "// TESTING")
+ fmt.Fprintln(w, "// returns an "+APPLE+" if "+COLOR+" matches, otherwise create")
+ fmt.Fprintln(w, "func (x *"+FRUIT+") InsertBy"+COLOR+" (y string) *"+APPLE+" {")
+ fmt.Fprintln(w, " "+LOCK+".Lock()")
+ fmt.Fprintln(w, " defer "+LOCK+".Unlock()")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, " for _, p := range x."+APPLES+" {")
+ fmt.Fprintln(w, " if p."+COLOR+" == y {")
+ fmt.Fprintln(w, " return p")
+ fmt.Fprintln(w, " }")
+ fmt.Fprintln(w, " }")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, " z := new("+APPLE+")")
+ fmt.Fprintln(w, " z."+COLOR+" = y")
+ fmt.Fprintln(w, " x."+APPLES+" = append(x."+APPLES+", z)")
+ fmt.Fprintln(w, " return z")
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w, "")
}
func (msg *MsgName) appendUnique(w io.Writer, FRUIT, APPLES, APPLE string, COLORS []string) {