Notes added by 'git notes append'

This commit is contained in:
Jeff Carr 2025-02-07 09:57:22 -06:00
parent f3c22e164b
commit 8f4ad26de4
1 changed files with 170 additions and 0 deletions

View File

@ -1937,3 +1937,173 @@ func file_event_proto_init() {
} }
// `autogen:event.sort.pb.go` // `autogen:event.sort.pb.go`
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
// This file was autogenerated with autogenpb v0.0.50 2025-02-07_10:22:09_UTC
// 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 virtbuf
import (
"fmt"
"sync"
)
// a simple global lock
var eventMu sync.RWMutex
func (x *Events) fixUuid() {
if x == nil {
return
}
if x.Uuid == "1e3a50c7-5916-4423-b33c-f0b977a7e446" {
return
}
x.Uuid = "1e3a50c7-5916-4423-b33c-f0b977a7e446"
x.Version = "v0.0.1 go.wit.com/lib/protobuf/virtbuf"
}
func NewEvents() *Events {
x := new(Events)
x.Uuid = "1e3a50c7-5916-4423-b33c-f0b977a7e446"
x.Version = "v0.0.1 go.wit.com/lib/protobuf/virtbuf"
return x
}
// START SORT
// DEFINE THE Events ITERATOR.
// itializes a new iterator.
func newEventsIterator(things []*Events) *EventsIterator {
return &EventsIterator{things: things}
}
type EventsIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*Events
index int
}
func (it *EventsIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *EventsIterator) Next() *Events {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in EventsIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// DEFINE THE Event ITERATOR.
// itializes a new iterator.
func newEventIterator(things []*Event) *EventIterator {
return &EventIterator{things: things}
}
type EventIterator struct {
sync.RWMutex // this isn't getting used properly yet?
things []*Event
index int
}
func (it *EventIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *EventIterator) Next() *Event {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in EventIterator", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE ITERATOR
// safely returns a slice of pointers to the FRUIT protobufs
func (x *Events) allEvents() []*Event {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*Event
tmp = make([]*Event, len(x.Events))
for i, p := range x.Events {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the Event protobufs
func (x *Events) selectAllEvents() []*Event {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each Event
var tmp []*Event
tmp = make([]*Event, len(x.Events))
for i, p := range x.Events {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// END SORT
func (x *Events) Len() int {
x.RLock()
defer x.RUnlock()
return len(x.Events)
}
// just a simple Append() shortcut (but still uses the mutex lock)
func (x *Events) Append(y *Event) {
x.Lock()
defer x.Unlock()
x.Events = append(x.Events, y)
}
func (x *Events) All() *EventIterator {
EventPointers := x.selectAllEvents()
iterator := newEventIterator(EventPointers)
return iterator
}
func (x *Events) Delete(y *Event) bool {
x.Lock()
defer x.Unlock()
for i, _ := range x.Events {
if x.Events[i] == y {
x.Events[i] = x.Events[len(x.Events)-1]
x.Events = x.Events[:len(x.Events)-1]
return true
}
}
return false
}