<commit_before>#ifndef RETRIEVER_CACHE_HPP
#define RETRIEVER_CACHE_HPP

#include "list.hpp"
#include <memory>
#include <shared_mutex>
#include <unordered_map>

template <typename K, typename V> class CacheItem : public Item {
public:
  CacheItem(K k, V v) : key(k), value(v){};
  K key;
  V value;
};

template <typename K, typename V> class Cache {
public:
  explicit Cache(const int capacity) : capacity(capacity) {
    lookUpTable =
        std::unordered_map<K, std::unique_ptr<CacheItem<K, V>>>(capacity);
  };

  void set(const K key, const V value) {
    std::unique_lock<std::shared_mutex> lock(tableSMutex);

    auto mapIt = lookUpTable.find(key);
    if (mapIt == lookUpTable.end()) {
      std::unique_ptr<CacheItem<K, V>> item(new CacheItem<K, V>(key, value));
      if (lookUpTable.size() == capacity) {
        auto toRemove = kList.back;
        kList.remove(toRemove);
        lookUpTable.erase(
            lookUpTable.find(dynamic_cast<CacheItem<K, V> *>(toRemove)->key));
      }
      kList.pushFront(dynamic_cast<Item *>(item.get()));
    } else {
      auto item = mapIt->second;
      item->value = value;
      kList.moveToFront(dynamic_cast<Item *>(item.get()));
    }
  };

  V get(const K key) {
    std::shared_lock<std::shared_mutex> lock(tableSMutex);

    auto mapIt = lookUpTable.find(key);
    if (mapIt == lookUpTable.end()) {
      return V();
    }
    kList.moveToFront(dynamic_cast<Item *>(mapIt->second->get()));
    return mapIt->second->value;
  };

private:
  Cache(){};

  int capacity;
  std::unordered_map<K, std::unique_ptr<CacheItem<K, V>>> lookUpTable;
  std::shared_mutex tableSMutex;
  List kList;
};

#endif
<commit_msg>fix: transfer unordered map parameter<commit_after>#ifndef RETRIEVER_CACHE_HPP
#define RETRIEVER_CACHE_HPP

#include "list.hpp"
#include <memory>
#include <shared_mutex>
#include <unordered_map>

template <typename K, typename V> class CacheItem : public Item {
public:
  CacheItem(K k, V v) : key(k), value(v){};
  K key;
  V value;
};

template <typename K, typename V, class Hash = std::hash<K>,
          class KeyEqual = std::equal_to<K>,
          class Allocator = std::allocator<std::pair<const K, V>>>
class Cache {
public:
  explicit Cache(const int capacity) : capacity(capacity) {
    lookUpTable = std::unordered_map<K, std::unique_ptr<CacheItem<K, V>>, Hash,
                                     KeyEqual, Allocator>(capacity);
  };

  void set(const K key, const V value) {
    std::unique_lock<std::shared_mutex> lock(tableSMutex);

    auto mapIt = lookUpTable.find(key);
    if (mapIt == lookUpTable.end()) {
      std::unique_ptr<CacheItem<K, V>> item(new CacheItem<K, V>(key, value));
      if (lookUpTable.size() == capacity) {
        auto toRemove = kList.back;
        kList.remove(toRemove);
        lookUpTable.erase(
            lookUpTable.find(dynamic_cast<CacheItem<K, V> *>(toRemove)->key));
      }
      kList.pushFront(dynamic_cast<Item *>(item.get()));
    } else {
      auto item = mapIt->second;
      item->value = value;
      kList.moveToFront(dynamic_cast<Item *>(item.get()));
    }
  };

  V get(const K key) {
    std::shared_lock<std::shared_mutex> lock(tableSMutex);

    auto mapIt = lookUpTable.find(key);
    if (mapIt == lookUpTable.end()) {
      return V();
    }
    kList.moveToFront(dynamic_cast<Item *>(mapIt->second->get()));
    return mapIt->second->value;
  };

private:
  Cache(){};

  int capacity;
  std::unordered_map<K, std::unique_ptr<CacheItem<K, V>>, Hash, KeyEqual,
                     Allocator>
      lookUpTable;
  std::shared_mutex tableSMutex;
  List kList;
};

#endif

{'fraction_non_alphanumeric': 0.1515067735692563, 'fraction_numerical': 0.0, 'mean_word_length': 3.4944099378881988, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7268423', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1240, 'n_words': 265}