【问题标题】:Boost Multi-Index : Composite key of vector and int for hashed indicesBoost Multi-Index:散列索引的向量和 int 的复合键
【发布时间】:2010-12-14 15:13:40
【问题描述】:

正如我刚刚在in my other question 中学到的,我可以将composite_key 用于结构,它有一个std::vector 和一个整数。现在我的问题是:我可以以某种方式使用它来处理 hashed_indecies 吗?

这里有一个类似于THIS的例子:

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;

问题是(当然)std::vector&lt;int&gt; 不是合适的哈希键。我可以把这段代码放在一个优雅的包装器中(或类似的东西),以从my_vec 的每个条目中生成一个哈希键吗?

【问题讨论】:

    标签: c++ boost vector multi-index


    【解决方案1】:

    使用您的建议 here 中的代码 sn-p。它应该工作。我已经在那里添加了我的 cmets。

    【讨论】:

      【解决方案2】:

      如果你希望向量是可散列的,你可以在namespace std 中写一个hash&lt;vector&lt;int&gt; &gt; 函数,让它随心所欲地散列(提示:你也许可以只散列一些中的前几个元素应用程序)。这应该使std::hash_set&lt;vector&lt;int&gt; &gt; 工作,我认为你的更复杂的容器也是如此。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-28
        • 2010-12-21
        • 1970-01-01
        • 2014-07-14
        相关资源
        最近更新 更多