summaryrefslogtreecommitdiff
path: root/repo.SortByAge.go
blob: 458a9a0c635e352b56de8a59e53c61fce5b4a77a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package gitpb

import "sort"

func (x *Repos) SortByAge() *RepoScanner {
	// copy the pointers as fast as possible.
	things := x.selectAllRepos()

	// todo: try slices.SortFunc() instead to see what happens
	sort.Sort(sortReposAge(things))
	//    slices.SortFunc(things, func(a, b *Repos) bool {
	//        return a.Namespace < b.Namespace // Sort by ??. let the compiler work it out??
	//    })
	return newRepoScanner(things)
}

type sortReposAge []*Repo

func (a sortReposAge) Len() int { return len(a) }

// sorts in ? order
func (r sortReposAge) Less(i, j int) bool {
	if r[i].NewestAge() > r[j].NewestAge() {
		return true
	}
	return false
}
func (a sortReposAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] }