Stack and Hash joint

Posted by Alexandru on Stack Overflow See other posts from Stack Overflow or by Alexandru
Published on 2010-05-07T10:59:06Z Indexed on 2010/05/07 21:58 UTC
Read the original article Hit count: 501

Filed under:
|
|
|
|

I'm trying to write a data structure which is a combination of Stack and HashSet with fast push/pop/membership (I'm looking for constant time operations). Think of Python's OrderedDict.

I tried a few things and I came up with the following code: HashInt and SetInt. I need to add some documentation to the source, but basically I use a hash with linear probing to store indices in a vector of the keys. Since linear probing always puts the last element at the end of a continuous range of already filled cells, pop() can be implemented very easy without a sophisticated remove operation.

I have the following problems:

  • the data structure consumes a lot of memory (some improvement is obvious: stackKeys is larger than needed).
  • some operations are slower than if I have used fastutil (eg: pop(), even push() in some scenarios). I tried rewriting the classes using fastutil and trove4j, but the overall speed of my application halved.

What performance improvements would you suggest for my code? What open-source library/code do you know that I can try?

© Stack Overflow or respective owner

Related posts about stack

Related posts about hash