<commit_before>package main

import (
	"errors"
	"sort"
	"strings"
	"unicode/utf8"
)

func indexRuneStarting(str string, r rune, start int) int {
	idx := strings.IndexRune(str[start:], r)
	if idx == -1 {
		return -1
	}
	return idx + start
}

func allIndexRune(str string, r rune) []int {
	var allIndexRune []int
	for i, c := range str {
		if c == r {
			allIndexRune = append(allIndexRune, i)
		}
	}
	return allIndexRune
}

func findMatch(candidate string, query string) (Match, error) {
	var runePositions Match
	start := 0
	for _, r := range query {
		start = indexRuneStarting(candidate, r, start)
		if start == -1 {
			return nil, errors.New("No Match Found")
		}
		runePositions = append(runePositions, start)
		start += utf8.RuneLen(r)
	}
	return runePositions, nil
}

type Match []int

func (m Match) Length() int {
	return m[len(m)-1] - m[0] + 1
}

type matchSlice []Match

func (ms matchSlice) Len() int           { return len(ms) }
func (ms matchSlice) Swap(i, j int)      { ms[i], ms[j] = ms[j], ms[i] }
func (ms matchSlice) Less(i, j int) bool { return ms[i].Length() < ms[j].Length() }

func bestMatch(ms []Match) Match {
	sort.Sort(matchSlice(ms))
	return ms[0]
}

func Score(candidate, query string) float64 {
	if len(query) == 0 {
		return 1.0
	}
	if len(candidate) < len(query) {
		return 0.0
	}

	first, _ := utf8.DecodeRuneInString(query)
	firstQueryRunePositions := allIndexRune(candidate, first)

	var matches []Match
	for _, start := range firstQueryRunePositions {
		match, err := findMatch(candidate[start:], query)
		if err != nil {
			continue
		}
		matches = append(matches, match)
	}

	if len(matches) == 0 {
		return 0.0<commit_msg>Minor renaming of local function<commit_after>package main

import (
	"errors"
	"sort"
	"strings"
	"unicode/utf8"
)

func indexRuneStarting(str string, r rune, start int) int {
	idx := strings.IndexRune(str[start:], r)
	if idx == -1 {
		return -1
	}
	return idx + start
}

func indexesRune(str string, r rune) []int {
	var indexes []int
	for i, c := range str {
		if c == r {
			indexes = append(indexes, i)
		}
	}
	return indexes
}

func findMatch(candidate string, query string) (Match, error) {
	var runePositions Match
	start := 0
	for _, r := range query {
		start = indexRuneStarting(candidate, r, start)
		if start == -1 {
			return nil, errors.New("No Match Found")
		}
		runePositions = append(runePositions, start)
		start += utf8.RuneLen(r)
	}
	return runePositions, nil
}

type Match []int

func (m Match) Length() int {
	return m[len(m)-1] - m[0] + 1
}

type matchSlice []Match

func (ms matchSlice) Len() int           { return len(ms) }
func (ms matchSlice) Swap(i, j int)      { ms[i], ms[j] = ms[j], ms[i] }
func (ms matchSlice) Less(i, j int) bool { return ms[i].Length() < ms[j].Length() }

func bestMatch(ms []Match) Match {
	sort.Sort(matchSlice(ms))
	return ms[0]
}

func Score(candidate, query string) float64 {
	if len(query) == 0 {
		return 1.0
	}
	if len(candidate) < len(query) {
		return 0.0
	}

	first, _ := utf8.DecodeRuneInString(query)
	firstQueryRunePositions := indexesRune(candidate, first)

	var matches []Match
	for _, start := range firstQueryRunePositions {
		match, err := findMatch(candidate[start:], query)
		if err != nil {
			continue
		}
		matches = append(matches, match)
	}

	if len(matches) == 0 {
		return 0.0
{'fraction_non_alphanumeric': 0.14160891834890027, 'fraction_numerical': 0.012654413980114493, 'mean_word_length': 3.656381486676017, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5571086', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1256, 'n_words': 355}