<commit_before>package main

import (
	"errors"
	"strconv"
	"strings"
)

type SemverCandidate struct {
	GitRefHash              string
	GitRefName              string
	MajorVersion            int
	MinorVersion            int
	PatchVersion            int
	PrereleaseLabel         string
	PrereleaseVersion       int
	PrereleaseVersionExists bool
}

type SemverCandidateList []SemverCandidate

func NewSemverCandidate(
	gitRefHash string,
	gitRefName string,
	majorVersion string,
	minorVersion string,
	patchVersion string,
	prereleaseLabel string,
	prereleaseVersion string,
) (SemverCandidate, error) {
	var (
		err                     error
		majorVersionNumber      int
		minorVersionNumber      int
		patchVersionNumber      int
		prereleaseVersionNumber int
	)

	if len(gitRefHash) == 0 {
		return SemverCandidate{}, errors.New("Git ref hash is required")
	} else if len(gitRefName) == 0 {
		return SemverCandidate{}, errors.New("Git ref name is required")
	}

	if len(majorVersion) > 0 {
		majorVersionNumber, err = strconv.Atoi(majorVersion)
		if err != nil {
			return SemverCandidate{}, err
		}
	} else {
		return SemverCandidate{}, errors.New("Major version is required")
	}

	if len(minorVersion) > 0 {
		minorVersionNumber, err = strconv.Atoi(minorVersion)
		if err != nil {
			return SemverCandidate{}, err
		}
	} else {
		minorVersionNumber = 0
	}

	if len(patchVersion) > 0 {
		patchVersionNumber, err = strconv.Atoi(patchVersion)
		if err != nil {
			return SemverCandidate{}, err
		}
	} else {
		patchVersionNumber = 0
	}

	if len(prereleaseVersion) > 0 {
		prereleaseVersionNumber, err = strconv.Atoi(prereleaseVersion)
		if err != nil {
			return SemverCandidate{}, err
		}
	} else {
		prereleaseVersionNumber = 0
	}

	return SemverCandidate{
		GitRefHash:              gitRefHash,
		GitRefName:              gitRefName,
		MajorVersion:            majorVersionNumber,
		MinorVersion:            minorVersionNumber,
		PatchVersion:            patchVersionNumber,
		PrereleaseLabel:         prereleaseLabel,
		PrereleaseVersion:       prereleaseVersionNumber,
		PrereleaseVersionExists: (len(prereleaseLabel) > 0),
	}, nil
}

func (this SemverCandidate) CompareTo(that SemverCandidate) int {
	if this.MajorVersion > that.MajorVersion {
		return 1
	} else if this.MajorVersion < that.MajorVersion {
		return -1
	} else if this.MinorVersion > that.MinorVersion {
		return 1
	} else if this.MinorVersion < that.MinorVersion {
		return -1
	} else if this.PatchVersion > that.PatchVersion {
		return 1
	} else if this.PatchVersion < that.PatchVersion {
		return -1
	} else if len(this.PrereleaseLabel) > 0 && len(that.PrereleaseLabel) == 0 {
		// Prerelease immediately means that the version is lesser
		return -1
	} else if len(this.PrereleaseLabel) == 0 && len(that.PrereleaseLabel) > 0 {
		// Prerelease immediately means that the version is lesser
		return 1
	} else if this.PrereleaseLabel != that.PrereleaseLabel {
		// Prerelease labels don't match, so return a comparison
		return strings.Compare(this.PrereleaseLabel, that.PrereleaseLabel)
	} else if this.PrereleaseVersion > that.PrereleaseVersion {
		// Prerelease labels are identical, so continue comparison to versions
		return 1
	} else if this.PrereleaseVersion < that.PrereleaseVersion {
		return -1
	}
	// If we got this far, then the versions are clearly identical
	// (which is super weird)
	return 0
}<commit_msg>made candidate lists sortable<commit_after>package main

import (
	"errors"
	"sort"
	"strconv"
	"strings"
)

type SemverCandidate struct {
	GitRefHash              string
	GitRefName              string
	MajorVersion            int
	MinorVersion            int
	PatchVersion            int
	PrereleaseLabel         string
	PrereleaseVersion       int
	PrereleaseVersionExists bool
}

func NewSemverCandidate(
	gitRefHash string,
	gitRefName string,
	majorVersion string,
	minorVersion string,
	patchVersion string,
	prereleaseLabel string,
	prereleaseVersion string,
) (SemverCandidate, error) {
	var (
		err                     error
		majorVersionNumber      int
		minorVersionNumber      int
		patchVersionNumber      int
		prereleaseVersionNumber int
	)

	if len(gitRefHash) == 0 {
		return SemverCandidate{}, errors.New("Git ref hash is required")
	} else if len(gitRefName) == 0 {
		return SemverCandidate{}, errors.New("Git ref name is required")
	}

	if len(majorVersion) > 0 {
		majorVersionNumber, err = strconv.Atoi(majorVersion)
		if err != nil {
			return SemverCandidate{}, err
		}
	} else {
		return SemverCandidate{}, errors.New("Major version is required")
	}

	if len(minorVersion) > 0 {
		minorVersionNumber, err = strconv.Atoi(minorVersion)
		if err != nil {
			return SemverCandidate{}, err
		}
	} else {
		minorVersionNumber = 0
	}

	if len(patchVersion) > 0 {
		patchVersionNumber, err = strconv.Atoi(patchVersion)
		if err != nil {
			return SemverCandidate{}, err
		}
	} else {
		patchVersionNumber = 0
	}

	if len(prereleaseVersion) > 0 {
		prereleaseVersionNumber, err = strconv.Atoi(prereleaseVersion)
		if err != nil {
			return SemverCandidate{}, err
		}
	} else {
		prereleaseVersionNumber = 0
	}

	return SemverCandidate{
		GitRefHash:              gitRefHash,
		GitRefName:              gitRefName,
		MajorVersion:            majorVersionNumber,
		MinorVersion:            minorVersionNumber,
		PatchVersion:            patchVersionNumber,
		PrereleaseLabel:         prereleaseLabel,
		PrereleaseVersion:       prereleaseVersionNumber,
		PrereleaseVersionExists: (len(prereleaseLabel) > 0),
	}, nil
}

func (this SemverCandidate) CompareTo(that SemverCandidate) int {
	if this.MajorVersion > that.MajorVersion {
		return 1
	} else if this.MajorVersion < that.MajorVersion {
		return -1
	} else if this.MinorVersion > that.MinorVersion {
		return 1
	} else if this.MinorVersion < that.MinorVersion {
		return -1
	} else if this.PatchVersion > that.PatchVersion {
		return 1
	} else if this.PatchVersion < that.PatchVersion {
		return -1
	} else if len(this.PrereleaseLabel) > 0 && len(that.PrereleaseLabel) == 0 {
		// Prerelease immediately means that the version is lesser
		return -1
	} else if len(this.PrereleaseLabel) == 0 && len(that.PrereleaseLabel) > 0 {
		// Prerelease immediately means that the version is lesser
		return 1
	} else if this.PrereleaseLabel != that.PrereleaseLabel {
		// Prerelease labels don't match, so return a comparison
		return strings.Compare(this.PrereleaseLabel, that.PrereleaseLabel)
	} else if this.PrereleaseVersion > that.PrereleaseVersion {
		// Prerelease labels are identical, so continue comparison to versions
		return 1
	} else if this.PrereleaseVersion < that.PrereleaseVersion {
		return -1
	}
	// If we got this far, then the versions are clearly identical
	// (which is super weird)
	return 0
}

type SemverCandidateList []SemverCandidate

func (list SemverCandidateList) Len() int {
	return len(list)
}

func (list SemverCandidateList) Swap(i, j int) {
	list[i], list[j] = list[j], list[i]
}

func (list SemverCandidateList) Less(i, j int) bool {
	return list[i].CompareTo(list[j]) < 0
}

func (list SemverCandidateList) Lowest() *SemverCandidate {
	listLength := len(list)
	if listLength < 1 {
		return nil
	}

	sort.Sort(list)
	return &list[0]
}

func (list SemverCandidateList) Highest() *SemverCandidate {
	listLength := len(list)
	if listLength < 1 {
		return nil
	}

	sort.Sort(list)
	return &list[listLength-1]
}
{'fraction_non_alphanumeric': 0.08621621621621621, 'fraction_numerical': 0.007432432432432433, 'mean_word_length': 3.402736466389054, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 25, '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': '6856985', 'n_tokens_mistral': 2557, 'n_tokens_neox': 2280, 'n_words': 637}