<commit_before>package models

import (
	"debug/dwarf"
	"io/ioutil"
	"os"
	"path"
	"path/filepath"
	"sort"
	"strings"
)

type SourceLine struct {
	dwarf.LineEntry
	Start  uint64
	End    uint64
	Source string
}

func (s *SourceLine) Contains(addr uint64) bool {
	return s.Start <= addr && s.End > addr
}

type DebugFile struct {
	Symbols   []Symbol
	DWARF     *dwarf.Data
	SourceMap []*SourceLine
	SymbolMap map[string]Symbol
}

type symByStart []Symbol
type srcByStart []*SourceLine

func (a symByStart) Len() int      { return len(a) }
func (a symByStart) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a symByStart) Less(i, j int) bool {
	return a[i].Start < a[j].Start || a[i].Start == a[j].Start && a[i].End < a[j].End
}
func (a srcByStart) Len() int      { return len(a) }
func (a srcByStart) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a srcByStart) Less(i, j int) bool {
	return a[i].Start < a[j].Start || a[i].Start == a[j].Start && a[i].End < a[j].End
}

// sorts symbols by starting addr for binary search during symbolication
// builds source and symbol maps
func (m *DebugFile) CacheSym() {
	m.SymbolMap = make(map[string]Symbol)
	for _, sym := range m.Symbols {
		m.SymbolMap[sym.Name] = sym
	}
	sort.Sort(symByStart(m.Symbols))
}

func (m *DebugFile) CacheSource(srcPaths []string) {
	m.SourceMap = m.buildSourceMap(srcPaths)
	sort.Sort(srcByStart(m.SourceMap))
}

func findFile(srcPaths []string, parent string, shortname string, fullname string) []string {
	// TODO: if path is absolute, try -prefix
	// TODO: relative path to the exectuable?
	basename := path.Base(shortname)
	parname := path.Join(parent, shortname)
	names := []string{shortname, fullname, basename, parname}
	candidates := names
	for _, src := range srcPaths {
		for _, end := range names {
			candidates = append(candidates, filepath.Join(src, end))
		}
	}
	for _, fname := range candidates {
		if _, err := os.Stat(fname); err == nil {
			if data, err := ioutil.ReadFile(fname); err == nil {
				return strings.Split(string(data), "\n")
			}
		}<commit_msg>fix spelling error<commit_after>package models

import (
	"debug/dwarf"
	"io/ioutil"
	"os"
	"path"
	"path/filepath"
	"sort"
	"strings"
)

type SourceLine struct {
	dwarf.LineEntry
	Start  uint64
	End    uint64
	Source string
}

func (s *SourceLine) Contains(addr uint64) bool {
	return s.Start <= addr && s.End > addr
}

type DebugFile struct {
	Symbols   []Symbol
	DWARF     *dwarf.Data
	SourceMap []*SourceLine
	SymbolMap map[string]Symbol
}

type symByStart []Symbol
type srcByStart []*SourceLine

func (a symByStart) Len() int      { return len(a) }
func (a symByStart) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a symByStart) Less(i, j int) bool {
	return a[i].Start < a[j].Start || a[i].Start == a[j].Start && a[i].End < a[j].End
}
func (a srcByStart) Len() int      { return len(a) }
func (a srcByStart) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a srcByStart) Less(i, j int) bool {
	return a[i].Start < a[j].Start || a[i].Start == a[j].Start && a[i].End < a[j].End
}

// sorts symbols by starting addr for binary search during symbolication
// builds source and symbol maps
func (m *DebugFile) CacheSym() {
	m.SymbolMap = make(map[string]Symbol)
	for _, sym := range m.Symbols {
		m.SymbolMap[sym.Name] = sym
	}
	sort.Sort(symByStart(m.Symbols))
}

func (m *DebugFile) CacheSource(srcPaths []string) {
	m.SourceMap = m.buildSourceMap(srcPaths)
	sort.Sort(srcByStart(m.SourceMap))
}

func findFile(srcPaths []string, parent string, shortname string, fullname string) []string {
	// TODO: if path is absolute, try -prefix
	// TODO: relative path to the executable?
	basename := path.Base(shortname)
	parname := path.Join(parent, shortname)
	names := []string{shortname, fullname, basename, parname}
	candidates := names
	for _, src := range srcPaths {
		for _, end := range names {
			candidates = append(candidates, filepath.Join(src, end))
		}
	}
	for _, fname := range candidates {
		if _, err := os.Stat(fname); err == nil {
			if data, err := ioutil.ReadFile(fname); err == nil {
				return strings.Split(string(data), "\n")
			}
		}
{'fraction_non_alphanumeric': 0.15631848064280496, 'fraction_numerical': 0.0029218407596785976, 'mean_word_length': 3.919760479041916, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '1743739', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1537, 'n_words': 424}