Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Reorder functions in LruCache header
Browse files Browse the repository at this point in the history
  • Loading branch information
halfalicious committed Jul 30, 2019
1 parent c18f3e1 commit eb8969b
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions libdevcore/LruCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class LruCache

public:
explicit LruCache(size_t _capacity) : m_capacity(_capacity) {}

LruCache(LruCache<key_type, value_type> const& _l)
{
m_capacity = _l.m_capacity;
Expand Down Expand Up @@ -51,26 +52,6 @@ class LruCache
return *this;
}

bool contains(key_type const& _key) const { return m_index.find(_key) != m_index.cend(); }

bool contains(key_type const& _key, value_type const& _value) const
{
auto const cIter = m_index.find(_key);
return cIter != m_index.cend() && (*(cIter->second)).second == _value;
}

typename list_type::const_iterator cbegin() const { return m_data.cbegin(); }

typename list_type::iterator begin() { return m_data.begin(); }

typename list_type::const_iterator cend() const { return m_data.cend(); }

typename list_type::iterator end() { return m_data.end(); }

size_t size() const { return m_index.size(); }

bool empty() const { return m_index.empty(); }

size_t insert(key_type const& _key, value_type const& _val)
{
auto const cIter = m_index.find(_key);
Expand Down Expand Up @@ -104,8 +85,6 @@ class LruCache
return m_index.size();
}

size_t capacity() const { return m_capacity; }

bool touch(key_type const& _key)
{
auto const cIter = m_index.find(_key);
Expand All @@ -117,12 +96,32 @@ class LruCache
return false;
}

bool contains(key_type const& _key) const { return m_index.find(_key) != m_index.cend(); }

bool contains(key_type const& _key, value_type const& _value) const
{
auto const cIter = m_index.find(_key);
return cIter != m_index.cend() && (*(cIter->second)).second == _value;
}

bool empty() const { return m_index.empty(); }

size_t size() const { return m_index.size(); }

size_t capacity() const { return m_capacity; }

void clear()
{
m_index.clear();
m_data.clear();
}

// Expose data iterator for testing purposes
typename list_type::const_iterator cbegin() const { return m_data.cbegin(); }
typename list_type::iterator begin() { return m_data.begin(); }
typename list_type::const_iterator cend() const { return m_data.cend(); }
typename list_type::iterator end() { return m_data.end(); }

private:
list_type m_data;
map_type m_index;
Expand Down

0 comments on commit eb8969b

Please sign in to comment.