Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Associated values with HashMap

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 13-02-2010
Member
 
Join Date: Dec 2009
Posts: 292
Associated values with HashMap
  

Hello,
All this corresponds to a program that should provide the shortest path between two vertices of a weighted graph.
My structure is this:
Code:
private HashMap <Summit, trst <arc>> graph;
So I have a class that contains the Summit:
Code:
private String nm; 
	private int plusCourt; / / Evaluation Associate at Summit
And a class Arc:
Code:
private Summit arr;
	private int wg;
I created all vertices and all arcs. I entered the hashmap for each vertex the arcs involved. All this works wonderfully! Now I want to change the attribute plusCourt for all vertices contained in the hashmap.
Code:
for(S Summit: graph.keySet()){
						
			if(s.getName()== Departure)
			{
				sommetDepart = s;
s.setPlusCourt(0);
				
			}
			else
			{
				s.setPlusCourt(3255);	
			}
		}
And in fact, after running this code, as I travel all the keys to display the value, I have only null?!? Logically if I change a key it should keep its value in the associated hashmap? Thanks in advance.

Reply With Quote
  #2  
Old 13-02-2010
Member
 
Join Date: Nov 2009
Posts: 343
Re: Associated values with HashMap

Hello,
Just have a look at the code below, this will describe a function and I think you are interested in this.
Code:
if(s.getName()== Departure)
No comparison == on strings. Your "null" where you have specifically?
Reply With Quote
  #3  
Old 13-02-2010
Member
 
Join Date: Dec 2009
Posts: 211
Re: Associated values with HashMap

Hello,
Even I am trying a code something like this. In fact I put this bit of code before and after treatment:
Code:
TreeSet <arc> t;
		for(S Summit: graph.keySet()){
					
					
			t = graph.get(s);
System.out.System.out.println(t);
		}
It appears that everything is correct before and after I display with null.
Reply With Quote
  #4  
Old 13-02-2010
Member
 
Join Date: Dec 2009
Posts: 292
Re: Associated values with HashMap

Hey,
Here is my modified code, have a look and if I am wrong somewhere then you can correct me.
Code:
for(S Summit: lesKey){
			Summit tsm = s;
TreeSet <arc> tmpTree = graph.get(s);
			
			if(s.getName().equals(Departure))
			{
				sommetDepart = s;
s.setPlusCourt(0);
graph.remove(tsm);
graph.could(s, tmpTree);
				
			}
			else
			{
				s.setPlusCourt(3000);
graph.remove(tsm);
graph.could(s, tmpTree);
			}
		}
Reply With Quote
  #5  
Old 13-02-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: Associated values with HashMap

Hi,
Okay, you can add the following to your code and see how it is compiled.
Code:
HashMap <Summit, TreeSet <arc>> mtp = graph;
Set <VERTEX> lsky = mtp.keySet();
This is because AC reference the same objects in memory? You will have to create a new object again. Do, this and see if the program runs perfectly.
Reply With Quote
  #6  
Old 13-02-2010
Member
 
Join Date: Dec 2009
Posts: 211
Re: Associated values with HashMap

Hello,
Ok, I have modified my code and this is what I have with me now.
Code:
TreeSet <arc> t = graph.get(sommetDepart);	
		
		for(Arc: t){
			
			if(sommetDepart.getPlusCourt()+ a.getPoids()<a.getArrivee().getPlusCourt()){					
				a.getArrivee().splcrt(sommetDepart.getPlusCourt()+ a.getPoids());
			}
		}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Associated values with HashMap"
Thread Thread Starter Forum Replies Last Post
W32 registry values are not getting matched by the default values Angrzej Networking & Security 5 19-05-2011 12:23 PM
HashMap vs HashTable Joyjeet Software Development 6 04-01-2011 08:07 PM
Sorting a hashmap Gunner 1 Software Development 5 10-02-2010 04:06 AM
Iteration over a hashmap New ID Software Development 5 07-02-2010 02:40 AM
What is HashMap and Map? TAIPA Software Development 4 27-02-2009 10:16 PM


All times are GMT +5.5. The time now is 03:44 PM.