Nested HashTables?
I'm working on a Game Engine in Java and been trying to make the decision process for ons开发者_如何学运维creen drawing take the least amount of time. So I've been using a lot of HashTables nested in HashTables. I know it might be bad coding practice but I really want to know if there is any depth of nesting that will actually break my program from running?
Generally no, if you take the view that the general purpose of a hash table is one of scalability: i.e. to make operations have a "constant" time overall whatever the number of elements. Having to calculate multiple hash codes per operation doesn't in principle break this scalability guarantee.
Depending on your implementation, there may obviously be other considerations such as space/number of placeholder objects involved.
If the latter types of consideration are a concern, then consider using a large hash table with a combined hash function.
No, the depth doesn't matter (until the memory runs out, at least)
Just use HashMap
instead of Hashtable
Generally bad? No. But I've yet to see a game where deeply nested hashtables make sense. From what you're describing one gets the impression that you should take a good look at BSP trees.
It probably makes much more sense to use some of the high level frameworks anyhow instead of reinventing the wheel (badly).
精彩评论