<commit_before>package main

import (
	"fmt"
	"os"
	"sort"
	"text/tabwriter"
	"time"
)

// Track represent information about music track.
type Track struct {
	Title  string
	Artist string
	Album  string
	Year   int
	Length time.Duration
}

func printTracks(tracks []*Track) {
	const format = "%v\t%v\t%v\t%v\t%v\t\n"
	tw := new(tabwriter.Writer).Init(os.Stdout, 0, 8, 2, ' ', 0)
	fmt.Fprintf(tw, format, "Title", "Artist", "Album", "Year", "Length")
	fmt.Fprintf(tw, format, "-----", "------", "-----", "----", "------")
	for _, t := range tracks {
		fmt.Fprintf(tw, format, t.Title, t.Artist, t.Album, t.Year, t.Length)
	}
	tw.Flush()
}

type lessFunc func(i, j int) bool
type memoSort []lessFunc

func (m *memoSort) By(f lessFunc) lessFunc {
	*m = append(*m, f)
	return m.less
}

func (m *memoSort) less(i, j int) bool {
	for k := 0; k < len(*m)-1; k++ {
		f := (*m)[k]
		switch {
		case f(i, j):
			return true
		case f(j, i):
			return false
		}
	}
	return false
}

var tracks = []*Track{
	{"Go", "Delilah", "From the Roots Up", 2012, length("3m38s")},
	{"Go", "Moby", "Moby", 1992, length("3m37s")},
	{"Go Ahead", "Alicia Keys", "As I Am", 2007, length("4m36s")},
	{"Ready 2 Go", "<NAME>", "Smash", 2011, length("4m24s")},
}

func length(s string) time.Duration {
	d, err := time.ParseDuration(s)
	if err != nil {
		panic(s)
	}
	return d
}

func main() {
	m := new(memoSort)
	sort.Slice(tracks, m.By(func(i, j int) bool {
		return tracks[i].Title < tracks[j].Title
	}))
	sort.Slice(tracks, m.By(func(i, j int) bool {
		return tracks[i].Year < tracks[j].Year
	}))
	sort.Slice(tracks, m.By(func(i, j int) bool {
		return tracks[i].Length < tracks[j].Length
	}))

	printTracks(tracks)
}<commit_msg>[7.8] Moved momosort to gomill lib.<commit_after>package main

import (
	"fmt"
	"os"
	"sort"
	"text/tabwriter"
	"time"

	"github.com/krasoffski/gomill/memosort"
)

// Track represent information about music track.
type Track struct {
	Title  string
	Artist string
	Album  string
	Year   int
	Length time.Duration
}

func printTracks(tracks []*Track) {
	const format = "%v\t%v\t%v\t%v\t%v\t\n"
	tw := new(tabwriter.Writer).Init(os.Stdout, 0, 8, 2, ' ', 0)
	fmt.Fprintf(tw, format, "Title", "Artist", "Album", "Year", "Length")
	fmt.Fprintf(tw, format, "-----", "------", "-----", "----", "------")
	for _, t := range tracks {
		fmt.Fprintf(tw, format, t.Title, t.Artist, t.Album, t.Year, t.Length)
	}
	tw.Flush()
}

var tracks = []*Track{
	{"Go", "Delilah", "From the Roots Up", 2012, length("3m38s")},
	{"Go", "Moby", "Moby", 1992, length("3m37s")},
	{"Go Ahead", "<NAME>", "As I Am", 2007, length("4m36s")},
	{"Ready 2 Go", "<NAME>", "Smash", 2011, length("4m24s")},
}

func length(s string) time.Duration {
	d, err := time.ParseDuration(s)
	if err != nil {
		panic(s)
	}
	return d
}

func main() {
	m := memosort.New()
	sort.Slice(tracks, m.By(func(i, j int) bool {
		return tracks[i].Title < tracks[j].Title
	}))
	sort.Slice(tracks, m.By(func(i, j int) bool {
		return tracks[i].Year < tracks[j].Year
	}))
	sort.Slice(tracks, m.By(func(i, j int) bool {
		return tracks[i].Length < tracks[j].Length
	}))

	printTracks(tracks)
}
{'fraction_non_alphanumeric': 0.2173218280600831, 'fraction_numerical': 0.02237136465324385, 'mean_word_length': 3.5961820851688695, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1435698', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1298, 'n_words': 321}