summaryrefslogtreecommitdiff
path: root/generateSort.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-12 08:28:23 -0600
committerJeff Carr <[email protected]>2025-01-12 08:28:23 -0600
commit10f75f87a66a9329fd665bd85099fe94c7beae79 (patch)
tree5746e3e18d3bdf3d8213798436ee93d0dd052772 /generateSort.go
parent721bbd8f92d80286f12509fbbcff9f2f8e334093 (diff)
add nomutex support to disable it per message struct
Diffstat (limited to 'generateSort.go')
-rw-r--r--generateSort.go31
1 files changed, 23 insertions, 8 deletions
diff --git a/generateSort.go b/generateSort.go
index b92a4b1..3f14e21 100644
--- a/generateSort.go
+++ b/generateSort.go
@@ -5,7 +5,9 @@ import (
"io"
)
-func newIterAll(w io.Writer, FRUIT, APPLE, APPLES, LOCK string) string {
+func (msg *MsgName) newIterAll(w io.Writer, FRUIT, APPLE, APPLES, LOCK string) string {
+ LOCK = msg.getLockname("x")
+
funcdef := "func (x *" + FRUIT + ") all" + APPLES + "() []*" + APPLE + " {"
fmt.Fprintln(w, "// safely returns a slice of pointers to the FRUIT protobufs")
@@ -35,7 +37,9 @@ func newIter(w io.Writer, msg *MsgName) string {
msg.NeedIter = false
APPLE := msg.Name
- funcdef := "func New" + APPLE + "Iterator(things []*" + APPLE + ") *" + APPLE + "Iterator"
+ // should this be 'new' or 'New' ? Does it matter? I think it's totally internal here
+ // in this file where it is "new or "New". I changed it to lower case 2025.01.12
+ funcdef := "func new" + APPLE + "Iterator(things []*" + APPLE + ") *" + APPLE + "Iterator"
fmt.Fprintln(w, "// DEFINE THE", APPLE, "ITERATOR.")
fmt.Fprintln(w, "// itializes a new iterator.")
@@ -76,6 +80,8 @@ func newIter(w io.Writer, msg *MsgName) string {
// TODO; figure out what types this actually works on
// TODO; add timestamppb compare
func newSortType(w io.Writer, STRUCT, VARNAME string) string {
+
+ // Can these be lower case? Should they be lower case? maybe sort.Sort() requires upper case?
fmt.Fprintln(w, "// sort struct by", VARNAME)
fmt.Fprintln(w, "type "+STRUCT+VARNAME+" []*"+STRUCT+"")
fmt.Fprintln(w, "")
@@ -87,16 +93,21 @@ func newSortType(w io.Writer, STRUCT, VARNAME string) string {
return "type " + STRUCT + VARNAME + " []*" + STRUCT + " // { return a[i]." + VARNAME + " < a[j]." + VARNAME + " }"
}
-func newSortBy(w io.Writer, STRUCT, ITER, SORTNAME, SORTBY, SELECT string) string {
+func newSortBy(w io.Writer, STRUCT, ITER, SORTNAME, SORTBY, SELECT, VARNAME string) string {
funcdef := "func (x *" + STRUCT + ") " + SORTBY + "() *" + ITER + "Iterator"
fmt.Fprintln(w, funcdef, "{")
+ fmt.Fprintln(w, " // copy the pointers as fast as possible.")
fmt.Fprintln(w, " things := x."+SELECT+"()")
fmt.Fprintln(w, "")
+ fmt.Fprintln(w, "// todo: try slices.SortFunc() instead to see what happens")
fmt.Fprintln(w, " sort.Sort("+SORTNAME+"(things))")
- fmt.Fprintln(w, "")
- fmt.Fprintln(w, " iterator := New"+ITER+"Iterator(things)")
- fmt.Fprintln(w, " return iterator")
+ fmt.Fprintln(w, "// slices.SortFunc(things, func(a, b *"+STRUCT+") bool {")
+ fmt.Fprintln(w, "// return a."+VARNAME+" < b."+VARNAME+" // Sort by ??. let the compiler work it out??")
+ fmt.Fprintln(w, "// })")
+ // should this be 'new' or 'New' ? Does it matter? I think it's totally internal here
+ // in this file where it is "new or "New". I changed it to lower case 2025.01.12
+ fmt.Fprintln(w, " return new"+ITER+"Iterator(things)")
fmt.Fprintln(w, "}")
return funcdef
@@ -108,7 +119,9 @@ func addAllFunc(w io.Writer, FRUIT, APPLE, APPLES string) string {
fmt.Fprintln(w, funcdef)
fmt.Fprintln(w, " "+APPLE+"Pointers := x.selectAll"+APPLES+"()")
fmt.Fprintln(w, "")
- fmt.Fprintln(w, " iterator := New"+APPLE+"Iterator("+APPLE+"Pointers)")
+ // should this be 'new' or 'New' ? Does it matter? I think it's totally internal here. I think there are only 3 places
+ // in this file where it is "new or "New". I changed it to lower case 2025.01.12
+ fmt.Fprintln(w, " iterator := new"+APPLE+"Iterator("+APPLE+"Pointers)")
fmt.Fprintln(w, " return iterator")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
@@ -130,7 +143,9 @@ func addLenFunc(w io.Writer, FRUIT, APPLES, LOCK string) string {
return funcdef
}
-func addSelectAll(w io.Writer, FRUIT, APPLE, APPLES, LOCK string) string {
+func (msg *MsgName) addSelectAll(w io.Writer, FRUIT, APPLE, APPLES, LOCK string) string {
+ LOCK = msg.getLockname("x")
+
funcdef := "func (x *" + FRUIT + ") selectAll" + APPLES + "() []*" + APPLE
fmt.Fprintln(w, "// safely returns a slice of pointers to the "+APPLE+" protobufs")
fmt.Fprintln(w, funcdef, "{")