needed DeleteBy()
This commit is contained in:
parent
805d3cdcc3
commit
02e868647f
|
@ -21,5 +21,6 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
pf.appendUnique(f) // Append() enforce no unique keys
|
||||
pf.iterSortBy(f)
|
||||
pf.iterAll(f)
|
||||
pf.iterDelete(f)
|
||||
return nil
|
||||
}
|
||||
|
|
38
sort.go
38
sort.go
|
@ -223,26 +223,26 @@ func iterReplace(w io.Writer, names map[string]string) {
|
|||
fmt.Fprintln(w, "")
|
||||
}
|
||||
|
||||
func iterDelete(w io.Writer, names map[string]string) {
|
||||
fmt.Fprintln(w, "func (all *"+names["Bases"]+") DeleteBy"+names["append"]+"(s string) bool {")
|
||||
if sortmap["lock"] == "all" {
|
||||
fmt.Fprintln(w, " "+names["lock"]+".Lock.RLock()")
|
||||
fmt.Fprintln(w, " defer "+names["lock"]+".Lock.RUnlock()")
|
||||
} else {
|
||||
fmt.Fprintln(w, " "+names["lock"]+".RLock()")
|
||||
fmt.Fprintln(w, " defer "+names["lock"]+".RUnlock()")
|
||||
func (pf *File) iterDelete(w io.Writer) {
|
||||
var MSG string = pf.Bases.Name
|
||||
var LOCK string = pf.Bases.Lockname
|
||||
|
||||
for _, KEY := range pf.Base.Sort {
|
||||
fmt.Fprintln(w, "func (all *"+MSG+") DeleteBy"+KEY+"(s string) bool {")
|
||||
fmt.Fprintln(w, " "+LOCK+".RLock()")
|
||||
fmt.Fprintln(w, " defer "+LOCK+".RUnlock()")
|
||||
fmt.Fprintln(w, "")
|
||||
fmt.Fprintln(w, " for i, _ := range all."+MSG+" {")
|
||||
fmt.Fprintln(w, " if all."+MSG+"[i]."+KEY+" == s {")
|
||||
fmt.Fprintln(w, " all."+MSG+"[i] = all."+MSG+"[len(all."+MSG+")-1]")
|
||||
fmt.Fprintln(w, " all."+MSG+" = all."+MSG+"[:len(all."+MSG+")-1]")
|
||||
fmt.Fprintln(w, " return true")
|
||||
fmt.Fprintln(w, " }")
|
||||
fmt.Fprintln(w, " }")
|
||||
fmt.Fprintln(w, " return false")
|
||||
fmt.Fprintln(w, "}")
|
||||
fmt.Fprintln(w, "")
|
||||
}
|
||||
fmt.Fprintln(w, "")
|
||||
fmt.Fprintln(w, " for i, _ := range all."+names["Bases"]+" {")
|
||||
fmt.Fprintln(w, " if all."+names["Bases"]+"[i]."+names["append"]+" == s {")
|
||||
fmt.Fprintln(w, " all."+names["Bases"]+"[i] = all."+names["Bases"]+"[len(all."+names["Bases"]+")-1]")
|
||||
fmt.Fprintln(w, " all."+names["Bases"]+" = all."+names["Bases"]+"[:len(all."+names["Bases"]+")-1]")
|
||||
fmt.Fprintln(w, " return true")
|
||||
fmt.Fprintln(w, " }")
|
||||
fmt.Fprintln(w, " }")
|
||||
fmt.Fprintln(w, " return false")
|
||||
fmt.Fprintln(w, "}")
|
||||
fmt.Fprintln(w, "")
|
||||
}
|
||||
|
||||
// this tries to return the deleted one but is wrong/gives warning if mutex lock is in struct
|
||||
|
|
Loading…
Reference in New Issue