Closed breznak closed 7 years ago
the easiest way is to define a std::hash<> for your vector object
for a vector
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.
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
I'll test this approach, thank you very much :+1:
the err is caused by the type I wish to use for a key:
Even though as I understand, the
operator==
is defined well forvector<>
, 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 aLock=
is used? That would attempt to callmyHashFn(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:
Can you help me with it please @mohaps ?
My
./configure
(cmake), if that helps:Thank you very much