This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help quickly....intelligent city name problem  RSS feed

 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have to create an intelligent city name resolution program, where there would be a number of city names(city values) that would map to a unique city code

for example

city code city values
aaa aaa,aab,aac,aad
bbb bbb,bba,bbc,bbd,bbf
ccc cca,ccb,ccc,ccd,cce
ddd dda.ddb,ddc,aaa(*Note*)


please note that aaa has been mapped to aaa as well as ddd.
Multiple recurring city values may be mapped to different keys.

i need to find all city codes that map to aaa ie i need
aaa<-aaa
ddd<-aaa


whats the best technique to implement the above problem
 
Steve Simon Joseph Fernandez
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Didn't understand the question

_steve.
 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by madhup narain:
[QB]
city code city values
aaa aaa,aab,aac,aad
bbb bbb,bba,bbc,bbd,bbf
ccc cca,ccb,ccc,ccd,cce
ddd dda.ddb,ddc,aaa(*Note*)


is actually like...

city code<----------city values
aaa<------------aaa,aab,aac,aad
bbb<------------bbb,bba,bbc,bbd,bbf
ccc<------------cca,ccb,ccc,ccd,cce
ddd<------------dda.ddb,ddc,aaa(*Note*)
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a homework problem, where you just have to find the answer, or real code, where you have to do lookups both ways multiple times? And is the data already in memory in some form, or should we start with reading in a file?
 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thanks for the pronto reply.
This aint no home work cause i always asked my DAD to do my homework
Anyways apart form kidding... lets get started..
I would prefer the data to be in memory rather than being in a file cause thats an external overhead of reading the file.
Plus you are correct that we'd need to read the data multiple times.

I was going through some stuff and have an idea i may implement this with a HASHTABLE or a HASHMAP.

So what else do you wanna know.. lets try to work this out together

Regards
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a production environment, you'd simply load all this data into a single relational database table with two indexes; unless it was for a consumer desktop app, in which case, yes, a HashMap of City objects keyed by codes, and a LinkedList of codes inside each City, and finally a HashMap of those same City objects by city name, would do it.
 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to do this in java. i would not prefer to do this using the relational database as a soultion as you provided.
Could we start with an example code that i did..

aaa<------------aaa,aab,aac,aad
bbb<------------bbb,bba,bbc,bbd,bbf
ddd<------------dda.ddb,ddc,aaa(*Note*)


public static void main(String args[])
{

Hashtable numbers= new Hashtable(1);
numbers.put("aaa","aaa");
numbers.put("aab","aaa");
numbers.put("aac","aaa");
numbers.put("aad","aaa");
numbers.put("bbb","bbb");
numbers.put("bba","bbb");
numbers.put("bbc","bbb");
numbers.put("bbd","bbb");
numbers.put("bbf","bbb");
numbers.put("dda","ddd");
numbers.put("ddb","ddd");
numbers.put("ddc","ddd");
numbers.put("aaa","ddd");

}
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now, as I said, instead of city names, define a City class, with a name and a List of codes in it. Put Lists of those into the HashMap instead of the city names. Also keep those City objects in a separate HashMap indexed by their names, so you can find them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!