Notes added by 'git notes append'
This commit is contained in:
parent
0f66a39528
commit
d88d8a90d5
|
@ -2518,3 +2518,235 @@ func file_experiment_proto_init() {
|
|||
}
|
||||
|
||||
// `autogen:experiment.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 experimentMu sync.RWMutex
|
||||
|
||||
func (x *Experiments) fixUuid() {
|
||||
if x == nil {
|
||||
return
|
||||
}
|
||||
if x.Uuid == "aadb95db-d798-4647-8c59-cce82e8f1ed6" {
|
||||
return
|
||||
}
|
||||
x.Uuid = "aadb95db-d798-4647-8c59-cce82e8f1ed6"
|
||||
x.Version = "v0.0.1 go.wit.com/lib/protobuf/virtbuf"
|
||||
}
|
||||
|
||||
func NewExperiments() *Experiments {
|
||||
x := new(Experiments)
|
||||
x.Uuid = "aadb95db-d798-4647-8c59-cce82e8f1ed6"
|
||||
x.Version = "v0.0.1 go.wit.com/lib/protobuf/virtbuf"
|
||||
return x
|
||||
}
|
||||
|
||||
// START SORT
|
||||
|
||||
// DEFINE THE Experiments ITERATOR.
|
||||
// itializes a new iterator.
|
||||
func newExperimentsIterator(things []*Experiments) *ExperimentsIterator {
|
||||
return &ExperimentsIterator{things: things}
|
||||
}
|
||||
|
||||
type ExperimentsIterator struct {
|
||||
sync.RWMutex // this isn't getting used properly yet?
|
||||
|
||||
things []*Experiments
|
||||
index int
|
||||
}
|
||||
|
||||
func (it *ExperimentsIterator) Scan() bool {
|
||||
if it.index >= len(it.things) {
|
||||
return false
|
||||
}
|
||||
it.index++
|
||||
return true
|
||||
}
|
||||
|
||||
// Next() returns the next thing in the array
|
||||
func (it *ExperimentsIterator) Next() *Experiments {
|
||||
if it.things[it.index-1] == nil {
|
||||
fmt.Println("Next() error in ExperimentsIterator", it.index)
|
||||
}
|
||||
return it.things[it.index-1]
|
||||
}
|
||||
|
||||
// END DEFINE THE ITERATOR
|
||||
|
||||
// DEFINE THE Experiment ITERATOR.
|
||||
// itializes a new iterator.
|
||||
func newExperimentIterator(things []*Experiment) *ExperimentIterator {
|
||||
return &ExperimentIterator{things: things}
|
||||
}
|
||||
|
||||
type ExperimentIterator struct {
|
||||
sync.RWMutex // this isn't getting used properly yet?
|
||||
|
||||
things []*Experiment
|
||||
index int
|
||||
}
|
||||
|
||||
func (it *ExperimentIterator) Scan() bool {
|
||||
if it.index >= len(it.things) {
|
||||
return false
|
||||
}
|
||||
it.index++
|
||||
return true
|
||||
}
|
||||
|
||||
// Next() returns the next thing in the array
|
||||
func (it *ExperimentIterator) Next() *Experiment {
|
||||
if it.things[it.index-1] == nil {
|
||||
fmt.Println("Next() error in ExperimentIterator", it.index)
|
||||
}
|
||||
return it.things[it.index-1]
|
||||
}
|
||||
|
||||
// END DEFINE THE ITERATOR
|
||||
|
||||
// DEFINE THE WhatsThis ITERATOR.
|
||||
// itializes a new iterator.
|
||||
func newWhatsThisIterator(things []*WhatsThis) *WhatsThisIterator {
|
||||
return &WhatsThisIterator{things: things}
|
||||
}
|
||||
|
||||
type WhatsThisIterator struct {
|
||||
sync.RWMutex // this isn't getting used properly yet?
|
||||
|
||||
things []*WhatsThis
|
||||
index int
|
||||
}
|
||||
|
||||
func (it *WhatsThisIterator) Scan() bool {
|
||||
if it.index >= len(it.things) {
|
||||
return false
|
||||
}
|
||||
it.index++
|
||||
return true
|
||||
}
|
||||
|
||||
// Next() returns the next thing in the array
|
||||
func (it *WhatsThisIterator) Next() *WhatsThis {
|
||||
if it.things[it.index-1] == nil {
|
||||
fmt.Println("Next() error in WhatsThisIterator", it.index)
|
||||
}
|
||||
return it.things[it.index-1]
|
||||
}
|
||||
|
||||
// END DEFINE THE ITERATOR
|
||||
|
||||
// DEFINE THE WhatInfo ITERATOR.
|
||||
// itializes a new iterator.
|
||||
func newWhatInfoIterator(things []*WhatInfo) *WhatInfoIterator {
|
||||
return &WhatInfoIterator{things: things}
|
||||
}
|
||||
|
||||
type WhatInfoIterator struct {
|
||||
sync.RWMutex // this isn't getting used properly yet?
|
||||
|
||||
things []*WhatInfo
|
||||
index int
|
||||
}
|
||||
|
||||
func (it *WhatInfoIterator) Scan() bool {
|
||||
if it.index >= len(it.things) {
|
||||
return false
|
||||
}
|
||||
it.index++
|
||||
return true
|
||||
}
|
||||
|
||||
// Next() returns the next thing in the array
|
||||
func (it *WhatInfoIterator) Next() *WhatInfo {
|
||||
if it.things[it.index-1] == nil {
|
||||
fmt.Println("Next() error in WhatInfoIterator", it.index)
|
||||
}
|
||||
return it.things[it.index-1]
|
||||
}
|
||||
|
||||
// END DEFINE THE ITERATOR
|
||||
|
||||
// safely returns a slice of pointers to the FRUIT protobufs
|
||||
func (x *Experiments) allExperiments() []*Experiment {
|
||||
x.RLock()
|
||||
defer x.RUnlock()
|
||||
|
||||
// Create a new slice to hold pointers to each FRUIT
|
||||
var tmp []*Experiment
|
||||
tmp = make([]*Experiment, len(x.Experiments))
|
||||
for i, p := range x.Experiments {
|
||||
tmp[i] = p // Copy pointers for safe iteration
|
||||
}
|
||||
|
||||
return tmp
|
||||
}
|
||||
|
||||
// safely returns a slice of pointers to the Experiment protobufs
|
||||
func (x *Experiments) selectAllExperiments() []*Experiment {
|
||||
x.RLock()
|
||||
defer x.RUnlock()
|
||||
|
||||
// Create a new slice to hold pointers to each Experiment
|
||||
var tmp []*Experiment
|
||||
tmp = make([]*Experiment, len(x.Experiments))
|
||||
for i, p := range x.Experiments {
|
||||
tmp[i] = p // Copy pointers for safe iteration
|
||||
}
|
||||
|
||||
return tmp
|
||||
}
|
||||
|
||||
// END SORT
|
||||
|
||||
func (x *Experiments) Len() int {
|
||||
x.RLock()
|
||||
defer x.RUnlock()
|
||||
|
||||
return len(x.Experiments)
|
||||
}
|
||||
|
||||
// just a simple Append() shortcut (but still uses the mutex lock)
|
||||
func (x *Experiments) Append(y *Experiment) {
|
||||
x.Lock()
|
||||
defer x.Unlock()
|
||||
|
||||
x.Experiments = append(x.Experiments, y)
|
||||
}
|
||||
|
||||
func (x *Experiments) All() *ExperimentIterator {
|
||||
ExperimentPointers := x.selectAllExperiments()
|
||||
|
||||
iterator := newExperimentIterator(ExperimentPointers)
|
||||
return iterator
|
||||
}
|
||||
|
||||
func (x *Experiments) Delete(y *Experiment) bool {
|
||||
x.Lock()
|
||||
defer x.Unlock()
|
||||
|
||||
for i, _ := range x.Experiments {
|
||||
if x.Experiments[i] == y {
|
||||
x.Experiments[i] = x.Experiments[len(x.Experiments)-1]
|
||||
x.Experiments = x.Experiments[:len(x.Experiments)-1]
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue