<commit_before>#pragma once

#include <algorithm>
#include <deque>
#include <functional>
#include <list>

namespace dariadb {
namespace utils {
template <class Key, class Value, class EqualPred = std::equal_to<Key>>
class LRU {
public:
  using pair_t = std::pair<Key, Value>;

  LRU(const size_t max_size):_max_size(max_size) {
  }
  
  void set_max_size(const size_t max_size) {
	  _max_size = max_size;
  }

  void erase(const Key&key) {
	  for (auto it = _deq.begin(); it != _deq.end(); ++it) {
		  if (EqualPred()(it->first, key)) {
			  _deq.erase(it);
			  break;
		  }
	  }
  }

  /// return true, if write to dropped value;
  bool put(const Key &k, const Value &v, Value*dropped) {
    _deq.push_front(std::make_pair(k, v));
	if (_deq.size() > _max_size) {
		*dropped = _deq.back().second;
		_deq.pop_back();
		return true;
	}
	return false;
  }

  bool find(const Key &k, Value *out) const {
    auto fres = std::find_if(_deq.begin(), _deq.end(), [&k](const pair_t &p) {
      return EqualPred()(p.first, k);
    });
    if (fres == _deq.end()) {
      return false;
    } else {
      *out = (*fres).second;
      return true;
    }
  }

  size_t size()const { return _deq.size(); }
protected:
  std::deque<pair_t> _deq;
  size_t _max_size;
};
}
}<commit_msg>lru: move finded value to head of queue<commit_after>#pragma once

#include <algorithm>
#include <deque>
#include <functional>
#include <list>

namespace dariadb {
namespace utils {
template <class Key, class Value, class EqualPred = std::equal_to<Key>>
class LRU {
public:
  using pair_t = std::pair<Key, Value>;

  LRU(const size_t max_size):_max_size(max_size) {
  }
  
  void set_max_size(const size_t max_size) {
	  _max_size = max_size;
  }

  void erase(const Key&key) {
	  for (auto it = _deq.begin(); it != _deq.end(); ++it) {
		  if (EqualPred()(it->first, key)) {
			  _deq.erase(it);
			  break;
		  }
	  }
  }

  /// return true, if write to dropped value;
  bool put(const Key &k, const Value &v, Value*dropped) {
	  inner_put(k, v);
	if (_deq.size() > _max_size) {
		*dropped = _deq.back().second;
		_deq.pop_back();
		return true;
	}
	return false;
  }

  bool find(const Key &k, Value *out)  {
    auto fres = std::find_if(_deq.begin(), _deq.end(), [&k](const pair_t &p) {
      return EqualPred()(p.first, k);
    });
    if (fres == _deq.end()) {
      return false;
    } else {
      *out = (*fres).second;
	  _deq.erase(fres);
	  inner_put(k, *out);
      return true;
    }
  }

  size_t size()const { return _deq.size(); }
protected:
	inline void inner_put(const Key&k, const Value &v){
          _deq.push_front(std::make_pair(k, v));
    }
protected:
  std::deque<pair_t> _deq;
  size_t _max_size;
};
}
}
{'fraction_non_alphanumeric': 0.16080029640607632, 'fraction_numerical': 0.0, 'mean_word_length': 3.2253521126760565, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, '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': '7183651', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1068, 'n_words': 251}