unordered-map

I don't understand std::tr1::unordered_map

I need an associative container that makes me index a certain object through a string, but that also keeps the order of insertion, so I can look for a specific object by its name or just iterate on it and retrieve objects in the same order I inserted them. I think this hybrid of linked list and hash map should do the job, but before I t...

Specify the minimum number of buckets when constructing a boost::unordered_map

I am trying to use boost::unordered_map to cache some values. I try to specify minimum number of buckets in the constructor: #include <boost/unordered_map.hpp> typedef boost::unordered_map<float, float> Mycache; Mycache cache((std::size_t)25165843, boost::hash<float>(), std::equal_to<float>(), s...

How to check for TR1 while compiling?

Dear all: We are programming a logging library that keeps itself in a .hpp file. We would like to include <tr1/unordered_map> (if the compiler supports TR1,) or the standard <map> otherwise. Is there a standard way of checking at compile time if tr1 is available or not? I was thinking that the same way that the "__cplusplus" define sym...

Hash function for a pair of long long?

I need to map a pair of long long to a double, but I'm not sure what hash function to use. Each pair may consist of any two numbers, although in practice they will usually be numbers between 0 and about 100 (but again, that's not guaranteed). Here is the tr1::unordered_map documentation. I started like this: typedef long long Int; type...

Handling Deprecated Includes With Autoconf

I have been using ext::hash_map in a C++ project and notice that in g++ 4.3 it is deprecated in favor of unordered_map. I need to maintain compatibility with old systems that do not have unordered_map available. It occurs to me that this is just the sort of thing that could be handled by autoconf, which I am already using. I have been...

Whats the syntax to use boost::pool_allocator with boost::unordered_map?

I'm just experimenting with boost::pool to see if its a faster allocator for stuff I am working with, but I can't figure out how to use it with boost::unordered_map: Here is a code snippet: unordered_map<int,int,boost::hash<int>, fast_pool_allocator<int>> theMap; theMap[1] = 2; Here is the compile error I get: Error 3 error C2064...

Boost.Intrusive and unordered_map

I am looking to use an intrusive unordered_map. For some reason there is only an unordered_set in the library. There is also an intrusive hashtable but I'm not sure it has the same functunality, also it doesn't have the same interface. Am I wrong and I missed the unordered_map link? If I am not is there a tutorial that will help me imple...

Difference between hash_map and unordered_map?

I recently discovered that the implementation of the hash map in c++ will be called unordered_map. When I looked up why they weren't just using hash_map, I discovered that apparently there are compatiblity issues with the implementation of hash_map that unordered_map resolves(http://en.wikipedia.org/wiki/Unordered_map_%28C%2B%2B%29). The...

Basic questions: Pointers to objects in unordered_maps (C++)

I'm new to C++ programming and would greatly appreciate replies that don't assume much prior knowledge. Thanks to suggestions here, I've created an unordered map: typedef std::tr1::unordered_map<std::string, Strain*> hmap; The data in this map are pointers to instances of class Strain. As soon as these instances are created, I create...

"error: assignment of read-only location" in unordered_map (C++)

I have an awkward hash table (specifically, an unordered_map) with int keys and vector< vector< int >> data. I periodically need to update elements in this two-dimensional vector of ints. There's no intrinsic reason I shouldn't be able to, right? A newer g++ compiler I've switched to complains of an assignment of read-only location on th...

How can I use a custom type for keys in a boost::unordered_map?

I'm using Boost's implementation of a hash map in a project right now, and I'm trying to implement a custom type for keys. I have four unsigned integers which I'd like to combine into a single 128-bit datatype to use as a key. I've created a struct with a 32-bit integer array of four elements, which serves as my storage. To be honest, I...

g++ linker error: Getting undefined reference error for std::hash

Hi, I'm using the unordered_map of TR1 implementation in my code and the linker gives weird errors I cannot even decipher: BPCFG.o: In function `std::__detail::_Hash_code_base<DottedRule, std::pair<DottedRule const, int>, std::_Select1st<std::pair<DottedRule const, int> >, eqDottedRule, std::hash<DottedRule>, std::__detail::_Mod_rang...

a C++ hash map that preserves the order of insertion

I have the following code: #include <iostream> #include "boost/unordered_map.hpp" using namespace std; using namespace boost; int main() { typedef unordered_map<int, int> Map; typedef Map::const_iterator It; Map m; m[11] = 0; m[0] = 1; m[21] = 2; for (It it (m.begin()); it!=m.end(); ++it) cout << i...

C++ unordered_map problem

This time I'm able to show a complete code: #include <unordered_map> #include <iostream> #include <stdlib.h> using namespace std; bool mystrcmp(const char *s1, const char *s2) { int i = 0; do { if(s1[i] != s2[i]) return false; } while(s1[i++] != '\0'); return true...

Defining custom hash function and equality function for unordered_map

I am trying to define a type of unordered_map that has a custom hash function and equality comparison function. The function prototypes of these functions are as follows: //set<Vertex3DXT*> is the type of the key; Cell3DXT* is the type of the value size_t VertexSetHashFunction(set<Vertex3DXT*> vertexSet); //hash function bool SetEqual(s...

Is there any advantage of using map over unordered_map in case of trivial keys?

A recent talk about unordered_map in C++ made me realize, that I should use unordered_map for most cases where I used map before, because of the efficiency of lookup ( amortized O(1) vs. O(log n) ). Most times I use a map I use either int's or std::strings as keys, hence I've got no problems with the definition of the hash function. The ...

Is it worth using std::tr1 in production?

I'm using MS VC 2008 and for some projects Intel C++ compiler 11.0. Is it worth using tr1 features in production? Will they stay in new standard? For example, now I use stdext::hash_map. TR1 defines std::tr1::unordered_map. But in MS implementation unordered_map is just theirs stdext::hash_map, templatized in another way. ...

Efficiency of iterators in unordered_map (C++)

I can't seem to find any information on this, so I turn to stackoverflow. How efficient are the iterators of std::tr1::unordered_map in C++? Especially compared to, say, list iterators. Would it make sense to make a wrapper class that also holds all the keys in a list to allow for efficient iteration (my code does use a lot of iterati...

Is there any thing hashmap can do but map cannot?

Hi, I only know that the difference between hashmap and map is that hashmap is implemented with hash function but map is implemented with tree. Could any body add anything more? Based on this, is there any thing hashmap can do but map cannot? ...

[C++] Index strings by other strings

Hello, I need to index specific strings with other strings and I can't really find a good way to do so. I tried to use tr1::unordered_map, but I'm having some difficulties using it. If someone could tell me what is the best way to do that I'd be really grateful :) I also need to index objects by a number (numbers are not in order so I ca...