// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. // This file was autogenerated with autogenpb v0.5.3-11-g737c5b7 2025.09.16_2337 // 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 gitpb import ( "fmt" "iter" "sort" "sync" "google.golang.org/protobuf/proto" ) // a simple global lock var goDepMu sync.RWMutex func (x *GoDeps) fixUuid() { if x == nil { return } if x.Uuid == "7de62c09-b335-4d80-902d-08552c501b7c" { return } x.Uuid = "7de62c09-b335-4d80-902d-08552c501b7c" x.Version = "v0.0.51 go.wit.com/lib/protobuf/gitpb" } func NewGoDeps() *GoDeps { x := new(GoDeps) x.Uuid = "7de62c09-b335-4d80-902d-08552c501b7c" x.Version = "v0.0.51 go.wit.com/lib/protobuf/gitpb" return x } // START SORT // DEFINE THE GoDeps SCANNER. // itializes a new scanner. func newGoDepsScanner(things []*GoDeps) *GoDepsScanner { return &GoDepsScanner{things: things} } type GoDepsScanner struct { sync.Mutex things []*GoDeps index int } func (it *GoDepsScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *GoDepsScanner) Next() *GoDeps { if it.things[it.index-1] == nil { fmt.Println("Next() error in GoDepsScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE GoDep SCANNER. // itializes a new scanner. func newGoDepScanner(things []*GoDep) *GoDepScanner { return &GoDepScanner{things: things} } type GoDepScanner struct { sync.Mutex things []*GoDep index int } func (it *GoDepScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *GoDepScanner) Next() *GoDep { if it.things[it.index-1] == nil { fmt.Println("Next() error in GoDepScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // sort struct by Hash type sortGoDepHash []*GoDep func (a sortGoDepHash) Len() int { return len(a) } func (a sortGoDepHash) Less(i, j int) bool { return a[i].Hash < a[j].Hash } func (a sortGoDepHash) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // sort struct by GoPath type sortGoDepGoPath []*GoDep func (a sortGoDepGoPath) Len() int { return len(a) } func (a sortGoDepGoPath) Less(i, j int) bool { return a[i].GoPath < a[j].GoPath } func (a sortGoDepGoPath) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // safely returns a slice of pointers to the FRUIT protobufs func (x *GoDeps) allGoDeps() []*GoDep { goDepMu.RLock() defer goDepMu.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*GoDep tmp = make([]*GoDep, len(x.GoDeps)) for i, p := range x.GoDeps { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the GoDep protobufs func (x *GoDeps) selectAllGoDeps() []*GoDep { goDepMu.RLock() defer goDepMu.RUnlock() // Create a new slice to hold pointers to each GoDep var tmp []*GoDep tmp = make([]*GoDep, len(x.GoDeps)) for i, p := range x.GoDeps { tmp[i] = p // Copy pointers for safe iteration } return tmp } func (x *GoDeps) SortByHash() *GoDepScanner { // copy the pointers as fast as possible. things := x.selectAllGoDeps() // todo: try slices.SortFunc() instead to see what happens sort.Sort(sortGoDepHash(things)) // slices.SortFunc(things, func(a, b *GoDeps) bool { // return a.Hash < b.Hash // Sort by ??. let the compiler work it out?? // }) return newGoDepScanner(things) } // 'for x := range' syntax using the awesome golang 1.24 'iter' func (x *GoDeps) IterByHash() iter.Seq[*GoDep] { items := x.selectAllGoDeps() sort.Sort(sortGoDepHash(items)) // log.Println("Made Iter.Seq[] with length", len(items)) return func(yield func(*GoDep) bool) { for _, v := range items { if !yield(v) { return } } } } func (x *GoDeps) SortByGoPath() *GoDepScanner { // copy the pointers as fast as possible. things := x.selectAllGoDeps() // todo: try slices.SortFunc() instead to see what happens sort.Sort(sortGoDepGoPath(things)) // slices.SortFunc(things, func(a, b *GoDeps) bool { // return a.GoPath < b.GoPath // Sort by ??. let the compiler work it out?? // }) return newGoDepScanner(things) } // 'for x := range' syntax using the awesome golang 1.24 'iter' func (x *GoDeps) IterByGoPath() iter.Seq[*GoDep] { items := x.selectAllGoDeps() sort.Sort(sortGoDepGoPath(items)) // log.Println("Made Iter.Seq[] with length", len(items)) return func(yield func(*GoDep) bool) { for _, v := range items { if !yield(v) { return } } } } // END SORT func (x *GoDeps) Len() int { goDepMu.RLock() defer goDepMu.RUnlock() return len(x.GoDeps) } // a Append() shortcut (that does Clone() with a mutex) notsure if it really works func (x *GoDeps) Append(y *GoDep) *GoDep { goDepMu.Lock() defer goDepMu.Unlock() z := proto.Clone(y).(*GoDep) x.GoDeps = append(x.GoDeps, z) return z } func (x *GoDeps) All() *GoDepScanner { GoDepPointers := x.selectAllGoDeps() scanner := newGoDepScanner(GoDepPointers) return scanner } // Iterate 'for x := range' syntax using the awesome golang 1.24 'iter' func (x *GoDeps) IterAll() iter.Seq[*GoDep] { items := x.selectAllGoDeps() // log.Println("Made All() Iter.Seq[] with length", len(items)) return func(yield func(*GoDep) bool) { for _, v := range items { if !yield(v) { return } } } } func (x *GoDeps) Delete(y *GoDep) bool { goDepMu.Lock() defer goDepMu.Unlock() for i, _ := range x.GoDeps { if x.GoDeps[i] == y { x.GoDeps[i] = x.GoDeps[len(x.GoDeps)-1] x.GoDeps = x.GoDeps[:len(x.GoDeps)-1] return true } } return false } // lookup a GoDeps by the Hash func (x *GoDeps) FindByHash(s string) *GoDep { if x == nil { return nil } goDepMu.RLock() defer goDepMu.RUnlock() for i, _ := range x.GoDeps { if x.GoDeps[i].Hash == s { return x.GoDeps[i] } } return nil } // returns a GoDep if Hash matches, otherwise create func (x *GoDeps) InsertByHash(y string) *GoDep { goDepMu.Lock() defer goDepMu.Unlock() for _, z := range x.GoDeps { if z.Hash == y { return z } } z := new(GoDep) z.Hash = y x.GoDeps = append(x.GoDeps, z) return z } // lookup a GoDeps by the GoPath func (x *GoDeps) FindByGoPath(s string) *GoDep { if x == nil { return nil } goDepMu.RLock() defer goDepMu.RUnlock() for i, _ := range x.GoDeps { if x.GoDeps[i].GoPath == s { return x.GoDeps[i] } } return nil } // returns a GoDep if GoPath matches, otherwise create func (x *GoDeps) InsertByGoPath(y string) *GoDep { goDepMu.Lock() defer goDepMu.Unlock() for _, z := range x.GoDeps { if z.GoPath == y { return z } } z := new(GoDep) z.GoPath = y x.GoDeps = append(x.GoDeps, z) return z } func (x *GoDeps) DeleteByHash(s string) bool { goDepMu.Lock() defer goDepMu.Unlock() for i, _ := range x.GoDeps { if x.GoDeps[i].Hash == s { x.GoDeps[i] = x.GoDeps[len(x.GoDeps)-1] x.GoDeps = x.GoDeps[:len(x.GoDeps)-1] return true } } return false } func (x *GoDeps) DeleteByGoPath(s string) bool { goDepMu.Lock() defer goDepMu.Unlock() for i, _ := range x.GoDeps { if x.GoDeps[i].GoPath == s { x.GoDeps[i] = x.GoDeps[len(x.GoDeps)-1] x.GoDeps = x.GoDeps[:len(x.GoDeps)-1] return true } } return false } func (x *GoDeps) AppendByHash(y *GoDep) bool { goDepMu.Lock() defer goDepMu.Unlock() for _, p := range x.GoDeps { if p.Hash == y.Hash { return false } } x.GoDeps = append(x.GoDeps, proto.Clone(y).(*GoDep)) return true } func (x *GoDeps) AppendByGoPath(y *GoDep) bool { goDepMu.Lock() defer goDepMu.Unlock() for _, p := range x.GoDeps { if p.GoPath == y.GoPath { return false } } x.GoDeps = append(x.GoDeps, proto.Clone(y).(*GoDep)) return true }