标签: multikey

如何使用/创建boost :: multi_index?

有人可以详细解释如何使用boost::multi_index?创建多索引地图?我在网上看到很多例子,还有提升页面,但我无法理解.我想将多个int/longs的类对象指针映射为键.有人可以帮我理解这个吗?

我有一个类X,哪些是类的多个属性long long,long,int,int.我想存储的属性long long,long,int,int作为键映射到- > <指针X>.

我希望能够查找给定任何属性的指针.某些属性对于每个对象都是唯一的,有些属性X不是唯一的.

c++ boost visual-c++ multikey

8
推荐指数
1
解决办法
3436
查看次数

用多个键映射

我正在尝试实现类似的地图

Map<<key1, key2>, List<value>>
Run Code Online (Sandbox Code Playgroud)

地图应包含2个键,相应的值将是一个列表.如果更改一个键值相等,我想在同一列表中添加记录 例如,考虑以下记录

R1[key1, key2]
R2[key1, null/empty] - Key1 is equal
R3[null/empty, key2] - Key2 is equal
R4[key1, key2] - Key1 and Key2 both are equal.
Run Code Online (Sandbox Code Playgroud)

所有应该插入相同的列表中

Key = <Key1,Key2> 
Value = <R1, R2, R3, R4>
Run Code Online (Sandbox Code Playgroud)

我不能使用Guava表公共MulitKeyMap(不要只为此包含整个库).

我试图实现一个类(我可以用作一个键),它将具有key1key2作为属性,但实现一个有效的哈希码,不考虑key1和key2似乎有点(或可能很多)棘手

public class Key {
    private int key1;
    private int key2;

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        // Cant include key1 and …
Run Code Online (Sandbox Code Playgroud)

java collections multikey

6
推荐指数
1
解决办法
2万
查看次数

如何迭代MultiKeyMap?

我正在使用提供多键值对的commons-collections中的MultiKeyMap.我有3个键是字符串.我有两个问题,我看不出如何解决.

如何迭代所有多键值对?使用简单的HashMap,我知道它.

其次,如何修复前两个键的所有多键值对?这意味着我想得到这样的东西,multiKey.get("key1","key2",?);其中没有指定第三个键.

java dictionary multikey apache-commons-collection

5
推荐指数
1
解决办法
5668
查看次数

MongoDB如何进行多键排序?

在MongoDB中,字段可以有多个值(值数组).它们中的每一个都被编入索引,因此您可以过滤任何值.但是你也可以"订购"具有多个值的字段,结果是什么?

更新:

> db.test.find().sort({a:1})
{ "_id" : ObjectId("4f27e36b5eaa9ebfda3c1c53"), "a" : [ 0 ] }
{ "_id" : ObjectId("4f27e3845eaa9ebfda3c1c54"), "a" : [ 0, 1 ] }
{ "_id" : ObjectId("4f27df6e5eaa9ebfda3c1c4c"), "a" : [ 1, 1, 1 ] }
{ "_id" : ObjectId("4f27df735eaa9ebfda3c1c4d"), "a" : [ 1, 1, 2 ] }
{ "_id" : ObjectId("4f27df795eaa9ebfda3c1c4e"), "a" : [ 2, 1, 2 ] }
{ "_id" : ObjectId("4f27df7f5eaa9ebfda3c1c4f"), "a" : [ 2, 2, 1 ] }
{ "_id" : ObjectId("4f27df845eaa9ebfda3c1c50"), "a" …
Run Code Online (Sandbox Code Playgroud)

sorting mongodb multikey

4
推荐指数
1
解决办法
1694
查看次数

为什么multiKey索引会阻止MongoDB中的indexOnly查询?

我试图在从MongoDB中的集合中读取数据时仅使用索引,因为我有一些大文档,而对于此查询,我只需要一个字段.

事实证明,如果索引是multiKey索引,我就不能拥有indexOnly = true.

这是我做的测试:

db.test.drop()
db.test.insert({a:1})
db.test.ensureIndex({a:1})
db.test.find({a:1}, {_id:0, a:1}).explain()
Run Code Online (Sandbox Code Playgroud)

- > indexOnly = true,isMultiKey = false

db.test.insert({a : [2,3]})
db.test.find({a:1}, {_id:0, a:1}).explain()
Run Code Online (Sandbox Code Playgroud)

- > indexOnly = false,isMultiKey = true

文件提到的多键索引的一些限制,但不是这一个.有没有人知道如何同时使用multikey和indexonly?

mongodb multikey

4
推荐指数
1
解决办法
534
查看次数

如何使用三个键创建和填充嵌套字典

我有一个独特的双精度对应于三个字符串的变体。我想填充字典或其他东西,以便我可以调用类似的东西dict[key1][key2][key3]并获取值。

我尝试过很多类似的事情

    Dictionary<string, Dictionary<string, double>> dict = new Dictionary<string, Dictionary<string, double>> {
        { "Foo", {"Bar", 1.2 } },
        { "Foo", {"Test", 3.4 } }
    };
Run Code Online (Sandbox Code Playgroud)

这给了我语法错误和错误,例如“错误 4 命名空间不能直接包含字段或方法等成员”

    Dictionary<double, Tuple<string, string>> dict = {
          {1.23, "Blah", "Foo"}
    };
Run Code Online (Sandbox Code Playgroud)

这给了我这样的错误:“错误 1 ​​只能使用数组初始值设定项表达式来分配给数组类型。请尝试使用新的表达式。”

    object dict = new Dictionary<string, Dictionary<string, Dictionary<string, string>>>();

    dict["k1"] = new Dictionary<string, Dictionary<string, string>>();
    dict["k1"]["k2"] = new Dictionary<string, string>();
    dict["k1"]["k2"]["k3"] = 3.5;
Run Code Online (Sandbox Code Playgroud)

这给了我语法错误和错误,例如“错误 2 类、结构或接口成员声明中的无效标记 '“k1”'”

我该怎么办?提前致谢。

![在此输入图像描述][1]

在此输入图像描述

编辑:尝试琼斯的代码:

namespace WindowsFormsApplication1
{
    public partial class …
Run Code Online (Sandbox Code Playgroud)

c# dictionary nested multikey

0
推荐指数
1
解决办法
4066
查看次数