Files
HackBrowserData/internal/export/order.go
T
Roger 0ed920f846 docs: trim code comments to the why (#676)
Comments that restated names or narrated the code are gone, and multi-line ones are cut to a line of why.
Only comments change: each edited Go file has the same token stream as before. winapi and abe come later.
2026-11-02 00:03:03 +08:00

45 lines
932 B
Go

package export
import (
"sort"
"time"
"github.com/moond4rk/hackbrowserdata/internal/record"
)
// Stable, so ties and keyless records keep source order: Safari's bookmarks and downloads have no timestamp.
func sortRecords(records []record.Record) {
sort.SliceStable(records, func(i, j int) bool {
return keyOf(records[i]).before(keyOf(records[j]))
})
}
type sortKey struct {
visits int
at time.Time
}
func keyOf(r record.Record) sortKey {
switch r := r.(type) {
case *record.Login:
return sortKey{at: r.CreatedAt}
case *record.Cookie:
return sortKey{at: r.CreatedAt}
case *record.Bookmark:
return sortKey{at: r.CreatedAt}
case *record.Download:
return sortKey{at: r.StartTime}
case *record.History:
return sortKey{visits: r.VisitCount}
default:
return sortKey{}
}
}
func (k sortKey) before(o sortKey) bool {
if k.visits != o.visits {
return k.visits > o.visits
}
return k.at.After(o.at)
}