Package it.unimi.dsi.util
Class CircularCharArrayBuffer
java.lang.Object
it.unimi.dsi.util.CircularCharArrayBuffer
A circular char buffer that can be used to implement a sliding
window over a text. The buffer has a maximum size, fixed at construction time. As new characters
are added, the oldest ones are discarded if necessary. At all
times, the number of available characters present in the buffer is
size()
(it will never be larger
than the buffer size). The characters present in the buffer are provided through the toCharArray(char[], int, int)
method and alike.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(char[] b, int offset, int length) Adds the charactersb[offset]
, …b[offset+length-1]
to the buffer (possibly just the last ones, and possibly discarding the oldest characters in the buffer).void
clear()
Clears the buffer content, before reuse.int
size()
The number of characters present in the buffer.char[]
Returns a new array containing a copy of the buffer content.void
toCharArray
(char[] b) Copies the content of the buffer to an array.void
toCharArray
(char[] b, int offset, int length) Copies the content of the buffer to an array.
-
Constructor Details
-
CircularCharArrayBuffer
public CircularCharArrayBuffer(int maxChar) Creates a new circular buffer.- Parameters:
maxChar
- the buffer size.
-
-
Method Details
-
add
public void add(char[] b, int offset, int length) Adds the charactersb[offset]
, …b[offset+length-1]
to the buffer (possibly just the last ones, and possibly discarding the oldest characters in the buffer).- Parameters:
b
- the array whence characters are copied.offset
- the starting point.length
- the (maximum) number of characters to be copied.
-
toCharArray
public void toCharArray(char[] b, int offset, int length) Copies the content of the buffer to an array.- Parameters:
b
- the buffer where the content is to be copied.offset
- the starting index where copy should start from.length
- the maximum number of characters to be copied.
-
toCharArray
public void toCharArray(char[] b) Copies the content of the buffer to an array.- Parameters:
b
- the buffer where the content is to be copied.
-
toCharArray
public char[] toCharArray()Returns a new array containing a copy of the buffer content.- Returns:
- a copy of the buffer content.
-
size
public int size()The number of characters present in the buffer.- Returns:
- the number of characters present in the buffer.
-
clear
public void clear()Clears the buffer content, before reuse.
-