hashmap

Hash Map with Two keys - Finding all elements linked to one key. C++

Hi, I have an object Line which contains 2 objects of type Point called Point1 and Point2. I want to create a HashMap containing lines and whose keys are std::pair<Point1, Point2>. What I'd like to do is find all the Lines with are referenced (for instance) by Point1, i.e. with key std::pair<Point1, Anything>. I don't care about std::...

Hash map, string compares, and std::map?

First off, I would like to make a few points I believe to be true. Please can these be verified? A hash map stores strings by converting them into an integer somehow. std::map is not a hash map, and if I'm using strings, I should consider using a hash map for memory issues? String compares are not good to rely on. If std::map is not...

Difference between two maps

I need to very efficiently compare two maps in Clojure/Java, and return the difference as determined by Java's .equals(..), with nil/null equivalent to "not present". i.e. I am looking for the most efficient way to a write a function like: (map-difference {:a 1, :b nil, :c 2, :d 3} {:a 1, :b "Hidden", :c 3, :e 5}) => {:b nil, :c 2...

How To Pass HashMap Records Into JSP?

Im new to using HashMap. Im assigned a project to retrieve records from HashMap and display it as a Pie Chart on a JSP. However despite searching and look thru many different Hashmap examples. Im still stuck in my project which is about to due in 3 weeks time :( Kindly please give me some advice and i apologize if my code is in a mess. ...

Array to hash-Perl

Hi, I have an array and i try to convert the array contents to a hash with keys and values (index 0 is key, index 1 is value, index 2 is key, index 3 is value, etc). But some how i was struck and it is not producing the expected result. code is given below. open (FILE, "message.xml") || die "Cannot open\n"; $var = <FILE>; while ($va...

Help on __gnu_cxx::hash_map

Hi, Is there any document regarding "__gnu_cxx::hash_map"? I want to know how to use it. Srinivas ...

Android - Get value from HashMap

I have tried to search on HashMap in Android, but getting problem: Consider this example: HashMap<String, String> meMap=new HashMap<String, String>(); meMap.put("Color1","Red"); meMap.put("Color2","Blue"); meMap.put("Color3","Green"); meMap.put("Color4","White"); now i want to iterate it and get the value of eac...

Getting URL value from HashMap in a JSP page (Using Struts2)

Hi, I am trying to get my page to link to a certain URL that is stored in a HashMap (the key is some name, and the value is the URL I want to link to). I'm not very good at describing this, but here is my code: For the JSP page: <table> <s:iterator value="dependenciesList" id="dependency"> <tr><td> <a href="<s:url value="pro...

How can I extract ArrayList from HashMap and loop through it in Java?

I have set up a HashMap like so: Map<String, ArrayList<String>> theAccused = new HashMap<String, ArrayList<String>>(); ... and I populate this by storing for every name (key), a list of names (value). So: ArrayList<String> saAccused = new ArrayList<String>(); // populate 'saAccused' ArrayList ... // done populating theAccused.put(sAc...

Non-Uniform randomizer

I need to to generate 6 unique random numbers from 1 to 37; At first I used a simple array mapping: private int k=6, n=37; public int[] Results () { // fill an array with numbers 1 2 3 . . . n int[] numbers = new int[n]; for (int i = 0; i < numbers.length; i++) numbers[i] = i + 1; // draw k numbers and put them...

Java Hashmap values to Array

I have the following code which adds some arrays to a hashmap but then I want access those arrays to do some work on them later. I've gotten this far but can't figure the rest out to make it work.... import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; public static void main(String[] args) { St...

how to call an Iterator over a hashMap

i need to see my hashMap keys and values in order to check if it s working properly.but im getting an error for the below lines: Iterator iterator = myHashMap.keySet().iterator(); Flows flows = new Flows(); while(iterator.hasNext()){ Object key = iterator.next(); Object value = myHashMap.get(key); // <-- ...

how to insert a hashMap into excel to draw a graph

I have a hashMap in java in terms of some keys which each key is indicating a flow. Then each value showing statics about each packet belongs to that flow. What I need to do is, to draw graphs for each flow based on those values. for example: Flow1: {[length, time],[],[],...} Flow2: {[length, time],[length, time],[],...} I need to p...

Creating a CSV File in java from a HashMap

I have a hashMap in java in terms of some keys which each key is indicating a flow. Then each value showing statics about each packet belongs to that flow. What I need to do is, to draw graphs for each flow based on those values. for example: Flow1: {[length, time],[],[],...} Flow2: {[length, time],[length, time],[],...} i need t...

Java- not removing from HashMap

OK so I have this HashMap private Map<String, Player> players = new HashMap<String, Player>(); Here is what I use to remove: public void destroy() { players.remove("Red"); os.println(me.getUsername() + "|1|has left|yes|chat"); } I say Red because it's just a TEST right now. I will get the eventual correct one later. A...

How can I iterate over an object while modifying it in Java?

Possible Duplicates: Java: Efficient Equivalent to Removing while Iterating a Collection Removing items from a collection in java while iterating over it I'm trying to loop through HashMap: Map<String, Integer> group0 = new HashMap<String, Integer>(); ... and extract every element in group0. This is my approach: // itera...

Accessing the last entry in a Map

Hi all, How to move a particular HashMap entry to Last position? For Example, I have HashMap values like this: HashMap<String,Integer> map = new HashMap<String,Integer>(); map= {Not-Specified 1, test 2, testtest 3}; "Not-Specified" may come in any position. it may come first or in the middle of the map. But i want to move the "Not-...

Is it possible to create a HashMap that is Parcelable on Android?

I am trying to extend HashMap as a Parcelable and I got the syntax to compile, however, at runtime it throws an exception and returns a null pointer trying to un-marshal the data. The sender has to cast to (Parcelable) to resolve ambiguity, however, the receiver complains that is expected Parcelable but found HashMap. Has anyone been s...

What is the best way to cache and reuse immutable singleton objects in Java?

Hi, I have a class representing a set of values that will be used as a key in maps. This class is immutable and I want to make it a singleton for every distinct set of values, using the static factory pattern. The goal is to prevent identical objects from being created many (100+) times and to optimize the equals method. I am looking ...

Merge Hashmaps retaining values JAVA

Hi Say I have two hashmaps: {dog=1, cat=1, sport=3, golf=4} {dog=5, person=1, animal=4} I want to merge them retaining the values, so that the values add together in the output Output: {dog=6, person=1, animal=4, cat=1, sport=3, golf=4} Notice how "dog" has a value of 6 (5+1) Using Hashmap.putAll(), the value of dog becomes 5, a...