• Post Reply Bookmark Topic Watch Topic
  • New Topic

Lookup tables: best way for speed

 
Joe Vahabzadeh
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I have two separate scenarios right now, and am wondering if I've gone about this in the best way possible assuming that I want to maximize speed.

1) Straight lookup tables - I've got a massive array, where each entry is an array of bytes (each entry can be null, one, or more than one byte in the array). Right now, I have this set up as an interface that never gets implemented by anything, and is just accessed by whichever class needs them as myInterface.myLookupTable[index]. But can this be done better?

2) A slight variation on the above - a fairly large lookup table, but where it's just a one-dimensional array of bytes. However, depending on circumstances, as many as a dozen or so of the entries in the array need to be changed, but there's also a possibility that I'd need to switch back to the original array (default circumstance). In this case, I've made it a class, where both the methods and the reference to the array is static. The original array is private, but there's also a public array that gets initialized when a certain function is called (by copying the private one), and then the changes, if needed, are made in the public copy. Is this the ideal way (for speed) to handle this?

Thanks.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't do either. Hide the whole thing inside a class and access it with a lookup() method that hides its implementation. Then you can experiment with different implementations as need be, and you have the added benefit of being sure no one is changing the table by mistake.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!