Package it.unimi.dsi.util
Class CircularCharArrayBuffer
- java.lang.Object
-
- it.unimi.dsi.util.CircularCharArrayBuffer
-
public class CircularCharArrayBuffer extends java.lang.Object
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 issize()
(it will never be larger than the buffer size). The characters present in the buffer are provided through thetoCharArray(char[], int, int)
method and alike.
-
-
Constructor Summary
Constructors Constructor Description CircularCharArrayBuffer(int maxChar)
Creates a new circular buffer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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).void
clear()
Clears the buffer content, before reuse.int
size()
The number of characters present in the buffer.char[]
toCharArray()
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.
-
-
-
Method Detail
-
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.
-
-