mohaps / lrucache11

A header only C++11 LRU Cache template class that allows you to define key, value and optionally the Map type. uses a double linked list and a std::unordered_map style container to provide fast insert, delete and update No dependencies other than the C++ standard library. This is a C++11 remake of my earlier LRUCache project (https://github.com/mohaps/lrucache) The goal was to create a fast LRUCache header only library and to avoid any dependencies like boost.
https://github.com/mohaps/lrucache11
294 stars 63 forks source link

Add support for custom hash() callback, allowing "non-hashable" keys, eg. vector #8

Closed breznak closed 7 years ago

breznak commented 8 years ago

the err is caused by the type I wish to use for a key:

lru11::Cache<int, double> cache(10,0); // works fine
lru11::Cache<vector<int>, double> cache(10, 0); // reproduces the err above. 

Even though as I understand, the operator== is defined well for vector<>, so also hashing(?) should work?

Is there any way to use the vector/array type as a key for the cache?

I found a solution/workaround in:

Can we pass a Hash=myHashFn in the template header the same way a Lock= is used? That would attempt to call myHashFn(key) each time a key is used to address the cache, allowing to hash the so-far unsupported key types (vector, tuple, ...)

Below is report and "historical development" of my point of view on the issue:

Ok, so #3 enables the samples to compile and all code in #7 runs.

On a more complex program I'm however hitting a "template" problem:

In file included from /home/mmm/devel/HTM/nupic.core/src/test/unit/encoders/CachedEncoderTest.cpp:1:
In file included from /home/mmm/devel/HTM/nupic.core/src/nupic/encoders/CachedEncoder.hpp:9:
In file included from /home/mmm/devel/HTM/nupic.core/src/nupic/encoders/LRUCache11.hpp:31:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/unordered_map:47:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/hashtable.h:35:
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/hashtable_policy.h:85:11: error: implicit instantiation of undefined template
      'std::hash<std::tuple<std::vector<int, std::allocator<int> >, double> >'
        noexcept(declval<const _Hash&>()(declval<const _Key&>()))>
                 ^

/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/type_traits:138:14: note: in instantiation of template class
      'std::__detail::__is_noexcept_hash<std::tuple<std::vector<int, std::allocator<int> >, double>, std::hash<std::tuple<std::vector<int, std::allocator<int> >, double> > >'
      requested here
    : public conditional<_B1::value, _B2, _B1>::type
             ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/type_traits:148:39: note: in instantiation of template class
      'std::__and_<std::__is_fast_hash<std::hash<std::tuple<std::vector<int, std::allocator<int> >, double> > >, std::__detail::__is_noexcept_hash<std::tuple<std::vector<int,
      std::allocator<int> >, double>, std::hash<std::tuple<std::vector<int, std::allocator<int> >, double> > > >' requested here
    : public integral_constant<bool, !_Pp::value>
                                      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/unordered_map.h:46:34: note: in instantiation of template class
      'std::__not_<std::__and_<std::__is_fast_hash<std::hash<std::tuple<std::vector<int, std::allocator<int> >, double> > >,
      std::__detail::__is_noexcept_hash<std::tuple<std::vector<int, std::allocator<int> >, double>, std::hash<std::tuple<std::vector<int, std::allocator<int> >, double> > > >
      >' requested here
           typename _Tr = __umap_traits<__cache_default<_Key, _Hash>::value>>
                                        ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/unordered_map.h:100:15: note: in instantiation of default argument for
      '__umap_hashtable<std::tuple<std::vector<int, std::allocator<int> >, double>, lru11::kv::Node<std::tuple<std::vector<int, std::allocator<int> >, double>,
      std::vector<unsigned int, std::allocator<unsigned int> > > *, std::hash<std::tuple<std::vector<int, std::allocator<int> >, double> >,
      std::equal_to<std::tuple<std::vector<int, std::allocator<int> >, double> >, std::allocator<std::pair<const std::tuple<std::vector<int, std::allocator<int> >, double>,
      lru11::kv::Node<std::tuple<std::vector<int, std::allocator<int> >, double>, std::vector<unsigned int, std::allocator<unsigned int> > > *> > >' required here
      typedef __umap_hashtable<_Key, _Tp, _Hash, _Pred, _Alloc>  _Hashtable;
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/mmm/devel/HTM/nupic.core/src/nupic/encoders/LRUCache11.hpp:356:6: note: in instantiation of template class 'std::unordered_map<std::tuple<std::vector<int,
      std::allocator<int> >, double>, lru11::kv::Node<std::tuple<std::vector<int, std::allocator<int> >, double>, std::vector<unsigned int, std::allocator<unsigned int> > > *,
      std::hash<std::tuple<std::vector<int, std::allocator<int> >, double> >, std::equal_to<std::tuple<std::vector<int, std::allocator<int> >, double> >,
      std::allocator<std::pair<const std::tuple<std::vector<int, std::allocator<int> >, double>, lru11::kv::Node<std::tuple<std::vector<int, std::allocator<int> >, double>,
      std::vector<unsigned int, std::allocator<unsigned int> > > *> > >' requested here
        Map cache_;
            ^
/home/mmm/devel/HTM/nupic.core/src/nupic/encoders/CachedEncoder.hpp:56:35: note: in instantiation of template class 'lru11::Cache<std::tuple<std::vector<int,
      std::allocator<int> >, double>, std::vector<unsigned int, std::allocator<unsigned int> >, lru11::NullLock, std::unordered_map<std::tuple<std::vector<int,
      std::allocator<int> >, double>, lru11::kv::Node<std::tuple<std::vector<int, std::allocator<int> >, double>, std::vector<unsigned int, std::allocator<unsigned int> > > *,
      std::hash<std::tuple<std::vector<int, std::allocator<int> >, double> >, std::equal_to<std::tuple<std::vector<int, std::allocator<int> >, double> >,
      std::allocator<std::pair<const std::tuple<std::vector<int, std::allocator<int> >, double>, lru11::kv::Node<std::tuple<std::vector<int, std::allocator<int> >, double>,
      std::vector<unsigned int, std::allocator<unsigned int> > > *> > > >' requested here
    lru11::Cache<T, vector<UInt>> cache; 
                                  ^

/home/mmm/devel/HTM/nupic.core/src/test/unit/encoders/CachedEncoderTest.cpp:16:45: note: in instantiation of template class 'encoders::CachedEncoder<std::tuple<std::vector<int,
      std::allocator<int> >, double> >' requested here
  CachedEncoder<tuple<vector<int>, double>> dummy(sub);
                                            ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/system_error:134:12: note: template is declared here
    struct hash;
           ^
In file included from /home/mmm/devel/HTM/nupic.core/src/test/unit/encoders/CachedEncoderTest.cpp:1:
In file included from /home/mmm/devel/HTM/nupic.core/src/nupic/encoders/CachedEncoder.hpp:9:
In file included from /home/mmm/devel/HTM/nupic.core/src/nupic/encoders/LRUCache11.hpp:31:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/unordered_map:48:
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/unordered_map.h:522:7: error: multiple overloads of 'erase' instantiate to the same signature
      'iterator (iterator)' (aka 'int (int)')
      erase(iterator __position)
      ^
/home/mmm/devel/HTM/nupic.core/src/nupic/encoders/LRUCache11.hpp:356:6: note: in instantiation of template class 'std::unordered_map<std::tuple<std::vector<int,
      std::allocator<int> >, double>, lru11::kv::Node<std::tuple<std::vector<int, std::allocator<int> >, double>, std::vector<unsigned int, std::allocator<unsigned int> > > *,
      std::hash<std::tuple<std::vector<int, std::allocator<int> >, double> >, std::equal_to<std::tuple<std::vector<int, std::allocator<int> >, double> >,
      std::allocator<std::pair<const std::tuple<std::vector<int, std::allocator<int> >, double>, lru11::kv::Node<std::tuple<std::vector<int, std::allocator<int> >, double>,
      std::vector<unsigned int, std::allocator<unsigned int> > > *> > >' requested here
        Map cache_;
            ^
/home/mmm/devel/HTM/nupic.core/src/nupic/encoders/CachedEncoder.hpp:56:35: note: in instantiation of template class 'lru11::Cache<std::tuple<std::vector<int,
      std::allocator<int> >, double>, std::vector<unsigned int, std::allocator<unsigned int> >, lru11::NullLock, std::unordered_map<std::tuple<std::vector<int,
      std::allocator<int> >, double>, lru11::kv::Node<std::tuple<std::vector<int, std::allocator<int> >, double>, std::vector<unsigned int, std::allocator<unsigned int> > > *,
      std::hash<std::tuple<std::vector<int, std::allocator<int> >, double> >, std::equal_to<std::tuple<std::vector<int, std::allocator<int> >, double> >,
      std::allocator<std::pair<const std::tuple<std::vector<int, std::allocator<int> >, double>, lru11::kv::Node<std::tuple<std::vector<int, std::allocator<int> >, double>,
      std::vector<unsigned int, std::allocator<unsigned int> > > *> > > >' requested here
    lru11::Cache<T, vector<UInt>> cache; 
                                  ^
/home/mmm/devel/HTM/nupic.core/src/test/unit/encoders/CachedEncoderTest.cpp:16:45: note: in instantiation of template class 'encoders::CachedEncoder<std::tuple<std::vector<int,
      std::allocator<int> >, double> >' requested here
  CachedEncoder<tuple<vector<int>, double>> dummy(sub);
                                            ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/unordered_map.h:517:7: note: previous declaration is here
      erase(const_iterator __position)
      ^

Can you help me with it please @mohaps ?

My ./configure (cmake), if that helps:

$ CC=clang-3.8 CXX=clang++-3.8 cmake $NUPIC_CORE -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../release -DPY_EXTENSIONS_DIR=$NUPIC_CORE/bindings/py/nupic/bindings 
-- NUPIC_BUILD_PYEXT_MODULES = ON
-- PY_EXTENSIONS_DIR         = /home/mmm/devel/HTM/nupic.core/bindings/py/nupic/bindings
Doing a local build
-- CMAKE_CXX_COMPILER_ID = Clang
-- CMAKE_C_COMPILER      = 
-- CMAKE_CXX_COMPILER    = /usr/bin/clang++-3.8
-- CMAKE_BUILD_TYPE      = Release
-- CMAKE_INSTALL_PREFIX  = /home/mmm/devel/HTM/nupic.core/build/release
-- CMAKE BITNESS=64
-- CMAKE MEMORY=5672
GNU gold (GNU Binutils for Ubuntu 2.26.1) 1.11
Copyright (C) 2015 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
Using ld.gold as LINKER.
-- INTERNAL_CXX_FLAGS_OPTIMIZED=  -fvisibility=hidden  -fdiagnostics-show-option -m64 -fPIC -Wno-deprecated-register   -std=c++11 -fvisibility-inlines-hidden  -Werror -Wextra -Wreturn-type -Wunused -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers -Wall -pipe  -O2 -mtune=generic
-- INTERNAL_LINKER_FLAGS_OPTIMIZED=  -m64   -Wl,-undefined,error -O2 
-- EXTERNAL_C_FLAGS_UNOPTIMIZED=  -fvisibility=hidden  -fdiagnostics-show-option -m64 -fPIC -Wno-deprecated-register  -Wno-unused-variable -Wno-unused-parameter -Wno-incompatible-pointer-types -Wno-deprecated-declarations
-- EXTERNAL_C_FLAGS_OPTIMIZED=  -fvisibility=hidden  -fdiagnostics-show-option -m64 -fPIC -Wno-deprecated-register  -Wno-unused-variable -Wno-unused-parameter -Wno-incompatible-pointer-types -Wno-deprecated-declarations -pipe  -O2 -mtune=generic
-- PYEXT_LINKER_FLAGS_OPTIMIZED=  -m64   -O2  -Wl,-undefined,dynamic_lookup
-- EXTERNAL_CXX_FLAGS_UNOPTIMIZED=  -fvisibility=hidden  -fdiagnostics-show-option -m64 -fPIC -Wno-deprecated-register  -Wno-unused-variable -Wno-unused-parameter -Wno-incompatible-pointer-types -Wno-deprecated-declarations   -std=c++11 -fvisibility-inlines-hidden
-- EXTERNAL_CXX_FLAGS_OPTIMIZED=  -fvisibility=hidden  -fdiagnostics-show-option -m64 -fPIC -Wno-deprecated-register  -Wno-unused-variable -Wno-unused-parameter -Wno-incompatible-pointer-types -Wno-deprecated-declarations   -std=c++11 -fvisibility-inlines-hidden -pipe  -O2 -mtune=generic
-- EXTERNAL_LINKER_FLAGS_UNOPTIMIZED=  -m64   -Wl,-undefined,error
-- EXTERNAL_LINKER_FLAGS_OPTIMIZED=  -m64   -Wl,-undefined,error -O2 
-- COMMON_COMPILER_DEFINITIONS=-DHAVE_UNISTD_H
-- COMMON_COMPILER_DEFINITIONS_STR= -DHAVE_UNISTD_H
-- EXTERNAL_STATICLIB_CMAKE_DEFINITIONS_OPTIMIZED=
-- EXTERNAL_STATICLIB_CONFIGURE_DEFINITIONS_OPTIMIZED=
-- CapnProto CXX_FLAGS=  -fvisibility=hidden  -fdiagnostics-show-option -m64 -fPIC -Wno-deprecated-register  -Wno-unused-variable -Wno-unused-parameter -Wno-incompatible-pointer-types -Wno-deprecated-declarations   -std=c++11 -fvisibility-inlines-hidden  -DHAVE_UNISTD_H
-- MERGE_STATIC_LIBRARIES LIB_TARGET=capnp-bundle, STATIC_LIBS = /home/mmm/devel/HTM/nupic.core/build/scripts/ThirdParty/Install/lib/libcapnpc.a;/home/mmm/devel/HTM/nupic.core/build/scripts/ThirdParty/Install/lib/libcapnp.a;/home/mmm/devel/HTM/nupic.core/build/scripts/ThirdParty/Install/lib/libkj.a
-- MERGE_STATIC_LIBRARIES LIB_TARGET=apr-1-bundle, STATIC_LIBS = /home/mmm/devel/HTM/nupic.core/build/scripts/ThirdParty/Install/Apr1StaticLib/lib/libapr-1.a
-- MERGE_STATIC_LIBRARIES LIB_TARGET=aprutil-1-bundle, STATIC_LIBS = /home/mmm/devel/HTM/nupic.core/build/scripts/ThirdParty/Install/AprUtil1StaticLib/lib/libaprutil-1.a
-- MERGE_STATIC_LIBRARIES LIB_TARGET=yaml-bundle, STATIC_LIBS = /home/mmm/devel/HTM/nupic.core/build/scripts/ThirdParty/Build/YamlStaticLib/libyaml.a
-- MERGE_STATIC_LIBRARIES LIB_TARGET=yaml-cpp-bundle, STATIC_LIBS = /home/mmm/devel/HTM/nupic.core/build/scripts/ThirdParty/Install/YamlCppStaticLib/lib/libyaml-cpp.a
-- MERGE_STATIC_LIBRARIES LIB_TARGET=z-bundle, STATIC_LIBS = /home/mmm/devel/HTM/nupic.core/build/scripts/ThirdParty/Install/ZStaticLib/lib/libz.a
-- CMAKE Found python interpreter /home/mmm/devel/HTM/env/bin/python2.7 version=2.7.11
-- src_numpy_core   = /home/mmm/devel/HTM/env/local/lib/python2.7/site-packages/numpy/core
-- CMAKE_PREFIX_PATH   = /home/mmm/devel/HTM/nupic.core/external/common/;/home/mmm/devel/HTM/nupic.core/external/linux64/;/home/mmm/devel/HTM/env/local/lib/python2.7/site-packages/numpy/core/
-- PYTHON_EXECUTABLE   = /home/mmm/devel/HTM/env/bin/python2.7
-- PYTHON_INCLUDE_DIRS = /home/mmm/devel/HTM/env/include/python2.7
-- PYTHON_LIBRARIES    = /usr/lib/x86_64-linux-gnu/libpython2.7.so
-- src_pycapnp_include_dir      = /home/mmm/devel/HTM/env/local/lib/python2.7/site-packages
-- CAPNP_EXECUTABLE          = /home/mmm/devel/HTM/nupic.core/build/scripts/ThirdParty/Install/bin/capnp
-- CAPNP_CMAKE_DEFINITIONS   = -DCAPNP_LITE=0
-- CAPNP_INCLUDE_DIRS        = /home/mmm/devel/HTM/nupic.core/build/scripts/ThirdParty/Install/include
-- CAPNP_STATIC_LIB_TARGET   = capnp-bundle
-- src_common_os_libs        = pthread;dl
-- src_compile_flags =   -fvisibility=hidden  -fdiagnostics-show-option -m64 -fPIC -Wno-deprecated-register   -std=c++11 -fvisibility-inlines-hidden  -Werror -Wextra -Wreturn-type -Wunused -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers -Wall -pipe  -O2 -mtune=generic
-- src_lib_static_nupiccore_compile_flags =   -fvisibility=hidden  -fdiagnostics-show-option -m64 -fPIC -Wno-deprecated-register   -std=c++11 -fvisibility-inlines-hidden  -Werror -Wextra -Wreturn-type -Wunused -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers -Wall -pipe  -O2 -mtune=generic -I/home/mmm/devel/HTM/env/local/lib/python2.7/site-packages/numpy/core/include
-- MERGE_STATIC_LIBRARIES LIB_TARGET=nupic_core, STATIC_LIBS = nupic_core_solo;yaml-cpp-bundle;yaml-bundle;apr-1-bundle;aprutil-1-bundle;z-bundle
-- MERGE_STATIC_LIBRARIES: Link interface not specified in source lib nupic_core_solo.
-- MERGE_STATIC_LIBRARIES: Link interface not specified in source lib yaml-cpp-bundle.
-- MERGE_STATIC_LIBRARIES: Link interface not specified in source lib yaml-bundle.
-- MERGE_STATIC_LIBRARIES: Link interface not specified in source lib apr-1-bundle.
-- MERGE_STATIC_LIBRARIES: Link interface not specified in source lib aprutil-1-bundle.
-- MERGE_STATIC_LIBRARIES: Link interface not specified in source lib z-bundle.
-- src_common_test_exe_libs = nupic_core;/usr/lib/x86_64-linux-gnu/libpython2.7.so;pthread;dl;capnp-bundle
-- src_swig_flags = -c++;-features;autodoc=0,directors=0;-noproxyimport;-keyword;-modern;-modernargs;-noproxydel;-fvirtual;-fastunpack;-nofastproxy;-fastquery;-outputtuple;-castmode;-nosafecstrings;-w402;-w503;-w511;-w302;-w362;-w312;-w389;-DSWIG_PYTHON_LEGACY_BOOL;-I/home/mmm/devel/HTM/nupic.core/build/scripts/ThirdParty/Install/share/swig/3.0.2/python;-I/home/mmm/devel/HTM/nupic.core/build/scripts/ThirdParty/Install/share/swig/3.0.2;-DHAVE_UNISTD_H;-DNTA_OS_LINUX;-DNTA_ARCH_64;-DHAVE_CONFIG_H;-DNTA_INTERNAL;-DBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS;-DBOOST_NO_WREGEX;-DNUPIC2;-DAPR_DECLARE_STATIC;-DAPU_DECLARE_STATIC;-DNTA_ASM;-DNTA_COMPILER_CLANG
-- _SRC_SWIG_EXTRA_DEPS     = Swig
-- _SRC_SWIG_LINK_LIBRARIES = nupic_core;pthread;dl
-- _SRC_SWIG_EXTENSION_LINK_FLAGS=   -m64   -O2  -Wl,-undefined,dynamic_lookup
-- CMAKE_SWIG_FLAGS        = -c++;-features;autodoc=0,directors=0;-noproxyimport;-keyword;-modern;-modernargs;-noproxydel;-fvirtual;-fastunpack;-nofastproxy;-fastquery;-outputtuple;-castmode;-nosafecstrings;-w402;-w503;-w511;-w302;-w362;-w312;-w389;-DSWIG_PYTHON_LEGACY_BOOL;-I/home/mmm/devel/HTM/nupic.core/build/scripts/ThirdParty/Install/share/swig/3.0.2/python;-I/home/mmm/devel/HTM/nupic.core/build/scripts/ThirdParty/Install/share/swig/3.0.2;-DHAVE_UNISTD_H;-DNTA_OS_LINUX;-DNTA_ARCH_64;-DHAVE_CONFIG_H;-DNTA_INTERNAL;-DBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS;-DBOOST_NO_WREGEX;-DNUPIC2;-DAPR_DECLARE_STATIC;-DAPU_DECLARE_STATIC;-DNTA_ASM;-DNTA_COMPILER_CLANG
-- Writing export map file /home/mmm/devel/HTM/nupic.core/build/scripts/src/_algorithms_generated.expmap ({global: init_algorithms; local: *;};).
-- Created Swig target _algorithms for swig module algorithms. extra_deps=Swig;/home/mmm/devel/HTM/nupic.core/build/scripts/src/_algorithms_generated.expmap, link_flags=  -m64   -O2  -Wl,-undefined,dynamic_lookup -Wl,--version-script=/home/mmm/devel/HTM/nupic.core/build/scripts/src/_algorithms_generated.expmap
-- Writing export map file /home/mmm/devel/HTM/nupic.core/build/scripts/src/_engine_internal_generated.expmap ({global: init_engine_internal; local: *;};).
-- Created Swig target _engine_internal for swig module engine_internal. extra_deps=Swig;/home/mmm/devel/HTM/nupic.core/build/scripts/src/_engine_internal_generated.expmap, link_flags=  -m64   -O2  -Wl,-undefined,dynamic_lookup -Wl,--version-script=/home/mmm/devel/HTM/nupic.core/build/scripts/src/_engine_internal_generated.expmap
-- Writing export map file /home/mmm/devel/HTM/nupic.core/build/scripts/src/_experimental_generated.expmap ({global: init_experimental; local: *;};).
-- Created Swig target _experimental for swig module experimental. extra_deps=Swig;/home/mmm/devel/HTM/nupic.core/build/scripts/src/_experimental_generated.expmap, link_flags=  -m64   -O2  -Wl,-undefined,dynamic_lookup -Wl,--version-script=/home/mmm/devel/HTM/nupic.core/build/scripts/src/_experimental_generated.expmap
-- Writing export map file /home/mmm/devel/HTM/nupic.core/build/scripts/src/_math_generated.expmap ({global: init_math; local: *;};).
-- Created Swig target _math for swig module math. extra_deps=Swig;/home/mmm/devel/HTM/nupic.core/build/scripts/src/_math_generated.expmap, link_flags=  -m64   -O2  -Wl,-undefined,dynamic_lookup -Wl,--version-script=/home/mmm/devel/HTM/nupic.core/build/scripts/src/_math_generated.expmap
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mmm/devel/HTM/nupic.core/build/scripts

Thank you very much

mohaps commented 8 years ago

the easiest way is to define a std::hash<> for your vector object

for a vector it might be worthwhile to look into boost::hash_combine()

breznak commented 8 years ago

I know about the boost::hash_combine(), but I'm lost defining my custom class/hash function? to wrap vector and allow me using it in the Cache. Could you help me explain that please? This would be a nice doc/sample.

I found http://en.cppreference.com/w/cpp/utility/hash

mohaps commented 8 years ago

you can specify the MapType in the template params

have you tried with

using VMap = std::map< std::vector<int>,  double >;
using MyCache = lru11::Cache< std::vector<int>, double, NullLock, VMap >;

you'll need to #include <map> as per this: http://stackoverflow.com/questions/8903737/stl-map-with-a-vector-for-the-key std::vector can be a key in a map. the default in lrucache11 is an unordered map.

I'm currently away from my dev machine and will try this later.

If that works, I will close this issue

breznak commented 8 years ago

I'll test this approach, thank you very much :+1: