hashmap

Casting a Object to HashMap

Hello there, I'm having trouble working out how to count instances of Values in a HashMap. I have seen that there is methods attached to the Object class that look as if they are able to help me, so I've tried to cast those in to work but I must be doing something wrong somewhere. If there's an easier way, I haven't found it yet. NB: L...

Java generics Pair<String, String> stored in HashMap not retrieving key->value properly

Here's Pair.java import java.lang.*; import java.util.*; public class Pair<TYPEA, TYPEB> implements Comparable< Pair<TYPEA, TYPEB> > { protected final TYPEA Key_; protected final TYPEB Value_; public Pair(TYPEA key, TYPEB value) { Key_ = key; Value_ = value; } public TYPEA getKey() { return Key_; } public...

how to sort hash map

how we will be able to sort a hashmap i want so sort in the basis of a value in array list... thanx in advance.............. ...

Java HashMap indexed on 2 keys

I want to create a HashMap in java for users with preferences. This would be easy to do in a database, but unfortunately I can't use a database. What I need is a way to find a user by name in the HashMap, and to find all the users with a certain interest (e.g. golf). If I delete a user, then all their interests should be deleted. Anyon...

Run time to insert n elements into an empty hash table

People say it takes amortized O(1) to put into a hash table. Therefore, putting n elements must be O(n). That's not true for large n, however, since as an answerer said, "All you need to satisfy expected amortized O(1) is to expand the table and rehash everything with a new random hash function any time there is a collision." So: what ...

three item HashMap without internal iteration

What is the best way to implement a three item hashMap? For example, I would like to use a regular String key , but have it map to two different objects. The idea is like having a list of lists, except that the first item is a key. I am trying to avoid iterating through the list ( so the behavior is like a hashmap ). Would you agree the...

Using Hash Maps to represent an extremely large data source

I have a very large possible data set that I am trying to visualize at once. The set itself consists of hundreds of thousands of segments, each of which is mapped to an id. I have received a second data source that gives more real-time information for each segment, but the id's do not correspond to the id's I have. I have a 1:1 mappin...

Hashmap in the making

How to go about creating a Hashmap in C from scratch ? What would be the parameters taken into consideration and what how would you test the hashmap as to how good it is ? As in what would be benchmark test cases which you require to run before you say that your hash map is complete. ...

C# Equivalent of Java IdentityHashMap

As far as i know, there is no direct equivalent in C#. My current idea is to use a Dictionary with a custom IEqualityComparer, that checks for reference equality. However, this seems to lose the advantage gained by hashing. Is there a way to get an individual hashcode out of every different object? Or is this impossible and I should use...

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...

Populate an enum with values from database

I have a table which maps String->Integer. Rather than create an enum statically, I want to populate the enum with values from a database. Is this possible ? So, rather than delcaring this statically: public enum Size { SMALL(0), MEDIUM(1), LARGE(2), SUPERSIZE(3) }; I want to create this enum dynamically since the numbers {0,1,2,3} ...

Java hashmaps without the value?

Let's say I want to put words in a data structure and I want to have constant time lookups to see if the word is in this data structure. All I want to do is to see if the word exists. Would I use a HashMap (containsKey()) for this? HashMaps use key->value pairings, but in my case I don't have a value. Of course I could use null for t...

How to use stdext::hash_map?

I would like to see a simple example of how to override stdext::hash_compare properly, in order to define a new hash function and comparison operator for my own user-defined type. I'm using Visual C++ (2008). ...

Best Design for the scenario

Hi Experts, I have a requirement where I have to select around 60 million plus records from database. Once I have all records in ResultSet then I have to formate some columns as per the client requirement(date format and number format) and then I have to write all records in a file(secondary memory). Currently I am selecting records o...

Java: Search in HashMap keys based on regex?

I'm building a thesaurus using a HashMap to store the synonyms. I'm trying to search through the words based on a regular expression: the method will have to take a string as parameter and return an array of results. Here's my first stab at it: public ArrayList<String> searchDefinition(String regex) { ArrayList<String> results = new ...

Java: find 'connected components' in graph as HashMap

Ok, so here goes: I'm building a thesaurus using a HashMap <String,ArrayList<String>> to hold words and their synonyms (this data structure is required). For the purpose of the assignment, the synonymity relation is considered transitive. (We can imagine the thesaurus as a graph). What I'm trying to accomplish is to print this graph in ...

Keeping a pair of primitives in a Java HashMap

I have a list of files. I would like to scan through and keep a count of the number of files with the same size. the issue is with filesize which is a long, as we know, hashmap will take in only an object and not a primitive. So using new Long(filesize), i put it into the hashmap. instead of getting a pair of (filesize, count), i got a l...

Is there a way to get the value of a HashMap randomly in Java?

Is there a way to get the value of a HashMap randomly in Java? ...

Changing value after it's placed in HashMap changes what's inside HashMap?

This is a Java related question. If I create a new HashMap and a new List, and then place the List inside the Hashmap with some arbitrary key and then later call List.clear() will it affect what I've placed inside the hashmap? The deeper question here being: When I add something to a hashmap, is a new object copied and placed or is a ref...

Which is the better way to setListData in a jList, vector or array?

In this answer to a question I asked. Kathy Van Stone says that adding an array like so jList1.setListData(LinkedHashMap.keySet().toArray()); is a better way than to do it like this jList1.setListData(new Vector<String>(LinkedHashMap.keySet())); I am wondering if there was any truth to this and if so what the reason behind it was. ...