<commit_before>// Copyright 2013 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package repository

import (
	"strings"
)

type ItemMap map[string]*Item

func NewItemMap() ItemMap {
	return make(ItemMap)
}

func (itemmap ItemMap) Register(item *Item) {

	key := itemmap.getMapKey(item)
	itemmap[key] = item

}

func (itemmap ItemMap) Remove(item *Item) {

	key := itemmap.getMapKey(item)
	delete(itemmap, key)

}

func (itemmap ItemMap) LookupByAlias(alias string) *Item {
	key := itemmap.normalizeKey(alias)
	if item, exists := itemmap[key]; exists {
		return item
	}

	return nil
}

func (itemmap ItemMap) getMapKey(item *Item) string {
	return itemmap.normalizeKey(item.MetaData.Alias)
}

func (itemmap ItemMap) normalizeKey(key string) string {
	return strings.ToLower(key)
}<commit_msg>Refactored the ItemMap type to be able to hold one or more links for one alias<commit_after>// Copyright 2013 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package repository

import (
	"fmt"
	"strings"
)

type ItemMap map[string]ItemList

func NewItemMap() ItemMap {
	return make(ItemMap)
}

func (itemmap ItemMap) Register(item *Item) {

	key := itemmap.getMapKey(item)
	if itemlist, exists := itemmap[key]; exists {

		// add the item to the item list
		itemmap[key] = itemlist.Add(item)

	} else {

		// create a new item list
		itemmap[key] = NewItemList(item)
	}

}

func (itemmap ItemMap) Remove(item *Item) {

	key := itemmap.getMapKey(item)
	if itemlist, exists := itemmap[key]; exists {

		newItemList := itemlist.Remove(item)
		if len(newItemList) > 0 {
			itemmap[key] = newItemList
		} else {
			delete(itemmap, key)
		}

	}

}

func (itemmap ItemMap) LookupByAlias(alias string) *Item {
	key := itemmap.normalizeKey(alias)
	if itemList, exists := itemmap[key]; exists {
		if len(itemList) == 0 {
			return nil
		}

		// debug
		if len(itemList) > 1 {
			fmt.Printf("There is more than one document for the alias %q.\n", alias)
		}

		return itemList[0]
	}

	return nil
}

func (itemmap ItemMap) getMapKey(item *Item) string {
	return itemmap.normalizeKey(item.MetaData.Alias)
}

func (itemmap ItemMap) normalizeKey(key string) string {
	return strings.ToLower(key)
}
{'fraction_non_alphanumeric': 0.11423699914748509, 'fraction_numerical': 0.005115089514066497, 'mean_word_length': 4.025695931477516, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4401312', 'n_tokens_mistral': 854, 'n_tokens_neox': 806, 'n_words': 247}