As made clear in update 3 on this answer, this notation:
var hash = {};
hash[X]
does not actually hash the object X; it actually just converts X to a string (via .toString() if it's an object, or some other built-in conversions for various primitive types) and then looks that string up, without hashing it, in "hash". Object equality i...
What values should I pass to create an efficient HashMap / HashMap based structures for N items?
In an ArrayList, the efficient number is N (N already assumes future grow). What should be the parameters for a HashMap? ((int)(N * 0.75d), 0.75d)? more? less? What is the effect of changing the load factor?
...
I'm using Java HashMap in MATLAB
h = java.util.HashMap;
And while strings, arrays and matrices works seemlessly with it
h.put(5, 'test');
h.put(7, magic(4));
Structs do not
h=java.util.HashMap;
st.val = 7;
h.put(7, st);
??? No method 'put' with matching signature found for class 'java.util.HashMap'.
What would be the easiest...
I am attempting to troubleshoot an intermittent failure that appears to be related to removing an object from a HashMap and then putting that same object back using a new key. My HashMap is created as follows:
transactions = new HashMap<Short, TransactionBase>();
The code that does the re-assignment is as follows:
transactions.remov...
I am trying to compile the following code:
private String dataToString(){
Map data = (HashMap<MyClass.Key, String>) getData();
String toString = "";
for( MyClass.Key key: data.keySet() ){
toString += key.toString() + ": " + data.get( key );
return toString;
}
I get an error in the for line that says:
incompati...
Currently, I create a HashMap with Object Id as key and 1 as value. And the method asks for Object/Id and checks if there is a matching key.
Is that ok? Or, is(are) there better alternative(s)?
...
So I need a 2-dimensional ConcurrentHashMap.
It has to be as blazing fast as possible, as I'm going to be adding to and updating its values extremely frequently. It's in a multithreaded application, hence the choice to use ConcurrentHashMap instead of just HashMap.
Both the "x" and "y" indices are integers with a known range (0 throug...
I have a HashMap with millions of entries.
Need to retrieve all entries whose keys match a specific set of criteria (in this case, each key is an object with two integer properties; I need to retrieve all keys where each of these integers fall within a specified range).
What is the fastest, most efficient way to iterate through all suc...
My application is related to the stock market. I have a feed that is consistently updating an object called Price. Price has a HashMap that stores the security code (String) and price (Double). Every time a new price comes in this object is updated.
The application is supposed to scan the prices for large moves. I have a separate class ...
Hello,
I have faced a quite strange thing related to stdext hashmap. I have to work with a lot of objects and it is a priority to access the elements in a fast way.
My program read the object values from a file and if it's a new element, then insert this value in a hashmap, if it is an already processed object, then changes the stored ...
I am persisting objects using JPA. The Main object has an owning One-Many relationship with another object. The other object is stored in a HashMap. What sort of synchronization would fix this problem? It seems to happen at completely random times and is very unpredictable. Here is the exception I get:
Exception in thread "pool-1-t...
My problem is actually more nuanced than the question suggests, but wanted to keep the header brief.
I have a HashMap<String, File> of File objects as values. The keys are String name fields which are part of the File instances. I need to iterate over the values in the HashMap and return them as a single String.
This is what I have cu...
Hello,
I'm extensively using hash map data structures in my program. I'm using a hash map implementation by Barry Kelly posted on the Codegear forums. That implementation internally uses RTL's CompareText function. Profiling made me realize that A LOT of time is spent in SysUtils CompareText function.
I had a look at the
Fastcode site...
In the following example, how can I save the value of role to the role with id=1 without loading it? I have tried:
Map user = new HashMap();
user.put("address","Address test");
user.put("role",1);
session.save("User",user);
But that results in:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.util.Map
at o...
I need to create an empty map if the map its null.
if (fileParameters == null)
fileParameters = (HashMap<String, String>) Collections.EMPTY_MAP;
The problem is that I get a code warning:
Type safety: Unchecked cast from Map to HashMap
what its the best way to create this emptyMap.
...
I kinda need to decide on this to see if I can achieve it in a couple of hours before the deadline for my school project is due but I don't understand much about data structures and I need suggestions...
There's 2 things I need to do, they will probably use different data structures.
I need a data structure to hold profile records. Th...
I want to have a List or Array of some sort, storing this information about each country:
2 letter code
Country name such as Brazil
Continent/region of the world such as Eastern Europe, North America, etc.
I will classify each country into the region/continent manually (but if there exists a way to do this automatically, do let me k...
When I compile a c++ application I'm writing that makes use of hash_map, I get this warning on g++ 4.3.2:
You are using the deprecated header . To eliminate this warning, use an ANSI-standard header file or use hte -Wno-deprecated compiler flag.
9> #include <ext/hash_map>
What include replaces this? I've searched for a while on goog...
The following code is giving me a NullPointerException. The problem is on the following line:
...
dataMap.put(nextLine[0], nextLine[6]);
What is strange is that I have run this code without the above line and the call to nextLine[0] and nextLine[6] work exactly as expected - that is they give me back elements of a csv file. I declar...
Hi,
I've declared the following hashmap:
HashMap<Integer, Hive> hives
Where Hive is an object.
If I call "hives.get(2)" will it return a copy of the object Hive at that location or a reference to it?
My goal is to modify the Hive object at that location. If it returns the reference, I can just modify the returned hive and be don...