<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DotKafka.Prototype.Common.Cache {
    public class LRUCache<K, V> : ICache<K, V> {
        private readonly Dictionary<K, V> _cache;
        private readonly LinkedList<K> _lruList;
        private readonly int _capacity;

        public int Size => _cache.Count;

        public LRUCache(int maxSize) {
            _capacity = maxSize;
            _cache = new Dictionary<K, V>(_capacity);
            _lruList = new LinkedList<K>();
        }

        public V Get(K key) {
            V value;

            if (!_cache.TryGetValue(key, out value))
                return default(V);

            var node = _lruList.Find(key);

            _lruList.Remove(node);

            _lruList.AddFirst(node);

            return value;
        }

        public void Put(K key, V value) {
            LinkedListNode<K> node;

            if (_cache.ContainsKey(key)) {
                node = _lruList.Find(key);

                _lruList.Remove(node);

                _lruList.AddFirst(node);

                _cache[key] = value;
            }
            else {
                if (_cache.Count >= _capacity) {
                    node = _lruList.Last;

                    _cache.Remove(node.Value);

                    _lruList.RemoveLast();
                }

                _lruList.AddFirst(key);

                _cache.Add(key, value);
            }
        }

        public bool Remove(K key) {
            return _cache.Remove(key) && _lruList.Remove(key);
        }
    }
}<commit_msg>rewrite _cache.Add(key,value) to _cache[key] = value;<commit_after>﻿using System.Collections.Generic;

namespace DotKafka.Prototype.Common.Cache {
    public class LRUCache<K, V> : ICache<K, V> {
        private readonly Dictionary<K, V> _cache;
        private readonly LinkedList<K> _lruList;
        private readonly int _capacity;

        public int Size => _cache.Count;

        public LRUCache(int maxSize) {
            _capacity = maxSize;
            _cache = new Dictionary<K, V>(_capacity);
            _lruList = new LinkedList<K>();
        }

        public V Get(K key) {
            V value;

            if (!_cache.TryGetValue(key, out value))
                return default(V);

            var node = _lruList.Find(key);

            _lruList.Remove(node);

            _lruList.AddFirst(node);

            return value;
        }

        public void Put(K key, V value) {
            LinkedListNode<K> node;

            if (_cache.ContainsKey(key)) {
                node = _lruList.Find(key);

                _lruList.Remove(node);

                _lruList.AddFirst(node);
            }
            else {
                if (_cache.Count >= _capacity) {
                    node = _lruList.Last;

                    _cache.Remove(node.Value);

                    _lruList.RemoveLast();
                }

                _lruList.AddFirst(key);
            }

            _cache[key] = value;
        }

        public bool Remove(K key) {
            return _cache.Remove(key) && _lruList.Remove(key);
        }
    }
}
{'fraction_non_alphanumeric': 0.10122218740206831, 'fraction_numerical': 0.0, 'mean_word_length': 1.4648648648648648, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, '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': '1073249', 'n_tokens_mistral': 960, 'n_tokens_neox': 898, 'n_words': 194}