we have situation ending using multi-level hash maps; is, hash map inside of hash map, 3 or 4 levels deep.
instinctively felt wrong somewhere. have read posts here talks how iterate/use multi-level hash map, hardly of them best practice this.
why multi level hash maps bad, , better design, if any?
here sample design of multi-level hash maps have:
map<string, object1> map1; class object1 { string version; map<string,object2> map2; } class object2 { map<string,list<object3>> map4; map<string,string> map5; }
as long they're abstracted, it's not that big of deal, lead down nasty rabbit holes in terms of readability. without abstraction, maintaining becomes nightmare no developer wish on another.
essentially, you're creating table of sorts; first key primary key gain access further columns. on simple one, two, or three-level design, isn't terrible; need 3 keys single value. provided there's convenient way access it, below, it's not terrible idea (although there far better out there).
public interface table<k1, k2, k3, v> { v get(k1 key1, k2 key2, k3 key3); } ...however, depends on you're doing data structure. if find attempting iterate intermediate keys values (that is, you're looking @ key 3 collection of values between , key 5), you've got rethink business logic @ point. data structure provided isn't flexible enough handle all cases; more or less, it's used simplistic indexing based on set of values.
alternatively, 1 guava table, same sort of thing, better interface (something 1 have above).
Comments
Post a Comment