dodokek / LFU-Cache

Implementation of LFU Caching algorithm with C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cache

Overview

Here are my 2 different implementations of LFU cache and implementation of "Perfect" cache(Cache, awared of future queries).

Build

To build the project, you need to execute the following commands:

cd Cache
mkdir build
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release
make --directory=build

You will executables:

  • LFU_hashmap - O(1) realisation of LFU
  • perfect_cache - realisation of perfect cache

Testing

In this repository you can also find Python script for test generation and Shellscript for answers generation.

Script for compilation and comparison with perfect caching

To compile LFU_hashmap and compare its performance with Perfect cache, enter the following command:

# -----------------------------v Any executable name could be here
./test_gen/test_and_compare.sh LFU_hashmap

Scripts explanation

You can generate any amount (10 as example) of tests by:

mkdir tests
./test_get/gen_tests.py
> 10 

After that, you can run tests on executable by:

./test_gen/run_tests.sh <amount_of_tests> <path_to_exec> <path_to_ans_folder>
# example: ./run_tests.sh 10 ../LFU/build/perfect_cache ./perfect

To compare answers, you need to execute the following script

#/test_gen/

./compare.sh <tests_amount> <path_to_ans1_folder> <path_to_ans2_folder>
# example: ./compare.sh 9 ./tests/perfect ./tests/native

Conclusion

I learned a lot of new C++ mechanics, thanks to this project. You can read more about O(1) realisation of LFU cache here: http://dhruvbird.com/lfu.pdf

About

Implementation of LFU Caching algorithm with C++


Languages

Language:C++ 79.6%Language:Shell 11.2%Language:Python 5.3%Language:CMake 3.9%