Queue-like data structure with fast search and insertion

Posted by Max on Stack Overflow See other posts from Stack Overflow or by Max
Published on 2010-04-15T21:43:49Z Indexed on 2010/04/15 22:03 UTC
Read the original article Hit count: 272

I need a datastructure with the following properties:

  1. It contains integer numbers, no duplicates.

  2. After it reaches the maximal size the first element is removed. So if the capacity is 3, then this is how it would look when putting in it sequential numbers: {}, {1}, {1, 2}, {1, 2, 3}, {2, 3, 4}, {3, 4, 5} etc.

  3. Only two operations are needed: inserting a number into this container (INSERT) and checking if the number is already in the container (EXISTS). The number of EXISTS operations is expected to be approximately 2 * number of INSERT operations.

  4. I need these operations to be as fast as possible.

What would be the fastest data structure or combination of data structures for this scenario?

© Stack Overflow or respective owner

Related posts about data-structures

Related posts about Performance