Skip to content

Instantly share code, notes, and snippets.

@richardlehane
Last active June 8, 2020 07:50
Show Gist options
  • Save richardlehane/8a8a1fec99f4d2879ed12373901b507f to your computer and use it in GitHub Desktop.
Save richardlehane/8a8a1fec99f4d2879ed12373901b507f to your computer and use it in GitHub Desktop.
sorted.go
import "sort"
// sorted sorts signatures by their index so that runs of signatures e.g. fmt/1, fmt/1, fmt/2, fmt/1
// can be propertly placed.
type sorted struct{ Parseable }
func (s sorted) Signatures() ([]frames.Signature, []string, error) {
sigs, ids, err := m.Parseable.Signatures()
if err != nil {
return sigs, ids, err
}
retSigs := make([]frames.Signature, len(sigs))
retIds := make([]string, len(ids))
copy(retIds, ids)
sort.Strings(retIds)
var last string
var nth int
for i, this := range retIds {
if this == last {
nth++
} else {
nth = 0
last = this
}
var cursor int
for j, str = range ids {
if this != str {
continue
}
if cursor == nth {
retSigs[i] = sigs[j]
break
}
cursor++
}
}
return retSigs, retIds, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment