java - choosing data structure in which first search need to be done in key items in order to retrieve corresponding value -


this question has answer here:

i have choose 1 data structure need below explaining conditions there following values

abc,def,rty,ytr,dft map row r1b1 (actully key combination of r1+b1) abeerc,dfffef,rggty map row r1b1 (actully key combination of r1+b2)

  key                      value abc,def,rty,ytr,dft --->    r1b1 abeerc,dfffef,rggty --->    r1b2 

now example lets if ytr able retrieve r1b1 or lets value rggty able retrieve r1b2 case matters of search , complexity , time taken things have go in sequence

for example first pick first line search ytr , first match abc not match have match def not again match match rty not match match ytr , find key r1b1 finally

similarly if second string need searched lets rggty scan first row in not find value search continue second row , in second row in third element rggty element retrieve r1b2 value

lets if put thing in map sequence search go on key , able find corresponding value ,

folks please advise best data structure can implement in java in have search keys items find corresponding value in fast time not hit performance too

folks please advise best data structure obtain functionality

i use map. map entry, key matching sequence (abc) , key appropriate value (r1b1).

the same value can placed in map multiple times.

edit: example

// populating search map value r1 = value("r1"); value b1 = value("b1"); value b2 = value("b2");  multipartvalue r1b1 = new multipartvalue(r1, b1); multipartvalue r1b2 = new multipartvalue(r1, b2);  map<string, multipartvalue> searchmap = new hashmap<>();  searchmap.add("abc", r1b1); searchmap.add("def", r1b1); searchmap.add("rty", r1b1); searchmap.add("ytr", r1b1); searchmap.add("dft", r1b1);  searchmap.add("abeerc", r1b2); searchmap.add("dfffef", r1b2); searchmap.add("rggty", r1b2);   // using search map string searchtext = "ytr"; multipartvalue matchingvalue = searchmap.get(searchtext); // matchingvalue = r1b1 

the keys looked me strings; values r1b1 , r1b2 did not.

the classes multipartvalue , value modelling of combinations of r1b1 , r1b2. use ever appropriate use case. strings if appropraite.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -