Carl Summers
Carl Summers

Reputation: 504

Polymorphic HashTable like datastructure

I'm creating a client side cache object and one of the consumers of the cache needs a means of looking up data by type. Obviously I can't just have a map from class to data since that wouldn't retrieve subtypes of the class. Is there a 'standard' or well suited data structure for this kind of thing?

Upvotes: 1

Views: 175

Answers (2)

David Soroko
David Soroko

Reputation: 9096

If you key you HashMap by Class objects it will behave exactly as you expect it to. There will be no lookup on "subtype".

Upvotes: 0

David Weiser
David Weiser

Reputation: 5205

Instead of using a HashTable, it'd be easier to use a tree, since a tree would easily represent the type heirarchy.

Upvotes: 2

Related Questions