hashmap

C++ concurrent associative containers?

I'm looking for a associative container of some sort that provides safe concurrent read & write access provided you're never simultaneously reading and writing the same element. Basically I have this setup: Thread 1: Create A, Write A to container, Send A over the network. Thread 2: Receive response to A, Read A from container, do som...

Using struct as key in hashmap. How to insert values ?

The code fail at compilation line map_free_segments [ loc ] = color; The first line for the errors is : error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const localization' The complete source : ...

What exactly is a hash in regards to JSON?

I am learning JSON, but I found out that you can put what are called "hashes" into JSON as well? Where can I find out what a hash is? Or could you explain to me what a hash is? Also, what's a hashmap? I have experience in C++ and C#, and I am learning JS, Jquery, and JSON. ...

Setting Hashmap in a loop

I have the following code: Map<String, ObjectType> objectMap = new HashMap<String, ObjectType>(); for (ObjectType obj : objects) { obj.setSomeProperty("property value"); objectMap.put(obj.getADiffProperty(), obj); } It seems like during loop iteration some of the obj property changes for different keys than the one currently b...

Is ActionScript 3 Dictionary a hashmap?

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/ The dictionary does what I need but I do need to care about performance. Does anybody know if the Dictionary is implemented as hashmap? ...

How to check whether my custom hashing is good in hash_map?

I've written a custom hashing for my custom key in stdext::hash_map and would like to check whether the hasher is good. I'm using STL supplied with VS 2008. A typical check, as I know, is to check the uniformity of distribution among buckets. How should I organize such a check correctly? A solution that comes to my mind is to modify ST...

How to decide the hashcode value for storing words of a dictionary?

I am preparing for my interview and came across this question: Consider that i have 1000,000 words and i want to create a dictionary . The data structure i can use is Map or B+ trees . But on what criteria should i write my hashcode(), so that the retrieval can be fast. would welcome everybody views... ...

Recommended low memory hashmap for implementation for Java

I am currently working on a programming related problem where I am attempted to make a massive hashmap of data. The key for the data is a custom low-memory implementation of a CharSequence that implements hashCode() and equals(...) and the value is am Integer object. There may be millions of entries in this hashtable and I managed to d...

difference between hashmap and array list in java?

In java, ArrayList and HashMap are using in collections. But i couldn't understand at which situations we should use ArrayList and which time use HashMap. What is the major difference between both of them? ...

How to Create Own HashMap in Java?

I know about hashing algorithm and hashCode() to convert "key" into an equivalent integer (using some mathematically random expression) that is then compressed and stored into buckets. But can someone point me to an implementation or at least data structure that should be used as baseline? I haven't found it anywhere on the web. ...

Are final static variables thread safe in Java?

I've read around quite a bit but haven't found a definitive answer. I have a class that looks like this: public class Foo() { private static final HashMap<String, HashMap> sharedData; private final HashMap myRefOfInnerHashMap; static { // time-consuming initialization of sharedData f...

Is it possible in C++ to inherit operator() ?

I'm writing some examples of hash functions for hash_map. If I use a hash_map defined by my compiler, I need to define Comparer in Hasher. I know that it's better to use tr1::unordered_map but in my application it's important to set minimum number of buckets rather big and define mean bucket_size - a condition to grow. So I would like t...

When to trash hashmap contents to avoid performance degradation?

Hello, I'm woking on Java with a large (millions) hashmap that is actually built with a capacity of 10.000.000 and a load factor of .75 and it's used to cache some values since cached values become useless with time (not accessed anymore) but I can't remove useless ones while on the way I would like to entirely empty the cache when its ...

Data Structure Behind Amazon S3s Keys (Filtering Data Structure)

I'd like to implement a data structure similar to the lookup functionality of Amazon S3. For those of you who don't know what I'm taking about, Amazon S3 stores all files at the root, but allows you to look up groups of files by common prefixes in their names, therefore replicating the power of a directory tree without the complexity of...

Java, HashMaps and using Strings as the keys - does the string value get stored twice?

If I have a HashMap that looks like this: HashMap<String, MyObject> where the String key is a field in MyObject, does this string value get stored twice? So when I add entries: _myMap.put(myObj.getName(), myObj); Am I using double the String size in terms of memory? Or does Java do something clever behind the scenes? Thanks ...

Efficient way to get the most used keys in a HashMap - Java

Hi! I have a HashMap where the key is a word and the value is a number of occurrences of that string in a text. Now I'd like to reduce this HashMap to only 15 most used words (with greatest numbers of occurrences). Do you have any idea to do this efficiently? ...

Java Generics Type Safety warning with recursive Hashmap

Hi, I'm using a recursive tree of hashmaps, specifically Hashmap map where Object is a reference to another Hashmap and so on. This will be passed around a recursive algorithm: foo(String filename, Hashmap<String, Object> map) { //some stuff here for (Entry<String, Object> entry : map.entrySet()) { //type warning th...

Fill a rails form with a hashmap

Hey, I have a difficult situation. I let the the user create a form through a Rich Text Editor and then I save this. So for example, I save this literally into my DB: http://pastebin.com/DNdeetJp (how can you post HTML here? It gets interpreted, so now I use pastebin...) On another page I wrap this in a form_tag and it gets presented as ...

Why does this code sometimes throw a NullPointerException?

Consider the following Java source: if( agents != null ) { for( Iterator iter = agents.keySet().iterator(); iter.hasNext(); ) { // Code that uses iter.next() ... // } } The agents is a HashMap. Why does the for statement sometimes throw a NullPointerException? Thank you. ...

Hash Table v/s STL map in C++

Hi, I am trying to learn C++ maps. Was just wondering about the implementation of STL map. I read it employs Binary search tree. Is there a implementation of hash table in STL? How exactly do STL map stores Key Value pairs? ...