2024-03-17 18:17:12 +01:00
|
|
|
[System.Serializable]
|
2024-02-29 20:36:48 +01:00
|
|
|
public class CircularBuffer<T> {
|
2024-03-17 18:17:12 +01:00
|
|
|
public T[] buffer;
|
|
|
|
public int bufferSize;
|
2024-02-29 20:36:48 +01:00
|
|
|
|
|
|
|
public CircularBuffer(int bufferSize) {
|
|
|
|
this.bufferSize = bufferSize;
|
|
|
|
buffer = new T[bufferSize];
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Add(T item, int index) => buffer[index % bufferSize] = item;
|
|
|
|
public T Get(int index) => buffer[index % bufferSize];
|
|
|
|
public void Clear() => buffer = new T[bufferSize];
|
|
|
|
}
|