<commit_before>/*
 @ <NAME>
*/

#if defined(_MSC_VER)
#pragma once
#endif

#ifndef KBASE_MEMORY_LRU_CACHE_H_
#define KBASE_MEMORY_LRU_CACHE_H_

#include <map>
#include <unordered_map>

namespace kbase {

// Standardize type argument signatures of std::map and std::unordered_map.

template<typename Key, typename Value>
struct TreeMap {
    using MapType = std::map<Key, Value>;
};

template<typename Key, typename Value>
struct HashMap {
    using MapType = std::unordered_map<Key, Value>;
};

template<typename Key, typename Entry, template<typename, typename> class Map>
class LRUCache {
public:
    using key_type = Key;
    using value_type = std::pair<const Key, Entry>;

private:
    using CachedEntryList = std::list<value_type>;
    using KeyTable = typename Map<Key, typename CachedEntryList::iterator>::MapType;

public:
    using size_type = size_t;
    using iterator = typename CachedEntryList::iterator;
    using const_iterator = typename CachedEntryList::const_iterator;
    using reverse_iterator = typename CachedEntryList::reverse_iterator;
    using const_reverse_iterator = typename CachedEntryList::const_reverse_iterator;

    enum : size_type {
        NO_AUTO_EVICT = 0
    };

    explicit LRUCache(size_type max_size)
        : max_size_(max_size)
    {}

    LRUCache(const LRUCache&) = delete;

    // TODO: LRUCache(LRUCache&&);

    LRUCache& operator=(const LRUCache&) = delete;

    // TODO: LRUCache& operator=(LRUCache&&);

    ~LRUCache() = default;

    // Add a pair of <key, entry> into the cache. If the key already exists, update
    // the entry.
    // If auto-eviction is enabled for the cache, and also cache runs out its free
    // storage, then LRU replacement algorithm is employed when caching into new
    // entry.

    iterator Put(const Key& key, const Entry& entry)
    {
        return PutInternal(key, entry);    
    }

    iterator Put(const Key& key, Entry&& entry)
    {
        return PutInternal(key, std::move(entry));
    }

    // Returns the iterator to the value associated with |key|.
    // Returns end() if no matched value was found.
    // Accessing a cached entry marks this entry as recently used by moving it to
    // the tail of cached entry list.
    iterator Get(const Key& key)
    {
        auto key_it = key_table_.find(key);
        if (key_it == key_table_.end()) {
            return end();
        }

        auto entry_it = key_it->second;
        entry_ordering_list_.splice(entry_ordering_list_.end(), entry_ordering_list_,
                                    entry_it);

        return entry_it;
    }

    iterator erase(const_iterator pos)
    {<commit_msg>tmp save for LRUCache<commit_after>/*
 @ <NAME>
*/

#if defined(_MSC_VER)
#pragma once
#endif

#ifndef KBASE_MEMORY_LRU_CACHE_H_
#define KBASE_MEMORY_LRU_CACHE_H_

#include <map>
#include <unordered_map>

namespace kbase {

// Standardize type argument signatures of std::map and std::unordered_map.

template<typename Key, typename Value>
struct TreeMap {
    using MapType = std::map<Key, Value>;
};

template<typename Key, typename Value>
struct HashMap {
    using MapType = std::unordered_map<Key, Value>;
};

template<typename Key, typename Entry, template<typename, typename> class Map>
class LRUCache {
public:
    using key_type = Key;
    using value_type = std::pair<const Key, Entry>;

private:
    using CachedEntryList = std::list<value_type>;
    using KeyTable = typename Map<Key, typename CachedEntryList::iterator>::MapType;

public:
    using size_type = size_t;
    using iterator = typename CachedEntryList::iterator;
    using const_iterator = typename CachedEntryList::const_iterator;
    using reverse_iterator = typename CachedEntryList::reverse_iterator;
    using const_reverse_iterator = typename CachedEntryList::const_reverse_iterator;

    enum : size_type {
        NO_AUTO_EVICT = 0
    };

    explicit LRUCache(size_type max_size)
        : max_size_(max_size)
    {}

    LRUCache(const LRUCache&) = delete;

    // TODO: LRUCache(LRUCache&&);

    LRUCache& operator=(const LRUCache&) = delete;

    // TODO: LRUCache& operator=(LRUCache&&);

    ~LRUCache() = default;

    // Add a pair of <key, entry> into the cache. If the key already exists, update
    // the entry.
    // If auto-eviction is enabled for the cache, and also cache runs out its free
    // storage, then LRU replacement algorithm is employed when caching into new
    // entry.

    iterator Put(const Key& key, const Entry& entry)
    {
        return PutInternal(key, entry);    
    }

    iterator Put(const Key& key, Entry&& entry)
    {
        return PutInternal(key, std::move(entry));
    }

    // Returns the iterator to the value associated with |key|.
    // Returns end() if no matched value was found.
    // Accessing a cached entry marks this entry as recently used by moving it to
    // the tail of cached entry list.
    iterator Get(const Key& key)
    {
        auto key_it = key_table_.find(key);
        if (key_it == key_table_.end()) {
            return end();
        }

        auto entry_it = key_it->second;
        entry_ordering_list_.splice(entry_ordering_list_.end(), entry_ordering_list_,
                                    entry_it);

        return entry_it;
    }

    const_iterator find(const Key& key) const
    {
        auto key_it = key_table_.find(key);
        if (key_it == key_table_.end()) {
            return end();
        }

        return key_it->second;
    }

    iterator find(const Key& key)
    {
        auto key_it = key_table_.find(key);
        if (key_it == key_table_.end()) {
            return end();
        }

        return key_it->second;
    }

    iterator erase(const_iterator pos)
    {
{'fraction_non_alphanumeric': 0.09888190076869321, 'fraction_numerical': 0.00034940600978336826, 'mean_word_length': 2.9293067947838023, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3592033', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1704, 'n_words': 508}