Bidirectional map is associative data structure where keys and values can switch their roles.
Questions tagged [bimap]
85 questions
83
votes
6 answers
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 a user-friendly interface:
template class Bimap
{
std::map map1;
…

Vittorio Romeo
- 90,666
- 33
- 258
- 416
40
votes
6 answers
How to reverse a Map in Kotlin?
I am trying to reverse a Map in Kotlin. So far, I have come up with:
mapOf("foo" to 42)
.toList()
.map { (k, v) -> v to k }
.toMap()
Is there any better way of doing this without using a middleman(middlelist)?

Grzegorz Piwowarek
- 13,172
- 8
- 62
- 93
33
votes
2 answers
Is there a Boost.Bimap alternative in c++11?
Is there a usable alternative to Boost's bimap in C++0x?
I would like to avoid Boost, but fully embrace C++11. If necessary, a slimmed down version of Boost's bimap would work for me (I need a constant bimap to switch between enums and corresponding…

rubenvb
- 74,642
- 33
- 187
- 332
20
votes
2 answers
Boost::Bimap equivalent of bidirectional multimap
First part of the question is that I am trying to use boost::bimap, but from the documentation it is unclear to me how to define a bidirectional multimap.
The second part of the question is that I need it to be a map in one direction and a multimap…

BlueTrin
- 9,610
- 12
- 49
- 78
18
votes
5 answers
BiMap / 2-way hashmap in Kotlin
is there a bidirectional hashmap for kotlin?
If not - what is the best way to express this in kotlin?
Including guava to get the BiMap from there feels like shooting with a very big gun on a very little target - no solution that I can imagine…

ligi
- 39,001
- 44
- 144
- 244
16
votes
3 answers
To instantiate BiMap Of google-collections in Java
How can you instantiate a Bimap of Google-collections?
I've read the question Java: Instantiate Google Collection's HashBiMap
A sample of my code
import com.google.common.collect.BiMap;
public class UserSettings {
private Map…

Léo Léopold Hertz 준영
- 134,464
- 179
- 445
- 697
8
votes
2 answers
Variadic typedefs, or "Bimaps done the C++0x way"
Short question: Can I typedef a variadic argument pack? I need template struct Forward { typedef T... args; };.
Long version:
I was thinking about reimplementing the excellent boost bimap in C++0x. Recall that a bimap of two types S…

Kerrek SB
- 464,522
- 92
- 875
- 1,084
8
votes
1 answer
Replace vector and hash table with Boost.Bimap
I'm looking to replace a vector and a boost::unordered_map mapping string to indices in the former with a boost::bimap.
What instantiation of bimap should I use? So far, I've come up with
typedef bimap<
…

Fred Foo
- 355,277
- 75
- 744
- 836
8
votes
1 answer
Do we have a MultiBiMap?
As we know, there is the concept of BiMap and MultiMap but is there a MultiBiMap ? so what do I mean by this.
In MultiMap you have one-to-many relationship between K and V, a single key can be associated to multiple value, hence the name.
In BiMap…

AR5HAM
- 1,220
- 11
- 19
8
votes
5 answers
Guava: java.lang.NoClassDefFoundError - com.google.common.collect.HashBiMap
I currently face the problem of java.lang.NoClassDefFoundError: com.google.common.collect.HashBiMap when using guava libraries downloaded from here:
http://code.google.com/p/guava-libraries/
I already add guava-12.0.jar into my project as a…

Eric
- 357
- 1
- 4
- 14
7
votes
1 answer
Bidirectional HashMap in Racket
Does Racket have a bidirectional hashmap?
That is, a hash map that can in constant time, be given a key and look up the value, or given the value and look up the key? I would be happy for an API that looks something like this:
#lang racket
(define…

Leif Andersen
- 21,580
- 20
- 67
- 100
7
votes
1 answer
Use of Boost Bimap in C++
C++ Boost has Bimap container that is a bidirectional map:
http://www.boost.org/doc/libs/1_43_0/libs/bimap/doc/html/index.html
Does anyone know the performance of Boost::bimap? I mean what's the time complexity of accessing an element in the map? Is…

user414585
- 715
- 2
- 8
- 14
6
votes
1 answer
bimap implementation in modern C++ without Boost
This question has been asked before here I admit, but it's now 4 years ago so I dare to ask for an update:
I need a way to add a tuple/pair to a container and search for both - the left and the right element efficiently.
Boost has bimap and…

frans
- 8,868
- 11
- 58
- 132
6
votes
1 answer
boost::bimap for enum
I'm trying to create a simple bi-directional lookup facility for enums in C++. I have one-way lookup working fine...
enum MyEnum
{
One,
Two,
Three
};
const boost::unordered_map MyEnumMap = map_list_of
(One,…

salimoneus
- 95
- 6
5
votes
1 answer
Use a custom allocator with boost::bimap
I am working on improving the performance of a program which uses both the Boost Graph Library and boost::bimap. Profiling revealed that most of the time was being spent in memory allocation and deallocation. Making the adjacency_list class of the…

Ryan Gabbard
- 2,269
- 2
- 24
- 37