GithubHelp home page GithubHelp logo

skyformat99 / caches Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vpetrigo/caches

0.0 2.0 0.0 40 KB

LRU, LFU, FIFO cache C++ implementations

License: BSD 3-Clause "New" or "Revised" License

CMake 7.26% C++ 92.74%

caches's Introduction

Build Status Build status

C++ Cache implementation

This project implements a simple thread-safe cache with several page replacement policies:

  • Least Recently Used
  • First-In/First-Out
  • Least Frequently Used

More about cache algorithms and policy you could read on Wikipedia

Usage

Using this library is simple. It is necessary to include header with the cache implementation (cache.hpp file) and appropriate header with the cache policy if it is needed. If not then the non-special algorithm will be used (it removes the last element which key is the last in the internal container).

Currently there is only three of them:

  • fifo_cache_policy.hpp
  • lfu_cache_policy.hpp
  • lru_cache_policy.hpp

Example for the LRU policy:

#include <string>
#include "cache.hpp"
#include "lru_cache_policy.hpp"

// alias for easy class typing
template <typename Key, typename Value>
using lru_cache_t = typename caches::fixed_sized_cache<Key, Value, LRUCachePolicy<Key>>;

void foo(...) {
  constexpr std::size_t CACHE_SIZE = 256;
  lru_cache_t<std::string, int> cache(CACHE_SIZE);

  cache.Put("Hello", 1);
  cache.Put("world", 2);

  std::cout << cache.Get("Hello") << cache.Get("world") << std::endl;
  // "12"
}

Requirements

The only requirement is a compatible C++11 compiler.

This project was tested in the environments listed below:

  • MinGW64 (MSYS2 project)
    • Clang 3.8.0
    • GCC 5.3.0
  • MSVC (VS 2015)
  • FreeBSD
    • Clang 3.4.1

If you have any issues with the library building, let me know please.

Contributing

Please fork this repository and contribute back using pull requests. Features can be requested using issues. All code, comments, and critiques are greatly appreciated.

caches's People

Contributors

vpetrigo avatar karasikov avatar

Watchers

skyformat99 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.