needed DeleteBy()

This commit is contained in:
Jeff Carr 2025-01-09 21:15:01 -06:00
parent 805d3cdcc3
commit 02e868647f
2 changed files with 20 additions and 19 deletions

View File

@ -21,5 +21,6 @@ func (pb *Files) makeNewSortfile(pf *File) error {
pf.appendUnique(f) // Append() enforce no unique keys pf.appendUnique(f) // Append() enforce no unique keys
pf.iterSortBy(f) pf.iterSortBy(f)
pf.iterAll(f) pf.iterAll(f)
pf.iterDelete(f)
return nil return nil
} }

26
sort.go
View File

@ -223,20 +223,19 @@ func iterReplace(w io.Writer, names map[string]string) {
fmt.Fprintln(w, "") fmt.Fprintln(w, "")
} }
func iterDelete(w io.Writer, names map[string]string) { func (pf *File) iterDelete(w io.Writer) {
fmt.Fprintln(w, "func (all *"+names["Bases"]+") DeleteBy"+names["append"]+"(s string) bool {") var MSG string = pf.Bases.Name
if sortmap["lock"] == "all" { var LOCK string = pf.Bases.Lockname
fmt.Fprintln(w, " "+names["lock"]+".Lock.RLock()")
fmt.Fprintln(w, " defer "+names["lock"]+".Lock.RUnlock()") for _, KEY := range pf.Base.Sort {
} else { fmt.Fprintln(w, "func (all *"+MSG+") DeleteBy"+KEY+"(s string) bool {")
fmt.Fprintln(w, " "+names["lock"]+".RLock()") fmt.Fprintln(w, " "+LOCK+".RLock()")
fmt.Fprintln(w, " defer "+names["lock"]+".RUnlock()") fmt.Fprintln(w, " defer "+LOCK+".RUnlock()")
}
fmt.Fprintln(w, "") fmt.Fprintln(w, "")
fmt.Fprintln(w, " for i, _ := range all."+names["Bases"]+" {") fmt.Fprintln(w, " for i, _ := range all."+MSG+" {")
fmt.Fprintln(w, " if all."+names["Bases"]+"[i]."+names["append"]+" == s {") fmt.Fprintln(w, " if all."+MSG+"[i]."+KEY+" == s {")
fmt.Fprintln(w, " all."+names["Bases"]+"[i] = all."+names["Bases"]+"[len(all."+names["Bases"]+")-1]") fmt.Fprintln(w, " all."+MSG+"[i] = all."+MSG+"[len(all."+MSG+")-1]")
fmt.Fprintln(w, " all."+names["Bases"]+" = all."+names["Bases"]+"[:len(all."+names["Bases"]+")-1]") fmt.Fprintln(w, " all."+MSG+" = all."+MSG+"[:len(all."+MSG+")-1]")
fmt.Fprintln(w, " return true") fmt.Fprintln(w, " return true")
fmt.Fprintln(w, " }") fmt.Fprintln(w, " }")
fmt.Fprintln(w, " }") fmt.Fprintln(w, " }")
@ -244,6 +243,7 @@ func iterDelete(w io.Writer, names map[string]string) {
fmt.Fprintln(w, "}") fmt.Fprintln(w, "}")
fmt.Fprintln(w, "") fmt.Fprintln(w, "")
} }
}
// this tries to return the deleted one but is wrong/gives warning if mutex lock is in struct // this tries to return the deleted one but is wrong/gives warning if mutex lock is in struct
func iterDeleteWithCopy(w io.Writer, names map[string]string) { func iterDeleteWithCopy(w io.Writer, names map[string]string) {