Bidirectional map is associative data structure where keys and values can switch their roles.
Questions tagged [bimap]
85 questions
5
votes
1 answer
Boost Bimap to insert_or_modify
STL map "[]" operator can insert new entries or modify existing entries.
map myMap;
myMap["key1"] = "value1";
myMap["key1"] = "value2";
I am rewriting some code with boost::bimap which was implemented by STL map. Is there an easy…

Stan
- 37,207
- 50
- 124
- 185
5
votes
1 answer
Java: Instantiate Google Collection's HashBiMap
I'm using Eclipse, and I've added google-collect.1.0-rc2.jar as a referenced library. Yet somehow this still doesn't work:
import com.google.common.collect.HashBiMap;
public class Odp {
//...
HashBiMap…

Nick Heiner
- 119,074
- 188
- 476
- 699
4
votes
1 answer
Anything available implemented like Loki's AssocVector but with the functionality of Boost's Bimap?
I wonder if anyone is aware of any library code that has the performance characteristics provided by Loki's AssocVector (Locality of reference of the elements, lower per-element memory overhead compared to a map) but with Boost's BiMap functionality…

JPC
- 41
- 2
4
votes
1 answer
Tagged boost::bimap in templates - do they work?
I am embedding a boost::bimap in a templated class, and after much trial-and-error I have discovered something that compiles and something that does not. I am using g++ (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6) and Boost 1.55. I will give the full code…

Geir
- 163
- 3
4
votes
1 answer
BiMap capabilities of a Guava Cache?
I have a simple mapping table in a database that associates integer keys with certain values. Once I stick the values in the table, they never go away. I'd like to use a Guava Cache so that these keys can be looked up once and then stay stored in…

Garret Wilson
- 18,219
- 30
- 144
- 272
4
votes
1 answer
Is it safe to mutate values in a HashBiMap?
In my code I'd like to have a
HashBiMap> bimap;
Is it OK to mutate values in a bimap? When I use bimap.inverse(), won't it lead to the same hashCode()-related issues it leads with a HashMap containing mutable keys?

gvlasov
- 18,638
- 21
- 74
- 110
4
votes
2 answers
key-value data structure to search key in O(1) and get Max value in O(1)
I need to implement a key-value data structure that search for a unique key in O(lgn) or O(1) AND get max value in O(1). I am thinking about
boost::bimap< unordered_set_of ,multiset_of >
Note that there is no duplicated key in my…

ARH
- 1,355
- 3
- 18
- 32
4
votes
1 answer
Copying/Inserting a std::map into a boost::bimap
I tried copying the elements of a std::map into a boost::bimap. I cannot get std::copy to work (the boost documentation seems to indicate that bimap should be compatible with std::copy).
I tried the following:
std::map…

BlueTrin
- 9,610
- 12
- 49
- 78
4
votes
1 answer
Cpp - Check if key exist in boost bimap
I have a bimap. I want to check if key exists in my bimap. How can i do that. Here is my bimap:
namespace bimap
{
struct Name{};
struct ID{};
typedef
…

Seçkin Durgay
- 2,758
- 4
- 27
- 36
3
votes
1 answer
What is the best Guava (Google) collection API to represent direct or inverse relationship between two or multiple factors?
BiMap do have inverse method but I am not sure it is a right collection to use for the problem. Can someone please suggest alternative approach or collection/method? An example would be helpful.
Thanks in advance.
Prakash

Prakash Gautam
- 502
- 4
- 13
3
votes
2 answers
STL Type for mapping one-to-one relations?
when thinking about design decisions of my code regarding one-to-one relations I came to think about if I should use std::vector> instead of std::map, and implement two methods A to B and B to A myself.
I can't use boost,…

user3520616
- 60
- 3
- 17
3
votes
2 answers
C++ data structure to store multiple relationships between two unique sets of elements
I am working on a project where I have two unique sets of elements. Any of the elements in one set may be related to any of the elements in the other set.
Example:
Set 1: {A, B, C}
Set 2: {1, 2, 3, 4}
Allowed relationships:
(A, 1) (A, 3)
(B, 1)…

npp1993
- 330
- 4
- 20
3
votes
2 answers
Does the "no primitives in container" rule apply to arrays?
I have recently been trying to implement a simple genetic algorithm. I need to use an inversible map which stores pairs of (Character,4 bits). I chose Guava's BiMap for this task. However tests will not pass because of an int array which I chose for…

don_pablito
- 382
- 1
- 9
3
votes
1 answer
how to find whether a substring in file is already present in hashmap?
I have a hashMap(guava bimap) in which keys and values both are strings, I wanted to write a program which parses the given file and replaces all the strings in the file which are also in BiMap with corresponding values from Bimap.
for example: i…

Manjunath Bhat
- 31
- 3
3
votes
2 answers
Is there a BiMap implementation with predictable iteration ordering (insertion order)?
The standard library LinkedHashSet is a HashSet that provides insertion-order iteration. Is there a version of Guava's BiMap that maintains insertion-order iteration on keys and values? I do need the BiMap to be mutable, so ImmutableBiMap is not…

Jake Cobb
- 1,811
- 14
- 27