<commit_before>/*
Package Goria provides the functionality of an LRU Cache with an eye to JSR 107
*/
package goria

import (
	"container/list"
	"errors"
	"fmt"
)

type EvictionCallback func(key interface{}, value interface{})

type GoriaLRU struct {
	Name         string
	Size         int
	items        map[interface{}]*list.Element
	evictionList *list.List
	onEvict      EvictionCallback
	statsEnabled bool
	stats        CacheStats
}

type CacheStats struct {
	Items     int64
	Gets      int64
	Hits      int64
	Evictions int64
	Miss      int64
}

type entry struct {
	key   interface{}
	value interface{}
}

func newGoriaLRU(name string, size int, evictionC EvictionCallback, statsEnabled bool) (*GoriaLRU, error) {
	if size <= 0 {
		return nil, errors.New("The Goria Cache need a positive value as size")
	}
	fmt.Println(statsEnabled)
	c := &GoriaLRU{
		Name:         name,
		Size:         size,
		evictionList: list.New(),
		items:        make(map[interface{}]*list.Element),
		onEvict:      evictionC,
		statsEnabled: statsEnabled,
		stats: CacheStats{
			Items:     0,
			Evictions: 0,
			Gets:      0,
			Hits:      0,
			Miss:      0,
		},
	}
	return c, nil
}

func (c *GoriaLRU) Put(key, value interface{}) {
	if item, ok := c.items[key]; ok {
		c.evictionList.MoveToFront(item)
		item.Value.(*entry).value = value
		return
	}

	item := &entry{key, value}
	element := c.evictionList.PushFront(item)
	c.items[key] = element

	if c.evictionList.Len() > c.Size {
		c.removeFromTail()<commit_msg>Remove unuseful printf<commit_after>/*
Package Goria provides the functionality of an LRU Cache with an eye to JSR 107
*/
package goria

import (
	"container/list"
	"errors"
)

type EvictionCallback func(key interface{}, value interface{})

type GoriaLRU struct {
	Name         string
	Size         int
	items        map[interface{}]*list.Element
	evictionList *list.List
	onEvict      EvictionCallback
	statsEnabled bool
	stats        CacheStats
}

type CacheStats struct {
	Items     int64
	Gets      int64
	Hits      int64
	Evictions int64
	Miss      int64
}

type entry struct {
	key   interface{}
	value interface{}
}

func newGoriaLRU(name string, size int, evictionC EvictionCallback, statsEnabled bool) (*GoriaLRU, error) {
	if size <= 0 {
		return nil, errors.New("The Goria Cache need a positive value as size")
	}
	c := &GoriaLRU{
		Name:         name,
		Size:         size,
		evictionList: list.New(),
		items:        make(map[interface{}]*list.Element),
		onEvict:      evictionC,
		statsEnabled: statsEnabled,
		stats: CacheStats{
			Items:     0,
			Evictions: 0,
			Gets:      0,
			Hits:      0,
			Miss:      0,
		},
	}
	return c, nil
}

func (c *GoriaLRU) Put(key, value interface{}) {
	if item, ok := c.items[key]; ok {
		c.evictionList.MoveToFront(item)
		item.Value.(*entry).value = value
		return
	}

	item := &entry{key, value}
	element := c.evictionList.PushFront(item)
	c.items[key] = element

	if c.evictionList.Len() > c.Size {
		c.removeFromTail()
{'fraction_non_alphanumeric': 0.10782667114544844, 'fraction_numerical': 0.012764528048370843, 'mean_word_length': 2.970666666666667, 'pattern_counts': {'":': 0, '<': 5, '<?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': '592878', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1036, 'n_words': 291}