
El 16/09/2011 19:15, Chris Cleeland escribió:
I'm trying to use boost::multi_index_container on a type that I've defined. I want the container to have two indices:
1. insertion order 2. hashed_unique
Further, I want the hash to use an sha1 hash value, which I have represented as a struct. So, I have something like the following:
struct sha1_hash_value { ... };
class MyRecord { public: ... sha1_hash_value hash() const { return _sha1_hash; } ... private: sha1_hash_value _sha1_hash; };
using namespace boost::multi_index;
typedef boost::multi_index_container< MyRecord, indexed_by< sequenced<>, hashed_unique
> RecordSet;
Hi Chris, you have the concepts here slightly mixed up. The specification of a unique hashed index goes like (http://tinyurl.com/3n67upt ) hashed_unique< KeyFromValue, Hash=boost::hashKeyFromValue::result_type, Pred=std::equal_toKeyFromValue::result_type
where KeyFromValue is a key extractor, that is, the functor returning the piece of
info on which you want to do the hashing, and Hash and Pred are the (hashing,
equality) pair on that key. Furthermore, Hash must return a std::size_t.
Your particular case is a little exotic because MyRecord stores a precalculated
hash value (usually, the hash is calculated on the fly.) You can handle this situation
in one of the following two ways:
1. Consider that the key is MyRecord::hash():
hashed_unique<
const_mem_fun
For this to work, the default Hash predicate (boost::hash
Here, the default value for Hash is boost::hash<MyRecord>, which again you must customize as explained in http://tinyurl.com/5sfsmyo , simply using the value returned by MyRecord::hash in the process. Similar considerations apply to std::equal<MyRercord>. Hope this helps, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Este mensaje se dirige exclusivamente a su destinatario. Puede consultar nuestra política de envío y recepción de correo electrónico en el enlace situado más abajo. This message is intended exclusively for its addressee. We only send and receive email on the basis of the terms set out at. http://www.tid.es/ES/PAGINAS/disclaimer.aspx