1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

deadcode: groupbyRSet

This commit is contained in:
Tom Limoncelli
2024-03-03 10:37:37 -05:00
parent ed999b99bd
commit 34d6e079b2
3 changed files with 71 additions and 82 deletions

View File

@ -1,45 +1,40 @@
package diff2
import (
"github.com/StackExchange/dnscontrol/v4/models"
"github.com/StackExchange/dnscontrol/v4/pkg/prettyzone"
)
// type recset struct {
// Key models.RecordKey
// Recs []*models.RecordConfig
// }
type recset struct {
Key models.RecordKey
Recs []*models.RecordConfig
}
// func groupbyRSet(recs models.Records, origin string) []recset {
func groupbyRSet(recs models.Records, origin string) []recset {
// if len(recs) == 0 {
// return nil
// }
if len(recs) == 0 {
return nil
}
// // Sort the NameFQDN to a consistent order. The actual sort methodology
// // doesn't matter as long as equal values are adjacent.
// // Use the PrettySort ordering so that the records are extra pretty.
// pretty := prettyzone.PrettySort(recs, origin, 0, nil)
// recs = pretty.Records
// Sort the NameFQDN to a consistent order. The actual sort methodology
// doesn't matter as long as equal values are adjacent.
// Use the PrettySort ordering so that the records are extra pretty.
pretty := prettyzone.PrettySort(recs, origin, 0, nil)
recs = pretty.Records
// var result []recset
// var acc []*models.RecordConfig
var result []recset
var acc []*models.RecordConfig
// // Do the first element
// prevkey := recs[0].Key()
// acc = append(acc, recs[0])
// Do the first element
prevkey := recs[0].Key()
acc = append(acc, recs[0])
// for i := 1; i < len(recs); i++ {
// curkey := recs[i].Key()
// if prevkey == curkey { // A run of equal keys.
// acc = append(acc, recs[i])
// } else { // New key. Append old data to result and start new acc.
// result = append(result, recset{Key: prevkey, Recs: acc})
// acc = []*models.RecordConfig{recs[i]}
// }
// prevkey = curkey
// }
// result = append(result, recset{Key: prevkey, Recs: acc}) // The remainder
for i := 1; i < len(recs); i++ {
curkey := recs[i].Key()
if prevkey == curkey { // A run of equal keys.
acc = append(acc, recs[i])
} else { // New key. Append old data to result and start new acc.
result = append(result, recset{Key: prevkey, Recs: acc})
acc = []*models.RecordConfig{recs[i]}
}
prevkey = curkey
}
result = append(result, recset{Key: prevkey, Recs: acc}) // The remainder
return result
}
// return result
// }