53362

Boost Multi-Index : Composite key of vector and int for hashed indices

Question:

as I've just learned in <a href="https://stackoverflow.com/questions/1699704/boostmultiindexcontainer-with-randomaccess-and-orderedunique" rel="nofollow">in my other question</a>, I could use a composite_key for a struct, which has a std::vector and an integer. Now my question is: Can I use this somehow to work with hashed_indecies?

Here an example similar to <a href="http://www.boost.org/doc/libs/1_40_0/libs/multi_index/doc/tutorial/key_extraction.html#composite_keys_hash" rel="nofollow">THIS</a>:

struct unique_property { //the pair of int and std::vector<int> shall be unique int my_int; std::vector<int> my_vec; }; typedef multi_index_container< unique_property, indexed_by< hashed_unique< // indexed by my_int and every entry of my_vec composite_key< street_entry, member<unique_property,int,&unique_property::my_int>, member<unique_property,std::vector<int>,&unique_property::my_vec> > >, random_access< > > > property_locator;

The problem is (of course) that a std::vector<int> is no suitable hash-key. Can I put this code in an elegant wrapper (or something like that), to produce a hash-key from every entry of my_vec as well?

Answer1:

Use code snippet from your suggestion <a href="https://stackoverflow.com/questions/1699704/boostmultiindexcontainer-with-randomaccess-and-orderedunique/1700899#1700899" rel="nofollow">here</a>. It should work. I've added my comments there.

Answer2:

If you want vector to be hashable, you can just write a hash<vector<int> > function in namespace std, making it hash however you please (hint: you might be able to get away with hashing only the first few elements in some applications). This should make std::hash_set<vector<int> > work, and I think your more complex container as well.

Recommend

  • How to pass a boxed slice (`Box`) to a C function?
  • Sphinx Search Index
  • search for multiple indecies with Boost Multi-Index
  • in/out variables among shaders in a Pipeline Program
  • Doctrine ORM level difference between @UniqueConstraint and @Column(unique=true) options
  • Generate Facebook user picture using third_party_id
  • How to push ViewController with slide effect from left to right? Animation name required
  • hibernate entity is not mapped since version 4.3.2
  • Looping and adding to a counter in R
  • $this->db->insert_id(); returning 0 every time in codeigniter [duplicate]
  • Grouping observations based on first row value
  • Duplicate Entries in DB
  • Will new Date().toJSON() always be unique in Javascript?
  • Laravel 4 - Access Auth Class in Validation Class
  • How to utilize external libraries w/ Maquette.js?
  • Finding regular expressions for languages otherwise described
  • Variant of defaultdict for assigning value only once
  • MySQL select genres issue (php)
  • Assign dynamic ids to hidden fields when iterating over a collection
  • Validation: how to check for specific error
  • Linked tables and Slicer in excel
  • Returning semi-unique values from a list
  • bcrypt-nodejs compare method returns false every time
  • Passing unspecialized template as a template parameter
  • Count the occurrences across multiple columns
  • How to make a user wait with Laravel
  • Find unique tuples in a relation represented by a BDD
  • Slowly changing dimension - What is Pure type 6 implementation
  • SQL append distinct values from two columns and two tables
  • iOS - Is this a task for enums?
  • Hibernate: Inheritance and relationship mapping + generics
  • Should I use composite primary keys in Grails?
  • Is there a parser equivalent of 'fragment' marking in ANTLR4?
  • C++ Single function pointer for all template instances
  • Simple linked list-C
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?