<commit_before>package lru

import (
	"sync"

	"github.com/hashicorp/golang-lru/internal"
)

// ARCCache is a thread-safe fixed size Adaptive Replacement Cache (ARC).
// ARC is an enhancement over the standard LRU cache in that tracks both
// frequency and recency of use. This avoids a burst in access to new
// entries from evicting the frequently used older entries. It adds some
// additional tracking overhead to a standard LRU cache.
type ARCCache struct {
	size int // Size is the total capacity of the cache
	p    int // P is the dynamic preference towards T1 or T2

	t1 *internal.LRU // T1 is the LRU for recently accessed items
	b1 *internal.LRU // B1 is the LRU for evictions from t1

	t2 *internal.LRU // T2 is the LRU for frequently accessed items
	b2 *internal.LRU // B2 is the LRU for evictions from t2

	lock sync.RWMutex
}

// NewARC creates an ARC of the given size
func NewARC(size int) (*ARCCache, error) {
	// Create the sub LRUs
	b1, err := internal.NewLRU(size, nil)
	if err != nil {
		return nil, err
	}
	b2, err := internal.NewLRU(size, nil)
	if err != nil {
		return nil, err
	}
	t1, err := internal.NewLRU(size, nil)
	if err != nil {<commit_msg>Adding the cost of the ARC to comments<commit_after>package lru

import (
	"sync"

	"github.com/hashicorp/golang-lru/internal"
)

// ARCCache is a thread-safe fixed size Adaptive Replacement Cache (ARC).
// ARC is an enhancement over the standard LRU cache in that tracks both
// frequency and recency of use. This avoids a burst in access to new
// entries from evicting the frequently used older entries. It adds some
// additional tracking overhead to a standard LRU cache, computationally
// it is roughly 2x the cost, and the extra memory overhead is linear
// with the size of the cache.
type ARCCache struct {
	size int // Size is the total capacity of the cache
	p    int // P is the dynamic preference towards T1 or T2

	t1 *internal.LRU // T1 is the LRU for recently accessed items
	b1 *internal.LRU // B1 is the LRU for evictions from t1

	t2 *internal.LRU // T2 is the LRU for frequently accessed items
	b2 *internal.LRU // B2 is the LRU for evictions from t2

	lock sync.RWMutex
}

// NewARC creates an ARC of the given size
func NewARC(size int) (*ARCCache, error) {
	// Create the sub LRUs
	b1, err := internal.NewLRU(size, nil)
	if err != nil {
		return nil, err
	}
	b2, err := internal.NewLRU(size, nil)
	if err != nil {
		return nil, err
	}
	t1, err := internal.NewLRU(size, nil)
	if err != nil {
{'fraction_non_alphanumeric': 0.08205953338696702, 'fraction_numerical': 0.01246983105390185, 'mean_word_length': 3.2731958762886597, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6895807', 'n_tokens_mistral': 853, 'n_tokens_neox': 799, 'n_words': 367}