0

The data structure I'm looking for is kind of like a queue of characters, except with very little overhead and fast operations. How it does this is it maintains an array of characters. The array doesn't need to be resizable. It can add characters to the end and can pop them off the front.

In the example below, the size of the array was initialized to 20. The ? represents garbage characters which can be written over later and should never be read.

[??????abcdefghijklmnop???]
       ^               ^
  get position         |
                 put position

Then if we had an object that contained that data in Java, we could use it like this:

charQueue.put("qrstuv");
// put could throw an exception if we try to put
// more than the remaining available space
String abcde = charQueue.get(5); // contains "abcde"
// get could throw an exception if we try to get
// more than the remaining written characters
String fg = charQueue.get(2); // contains "fg"

Then the array would look like this:

[tuv??????????hijklmnopqrs]
    ^         ^
    |    get position
put position

Is there something in Java that already does this? I tried looking at CharBuffer, but I don't think it is exactly what I want.

redmoncoreyl
  • 133
  • 9

0 Answers0