hashmap

Using a java object in jsp

<c:set var="nameLookup" value="${names}" /> <c:forEach var="result" items="${results}"> <tr> <td>${result.uglyDisplayName}</td> <td>${result.phonenum}</td> </tr> </c:forEach> This is an excerpt from a jsp I'm trying to edit. Results is a List<Object> being returned in the ModelAndView from the controller, of which ...

PHP - Hashed array, insert at Index?

Hi, i wrote an array wrapper class PersonArray which can contain objects of a certain type (Person). Every person has a unique getHash() function which returns the ID + Name as a unique identifier. This allows for speedy retrieval of the Person from the PersonArray. The PersonArray actually holds two internal Arrays. One for the storage...

Fast, scalable hash lookup database? (Berkeley'ish)

I use and love Berkeley but it seems to bog down once you get near a million or so entries, especially on the inserts. I've tried memcachedb which works but it's not being maintained so I'm worried of using it in production. Does anyone have any other similar solutions, basically I want to be able to do key lookups on a large(possibly ...

Best way to create a hashmap of arraylist

I have one million rows of data in .txt format. the format is very simple. For each row: user1,value1 user2,value2 user3,value3 user1,value4 ... You know what I mean. For each user, it could appear many times, or appear only once (you never know). I need to find out all the values for each user. Because user may appear randomly, I u...

Java Collections Implimentations (e.g. HashMaps vs HashSet vs HashTable ...), what is the cost of choosing the wrong one?

In my code I default to using ArrayList for all Lists, HashMap for all maps, HashSet for all sets. From a practical standpoint how much am I losing in flexibility, scalability, readability and performance by choosing the wrong implementation? When does it make sense to spend time to decide to use one rather than another? I certainly se...

Is a Java hashmap really O(1)?

I've seen some interesting claims on SO re Java hashmaps and their O(1) lookup time. Can someone explain why this is so? Unless these hashmaps are vastly different from any of the hashing algorithms I was bought up on, there must always exist a dataset that contains collisions. In which case, the lookup would be O(n), not O(1). Can so...

Fast C++ container like the C# HashSet<T> and Dictionary<K,V>?

I've used HashSet and Dictionary a lot in C#, and found them very fast... I've tried using std::map and std::hash_map and am finding them very slow in comparision. Does this sound like expected behaviour? Is there something I might be doing wrong in my use of std::hash_map? Or, is there a better C++ Hash container out there? I'm has...

Using a byte array as HashMap key (Java)

See topic - do you see any problem with this? I could also do new String(byte[]) and hash by String but it is more straightforward to use byte[] ...

Java: iterate through HashMap

What is the best way to iterate through a HashMap? ...

Why does ExecutorService deadlock when performing HashMap operations?

When running the following class the ExecutionService will often deadlock. import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class ExecutorTest { p...

how to convert a python dict object to a java equivalent object?

I need to convert a python code into an equivalent java code. Python makes life very easy for the developers by providing lots of shortcut functionalities. But now I need to migrate the same to Java. I was wondering what will the equivalent of dict objects in java? I have tried using HashMap but life is hell. For starters consider this, ...

Efficient hashCode() implementation

I often auto-generate an class's hashCode() method using IntelliJ IDEA and typically the method takes the form: result = 31 * result + ... My question is what is the purpose of multiplying by 31? I know this is a prime number but why pick 31 specifically? Also, if implementing a hashCode() for a particularly small / large dataset wo...

Java: how to convert HashMap<String, Object> to array

Hi, I need to convert a HashMap<String, Object> to an array; could anyone show me how it's done? ...

Java HashMap get works but containsKey does not

Hi, I am trying to locate a key in a HashMap. I can print the selected key by using 'get' but when I use 'containsKey' in an if statement, it is not found. I KNOW the key is present in the Map but it keeps returning false. Any ideas people? My code: public static boolean checkLowerStructuralSupport(Location location) { boolean hasS...

Remove Elements from a HashSet while Iterating

So, if I try to remove elements from a Java HashSet while iterating, I get a ConcurrentModificationException. What is the best way to remove a subset of the elements from a HashSet as in the following example? Set<Integer> set = new HashSet<Integer>(); for(int i = 0; i < 10; i++) set.add(i); // Throws ConcurrentModificationExcept...

On using Enum based Singleton to cache large objects (Java)

Is there any better way to cache up some very large objects, that can only be created once, and therefore need to be cached ? Currently, I have the following: public enum LargeObjectCache { INSTANCE; private Map<String, LargeObject> map = new HashMap<...>(); public LargeObject get(String s) { if (!map.contains...

trouble deleting keys/values on STL hash_map when duplicate keys

I am using C++ hash_map to store some C-style string pairs. And all keys should be unique for this case... My problem is a serious memory leak when stress testing this over mutliple runs. When none of these keys in the test are not identical, there is no memory leak. But with identical keys its a different story... The hash_map (this...

Differences between .Net Hashtable, Java Hashtable & HashMap

Am I correct in saying that a .Net Hashtable is not synchronized while a Java Hashtable is? And at the same time a Java HashMap is not synchronized and has better performance? I am rewriting a Java app that makes heavy use of HashMaps in C# and I would like to use a HashTable and ensure that the performance is basically equivalent. ...

Efficient Hashmap Use

What is the more efficient approach for using hashmaps? A) Use multiple smaller hashmaps, or B) store all objects in one giant hashmap? (Assume that the hashing algorithm for the keys is fairly efficient, resulting in few collisions) CLARIFICATION: Option B implies segregation by primary key -- i.e. no additional lookup is necess...

Source code for hashmap implementation?

I’d like to study the source code for a fast and memory efficient hashmap implementation. Any suggestions where I can find one online? ...