7 type ResultSet map[AID]Anime // Mapping of AIDs to Anime
10 // Returns a slice with the AIDs of all anime in the Results.
11 func (res Results) AIDList() (aid []AID) {
12 aid = make([]AID, 0, len(res))
13 for _, r := range res {
14 aid = append(aid, r.AID)
19 // Converts the SearchMatches (which usually contains various duplicates)
20 // into a ResultSet. Needs the same TitlesDatabase as was used to generate the
22 func (matches SearchMatches) ToResultSet(db *TitlesDatabase) (rs ResultSet) {
30 for _, m := range matches {
31 rs[m.AID] = *db.AnimeMap[m.AID]
36 func (rs ResultSet) unsortedResults() (res Results) {
37 res = make(Results, 0, len(rs))
38 for _, r := range rs {
44 // Returns true if the first parameter should sort before the second parameter
45 type ResultComparer func(*Anime, *Anime) bool
48 aidSort = func(a *Anime, b *Anime) bool {
51 titleSort = func(a *Anime, b *Anime) bool {
52 return sort.StringSlice{a.PrimaryTitle, b.PrimaryTitle}.Less(0, 1)
56 // Returns the results sorted by AID
57 func (rs ResultSet) ResultsByAID() (res Results) {
58 return rs.ResultsByFunc(aidSort)
61 // Returns the results in inverse AID sort
62 func (rs ResultSet) ReverseResultsByAID() (res Results) {
63 return rs.ReverseResultsByFunc(aidSort)
66 // Returns the results sorted by Primary Title
67 func (rs ResultSet) ResultsByPrimaryTitle() (res Results) {
68 return rs.ResultsByFunc(titleSort)
71 // Returns the results in inverse Primary Title sort
72 func (rs ResultSet) ReverseResultsByPrimaryTitle() (res Results) {
73 return rs.ReverseResultsByFunc(titleSort)
76 // Returns the results sorted according to the given ResultComparer
77 func (rs ResultSet) ResultsByFunc(f ResultComparer) (res Results) {
78 res = rs.unsortedResults()
83 // Returns the results sorted inversely according to the given ResultComparer
84 func (rs ResultSet) ReverseResultsByFunc(f ResultComparer) (res Results) {
85 res = rs.unsortedResults()