Notes added by 'git notes append'

This commit is contained in:
Jeff Carr 2025-01-20 08:01:57 -06:00
parent 91f729a100
commit 4183c47d1c
1 changed files with 174 additions and 0 deletions

View File

@ -904,3 +904,177 @@ func file_package_proto_init() {
}
// `autogen:package.sort.pb.go`
package zoopb
// This file was autogenerated with autogenpb v0.0.33 DO NOT EDIT
// go install go.wit.com/apps/autogenpb@latest
//
// You can use it on simple protobuf files
// The .proto file must have a singular and plural form of a message
// (for those of you that know ruby on rails, it's like that)
//
// You can mark which repos you want to auto generate sort.pb.go and marshal.pb.go files for
//
// For an example,
// go-clone go.wit.com/lib/protobuf/gitpb
//
import (
"fmt"
"sort"
"sync"
)
type PackageIterator struct {
sync.RWMutex
packs []*Package
index int
}
// NewPackageIterator initializes a new iterator.
func NewPackageIterator(packs []*Package) *PackageIterator {
return &PackageIterator{packs: packs}
}
// Scan moves to the next element and returns false if there are no more packs.
// Use Scan() in a loop, similar to a while loop
//
// for iterator.Scan()
// d := iterator.Next(
// fmt.Println("found UUID:", d.Uuid
// }
func (it *PackageIterator) Scan() bool {
if it.index >= len(it.packs) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *PackageIterator) Next() *Package {
if it.packs[it.index-1] == nil {
for i, d := range it.packs {
fmt.Println("i =", i, d)
}
// fmt.Println("protobuf autogenpb sort error len =", len(it.packs))
// fmt.Println("protobuf autogenpb sort error next == nil", it.index, it.index-1)
}
return it.packs[it.index-1]
}
// does not enforce any unique fields
func (all *Packages) Append(newP *Package) bool {
all.Lock.RLock()
defer all.Lock.RUnlock()
all.Packages = append(all.Packages, newP)
return true
}
func (all *Packages) All() *PackageIterator {
packagePointers := all.selectAllPackage()
iterator := NewPackageIterator(packagePointers)
return iterator
}
func (all *Packages) Len() int {
all.Lock.RLock()
defer all.Lock.RUnlock()
return len(all.Packages)
}
func (all *Packages) SortByName() *PackageIterator {
packs := all.selectAllPackage()
sort.Sort(PackageName(packs))
iterator := NewPackageIterator(packs)
return iterator
}
type PackageName []*Package
func (a PackageName) Len() int { return len(a) }
func (a PackageName) Less(i, j int) bool { return a[i].Name < a[j].Name }
func (a PackageName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
// enforces Name is unique
func (all *Packages) AppendUniqueName(newP *Package) bool {
all.Lock.RLock()
defer all.Lock.RUnlock()
for _, p := range all.Packages {
if p.Name == newP.Name {
return false
}
}
all.Packages = append(all.Packages, newP)
return true
}
func (all *Packages) DeleteByName(s string) bool {
all.Lock.RLock()
defer all.Lock.RUnlock()
for i, _ := range all.Packages {
if all.Packages[i].Name == s {
all.Packages[i] = all.Packages[len(all.Packages)-1]
all.Packages = all.Packages[:len(all.Packages)-1]
return true
}
}
return false
}
// enforces Name is unique
func (all *Packages) ReplaceName(newP *Package) bool { // todo: make unique name here
all.Lock.RLock()
defer all.Lock.RUnlock()
for _, p := range all.Packages {
if p.Name == newP.Name {
return false
}
}
all.Packages = append(all.Packages, newP)
return true
}
// find a dependancy by the go path
func (all *Packages) FindByName(s string) *Package {
if all == nil {
return nil
}
all.Lock.RLock()
defer all.Lock.RUnlock()
for i, _ := range all.Packages {
if all.Packages[i].Name == s {
return all.Packages[i]
}
}
return nil
}
// safely returns a slice of pointers to the Package protobufs
func (all *Packages) selectAllPackage() []*Package {
all.Lock.RLock()
defer all.Lock.RUnlock()
// Create a new slice to hold pointers to each Package
var aStuff []*Package
aStuff = make([]*Package, len(all.Packages))
for i, p := range all.Packages {
aStuff[i] = p // Copy pointers for safe iteration
}
return aStuff
}