1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
// This file was autogenerated with autogenpb v0.0.42-1-gf74f364 2025.01.13_0345
// go install go.wit.com/apps/autogenpb@latest
//
// define which structs (messages) you want to use in the .proto file
// Then sort.pb.go and marshal.pb.go files are autogenerated
//
// autogenpb uses it and has an example .proto file with instructions
//
package main
import (
"fmt"
"sync"
)
// a simple global lock
var fileMu sync.RWMutex
// START SORT
// DEFINE THE Files ITERATOR.
// itializes a new iterator.
func newFilesIterator(things []*Files) *FilesIterator {
return &FilesIterator{things: things}
}
type FilesIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*Files
index int
}
func (it *FilesIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *FilesIterator) Next() *Files {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in FilesIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// DEFINE THE File ITERATOR.
// itializes a new iterator.
func newFileIterator(things []*File) *FileIterator {
return &FileIterator{things: things}
}
type FileIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*File
index int
}
func (it *FileIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *FileIterator) Next() *File {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in FileIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// DEFINE THE MsgVar ITERATOR.
// itializes a new iterator.
func newMsgVarIterator(things []*MsgVar) *MsgVarIterator {
return &MsgVarIterator{things: things}
}
type MsgVarIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*MsgVar
index int
}
func (it *MsgVarIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *MsgVarIterator) Next() *MsgVar {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in MsgVarIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// DEFINE THE MsgName ITERATOR.
// itializes a new iterator.
func newMsgNameIterator(things []*MsgName) *MsgNameIterator {
return &MsgNameIterator{things: things}
}
type MsgNameIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*MsgName
index int
}
func (it *MsgNameIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *MsgNameIterator) Next() *MsgName {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in MsgNameIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// DEFINE THE Sort ITERATOR.
// itializes a new iterator.
func newSortIterator(things []*Sort) *SortIterator {
return &SortIterator{things: things}
}
type SortIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*Sort
index int
}
func (it *SortIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *SortIterator) Next() *Sort {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in SortIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// DEFINE THE Find ITERATOR.
// itializes a new iterator.
func newFindIterator(things []*Find) *FindIterator {
return &FindIterator{things: things}
}
type FindIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*Find
index int
}
func (it *FindIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *FindIterator) Next() *Find {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in FindIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// DEFINE THE Identify ITERATOR.
// itializes a new iterator.
func newIdentifyIterator(things []*Identify) *IdentifyIterator {
return &IdentifyIterator{things: things}
}
type IdentifyIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*Identify
index int
}
func (it *IdentifyIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *IdentifyIterator) Next() *Identify {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in IdentifyIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// safely returns a slice of pointers to the FRUIT protobufs
func (x *Files) allFiles() []*File {
x.Lock.RLock()
defer x.Lock.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*File
tmp = make([]*File, len(x.Files))
for i, p := range x.Files {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the FRUIT protobufs
func (x *File) allMsgNames() []*MsgName {
x.Lock.RLock()
defer x.Lock.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*MsgName
tmp = make([]*MsgName, len(x.MsgNames))
for i, p := range x.MsgNames {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the FRUIT protobufs
func (x *File) allSortNames() []*MsgName {
x.Lock.RLock()
defer x.Lock.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*MsgName
tmp = make([]*MsgName, len(x.SortNames))
for i, p := range x.SortNames {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the FRUIT protobufs
func (x *File) allToSort() []*Sort {
x.Lock.RLock()
defer x.Lock.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*Sort
tmp = make([]*Sort, len(x.ToSort))
for i, p := range x.ToSort {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the FRUIT protobufs
func (x *MsgName) allVars() []*MsgVar {
x.Lock.RLock()
defer x.Lock.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*MsgVar
tmp = make([]*MsgVar, len(x.Vars))
for i, p := range x.Vars {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the File protobufs
func (x *Files) selectAllFiles() []*File {
x.Lock.RLock()
defer x.Lock.RUnlock()
// Create a new slice to hold pointers to each File
var tmp []*File
tmp = make([]*File, len(x.Files))
for i, p := range x.Files {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the MsgName protobufs
func (x *File) selectAllMsgNames() []*MsgName {
x.Lock.RLock()
defer x.Lock.RUnlock()
// Create a new slice to hold pointers to each MsgName
var tmp []*MsgName
tmp = make([]*MsgName, len(x.MsgNames))
for i, p := range x.MsgNames {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the MsgName protobufs
func (x *File) selectAllSortNames() []*MsgName {
x.Lock.RLock()
defer x.Lock.RUnlock()
// Create a new slice to hold pointers to each MsgName
var tmp []*MsgName
tmp = make([]*MsgName, len(x.SortNames))
for i, p := range x.SortNames {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the Sort protobufs
func (x *File) selectAllToSort() []*Sort {
x.Lock.RLock()
defer x.Lock.RUnlock()
// Create a new slice to hold pointers to each Sort
var tmp []*Sort
tmp = make([]*Sort, len(x.ToSort))
for i, p := range x.ToSort {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the MsgVar protobufs
func (x *MsgName) selectAllVars() []*MsgVar {
x.Lock.RLock()
defer x.Lock.RUnlock()
// Create a new slice to hold pointers to each MsgVar
var tmp []*MsgVar
tmp = make([]*MsgVar, len(x.Vars))
for i, p := range x.Vars {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// END SORT
func (x *Files) Len() int {
x.Lock.RLock()
defer x.Lock.RUnlock()
return len(x.Files)
}
// just a simple Append() shortcut (but still uses the mutex lock)
func (x *Files) Append(y *File) {
x.Lock.Lock()
defer x.Lock.Unlock()
x.Files = append(x.Files, y)
}
func (x *Files) All() *FileIterator {
FilePointers := x.selectAllFiles()
iterator := newFileIterator(FilePointers)
return iterator
}
|