<commit_before>package aggro

import "sort"

// Sortable provides an interface that various sorters can implement to compare
// two result buckets. This enables access to both the value and any metrics
// that the query may have contained.
type Sortable interface {
	Less(a, b *ResultBucket) bool
}

// sortableForOptions returns the appropriate sorter for the supplied sort
// options. If the options type provided is invalid, it is ignored an no sorter
// is returned. A nil response here will end up with results being in a
// non-deterministic order due to randomisation when ranging over maps.
func sortableForOptions(options *SortOptions) Sortable {
	if options == nil {
		return nil
	}
	switch options.Type {
	case "alphabetical":
		s := AlphabeticalSortable(!options.Desc)
		return &s
	}
	return nil
}

// AlphabeticalSortable is a simple  sorter that sorts alphabetically in the
// direction of the boolean, true meaning ascending and false being descending.
type AlphabeticalSortable bool

// Less implements Sortable by comparing the values field of each result.
func (sortable *AlphabeticalSortable) Less(a, b *ResultBucket) bool {
	return a.Value < b.Value == bool(*sortable)
}

// bucketSorter is an implementation of the sort.Sort interface that is capable
// or sorting the supplied slice of results with the supplied Sortable.
type bucketSorter struct {
	results  []*ResultBucket
	sortable Sortable
}

// Len implements the sort.Sort interface Len method.
func (sorter *bucketSorter) Len() int {
	return len(sorter.results)
}

// Swap implements the sort.Sort interface Swap method.
func (sorter *bucketSorter) Swap(i, j int) {
	sorter.results[i], sorter.results[j] = sorter.results[j], sorter.results[i]
}

// Less implement the sort.Sort less method by calling the Sortable that the
// sorter has been supplied, with the two appropriate results.
func (sorter *bucketSorter) Less(i, j int) bool {
	return sorter.sortable.Less(sorter.results[i], sorter.results[j])<commit_msg>Fix spelling<commit_after>package aggro

import "sort"

// Sortable provides an interface that various sorters can implement to compare
// two result buckets. This enables access to both the value and any metrics
// that the query may have contained.
type Sortable interface {
	Less(a, b *ResultBucket) bool
}

// sortableForOptions returns the sortable implementation for the supplied sort
// options. If the options type provided is invalid, it is ignored and no sorter
// is returned. A nil response here will end up with results being in a
// non-deterministic order due to randomisation when ranging over maps.
func sortableForOptions(options *SortOptions) Sortable {
	if options == nil {
		return nil
	}
	switch options.Type {
	case "alphabetical":
		s := AlphabeticalSortable(!options.Desc)
		return &s
	}
	return nil
}

// AlphabeticalSortable is a simple sorter that sorts alphabetically in the
// direction of the boolean, true meaning ascending and false being descending.
type AlphabeticalSortable bool

// Less implements Sortable by comparing the value field of each result.
func (sortable *AlphabeticalSortable) Less(a, b *ResultBucket) bool {
	return a.Value < b.Value == bool(*sortable)
}

// bucketSorter is an implementation of the sort.Sort interface that is capable
// of sorting the supplied slice of results with the supplied Sortable.
type bucketSorter struct {
	results  []*ResultBucket
	sortable Sortable
}

// Len implements the sort.Sort interface Len method.
func (sorter *bucketSorter) Len() int {
	return len(sorter.results)
}

// Swap implements the sort.Sort interface Swap method.
func (sorter *bucketSorter) Swap(i, j int) {
	sorter.results[i], sorter.results[j] = sorter.results[j], sorter.results[i]
}

// Less implements the sort.Sort Less method by calling the Sortable that the
// sorter has been supplied, with the two appropriate results.
func (sorter *bucketSorter) Less(i, j int) bool {
	return sorter.sortable.Less(sorter.results[i], sorter.results[j])
{'fraction_non_alphanumeric': 0.0786967418546366, 'fraction_numerical': 0.0, 'mean_word_length': 4.371467025572005, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, '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': '2151967', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1116, 'n_words': 486}