<commit_before>package disgo

type entry struct {
	locations []string
}

type db struct {
	entries map[PHash]*entry
}

var DB db

func init() {
	DB.entries = make(map[PHash]*entry)
}

func AddFile(filename string) error {
	phash, err := HashFile(filename)
	if err != nil {
		return err
	}
	return AddLocation(filename, phash)
}

func AddLocation(location string, phash PHash) error {
	e, found := DB.entries[phash]
	if !found {
		e = new(entry)
		DB.entries[phash] = e
	}
	e.locations = append(e.locations, location)
	return nil
}

func Find(phash PHash) ([]string, error) {
	if entry, found := DB.entries[phash]; found {
		return entry.locations, nil
	}
	return []string{}, nil
}

func SearchByFile(filename string, maxDistance uint) ([]string, error) {
	h, e := HashFile(filename)
	if e != nil {
		return nil, e
	}

	return SearchByHash(h, maxDistance)
}

func SearchByHash(phash PHash, maxDistance uint) ([]string, error) {
	var results []string

	// look for existing entry within maxDistance of the hash
	for p, e := range DB.entries {
		if p.Distance(phash) <= maxDistance {
			results = append(results, e.locations...)
		}
	}

	return results, nil
}
<commit_msg>Added a standard not found error<commit_after>package disgo

import (
	"errors"
)

type entry struct {
	locations []string
}

type db struct {
	entries map[PHash]*entry
}

var (
	ErrNotFound = errors.New("Image not found")
)

var DB db

func init() {
	DB.entries = make(map[PHash]*entry)
}

func AddFile(filename string) error {
	phash, err := HashFile(filename)
	if err != nil {
		return err
	}
	return AddLocation(filename, phash)
}

func AddLocation(location string, phash PHash) error {
	e, found := DB.entries[phash]
	if !found {
		e = new(entry)
		DB.entries[phash] = e
	}
	e.locations = append(e.locations, location)
	return nil
}

func Find(phash PHash) ([]string, error) {
	if entry, found := DB.entries[phash]; found {
		return entry.locations, nil
	}
	return []string{}, ErrNotFound
}

func SearchByFile(filename string, maxDistance uint) ([]string, error) {
	h, e := HashFile(filename)
	if e != nil {
		return nil, e
	}

	return SearchByHash(h, maxDistance)
}

func SearchByHash(phash PHash, maxDistance uint) ([]string, error) {
	var results []string

	// look for existing entry within maxDistance of the hash
	for p, e := range DB.entries {
		if p.Distance(phash) <= maxDistance {
			results = append(results, e.locations...)
		}
	}

	return results, nil
}

{'fraction_non_alphanumeric': 0.1278164686603851, 'fraction_numerical': 0.0, 'mean_word_length': 4.014373716632443, 'pattern_counts': {'":': 0, '<': 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': '7406184', 'n_tokens_mistral': 883, 'n_tokens_neox': 848, 'n_words': 256}