问题标签 [bimap]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
119 浏览

c++ - c ++ boost插入失败

我已经定义了 boost::bimap-

每次我检查我是否已经在 bimap 中有值 -

如果不是,我将使用命令插入它-

我有时在哈希中找不到字符串,尽管它确实存在,在其他情况下我已经找到了完全相同的字符串。然后,当我尝试再次将值插入到 bimap 时,我看到 bi-map 中的值的数量没有改变。

你知道我在哈希中找不到字符串的原因是什么吗?

谢谢。

0 投票
1 回答
1169 浏览

c++ - 使用用户定义的比较器提升 bimap set_of

我计划将我自己的比较功能与 boost bimap 一起使用。我要解决的问题是,当我将 boost bimap 与指针一起使用时,比较不应该比较两个指针,而应该比较指针指向的类。

我尝试了以下代码。但它甚至没有编译。我究竟做错了什么?还有一种更简单的方法来实现比较两个对象而不是两个指针的更少功能)

错误信息:

party1.cpp:104:64:错误:“模板结构 boost::bimaps::set_of”的模板参数列表中参数 2 的类型/值不匹配 party1.cpp:104:64:错误:预期类型,得到“comp_pointer” 'party1.cpp:104:70: 错误:模板参数 1 无效 party1.cpp:104:85: 错误:';'之前的声明类型无效 令牌

0 投票
1 回答
424 浏览

java - 在 HashBiMap 中改变值是否安全?

在我的代码中,我想要一个

可以改变 bimap 中的值吗?当我使用时,它不会导致与包含可变键的 HashMapbimap.inverse()相同的相关问题吗?hashCode()

0 投票
1 回答
463 浏览

c++ - Warnings when creating boost.bimap inside a template class (C++)

I am trying to create a template class with a boost.bimap as a member. However, when following the usual typedef protocols, my compiler (I'm using Visual Studio Express 2012) produces a whole ream of C4512 (assignment operator could not be generated) warnings. Strangely enough, the code will compile, and if I fully implement the class, things work correctly. I'd prefer to know the cause of the warning though, and how to avoid it, if possible. If anyone had any ideas, I'd be very grateful!

The bimap code, outside of a template, doesn't cause any warnings to appear.

0 投票
1 回答
3851 浏览

java - 我们有 MultiBiMap 吗?

就像我们现在一样,有 BiMap 和 multiMap 的概念,但是有 multiBiMap 吗?所以我的意思是什么。在 multiMap 中,K 和 V 之间存在一对多关系,单个键可以关联到多个值,因此得名。在双地图中,您有 K,V 对,这是双向的,这意味着您也可以获得 V,K 关系。就像有两个常规地图但同步。我需要一个双向多图,您可以在其中结合这两个概念。

0 投票
1 回答
548 浏览

c++ - 将 unordered_set_of 与 Boost.Bimap 一起使用时出错

我正在尝试遵循文档中的这个示例(请参阅 typedef for word_counter)。

抛出的错误是

test.cpp:11:1:错误:模板参数的数量错误(1,应该是 5)在 /usr/include/boost/bimap.hpp:13:0 包含的文件中,来自 test.cpp:3:/usr /include/boost/bimap/bimap.hpp:133:7:错误:为“模板类 boost::bimaps::bimap”提供 test.cpp:11:10:错误:“;”之前的声明类型无效 令牌

0 投票
2 回答
83 浏览

java - BiMap 单个函数将值转换为连接字符串值?

是否有等效于从位图中获取所有键(或逆)并将每个键与特殊字符连接为全新字符串的方法(无需遍历映射并手动构建它?

然后 concateKeys 的值 = "S1|S2|S3"

0 投票
6 回答
41772 浏览

c++ - Is there a more efficient implementation for a bidirectional map?

I created a simple bidirectional map class that works by internally storing two std::map instances, with opposite key/value types, and providing an user-friendly interface:

  • Is there a more efficient method of implementing a bidirectional map that doesn't require twice the memory?

  • How is a bimap usually implemented?


EDIT:

  • Should bimap element be mutable or immutable? (Changing one element in map1 should change the key in map2, but keys are const and that's impossible - what's the solution?)

  • Ownership of elements is also another problem: when an user inserts a key-value pair in the bimap, the bimap should make a copy of that key-value pair and store it, then the internal second map (with inverted key/value) should not copy but point to the original pair. How can this be achieved?


EDIT 2:

I've posted a possible implementation I made on Code Review.

0 投票
1 回答
246 浏览

c++ - Boost Bimap 在调试构建中占用太多内存

我正在使用相当多的表格容器

我在包含在相当多的 cpp 文件中的头文件中定义它们(这是在我尽可能限制头文件的公开之后)。在调试版本中创建的 .a 文件运行到 1 GB 以上(由于“设备上没有空间”错误导致编译中途停止,并且编译时间自然呈指数增长。

使用的编译器是 gcc 4.8.1。只是想知道是否有人遇到过 boost::bimap 的问题以及他们为解决此问题所做的工作

0 投票
1 回答
2028 浏览

c++ - 将 Bimap 提升为 insert_or_modify

STL 映射“[]”运算符可以插入新条目或修改现有条目。

我正在用 STL map 实现的 boost::bimap 重写一些代码。有没有一种简单的方法来保持 STL“[]”行为?我发现我必须写下 7 行代码来替换原始的 STL 映射代码(1 行!)。

我想知道是否有像 boost::bimap::insert_or_modify() 这样的实用函数。