Last active
June 8, 2020 07:50
-
-
Save richardlehane/8a8a1fec99f4d2879ed12373901b507f to your computer and use it in GitHub Desktop.
sorted.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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