Skip to content

Commit

Permalink
Change AggregatingRingBuffer code to be smarter about resetting to id…
Browse files Browse the repository at this point in the history
…entity values.
  • Loading branch information
lbooker42 committed Oct 23, 2024
1 parent b3a02fb commit 36756da
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,19 @@ public byte[] remove(int count) {
* O(size).
*/
public void clear() {
internalBuffer.clear();
final long prevHead = internalBuffer.head;
final int prevSize = size();

// Reset the pointers in the ring buffer without clearing the storage array. This leaves existing `identityVal`
// entries in place for the next `evaluate()` call.
internalBuffer.head = internalBuffer.tail = 0;

calcHead = calcTail = 0;

// Reset the cleared storage entries to the identity value
Arrays.fill(internalBuffer.storage, identityVal);
// Reset the previously populated storage entries to the identity value. After this call, all entries in the
// storage buffer are `identityVal`
fillWithIdentityVal(prevHead, prevSize);

// Reset the tree buffer with the identity value
Arrays.fill(treeStorage, identityVal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,19 @@ public char[] remove(int count) {
* O(size).
*/
public void clear() {
internalBuffer.clear();
final long prevHead = internalBuffer.head;
final int prevSize = size();

// Reset the pointers in the ring buffer without clearing the storage array. This leaves existing `identityVal`
// entries in place for the next `evaluate()` call.
internalBuffer.head = internalBuffer.tail = 0;

calcHead = calcTail = 0;

// Reset the cleared storage entries to the identity value
Arrays.fill(internalBuffer.storage, identityVal);
// Reset the previously populated storage entries to the identity value. After this call, all entries in the
// storage buffer are `identityVal`
fillWithIdentityVal(prevHead, prevSize);

// Reset the tree buffer with the identity value
Arrays.fill(treeStorage, identityVal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,19 @@ public double[] remove(int count) {
* O(size).
*/
public void clear() {
internalBuffer.clear();
final long prevHead = internalBuffer.head;
final int prevSize = size();

// Reset the pointers in the ring buffer without clearing the storage array. This leaves existing `identityVal`
// entries in place for the next `evaluate()` call.
internalBuffer.head = internalBuffer.tail = 0;

calcHead = calcTail = 0;

// Reset the cleared storage entries to the identity value
Arrays.fill(internalBuffer.storage, identityVal);
// Reset the previously populated storage entries to the identity value. After this call, all entries in the
// storage buffer are `identityVal`
fillWithIdentityVal(prevHead, prevSize);

// Reset the tree buffer with the identity value
Arrays.fill(treeStorage, identityVal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,19 @@ public float[] remove(int count) {
* O(size).
*/
public void clear() {
internalBuffer.clear();
final long prevHead = internalBuffer.head;
final int prevSize = size();

// Reset the pointers in the ring buffer without clearing the storage array. This leaves existing `identityVal`
// entries in place for the next `evaluate()` call.
internalBuffer.head = internalBuffer.tail = 0;

calcHead = calcTail = 0;

// Reset the cleared storage entries to the identity value
Arrays.fill(internalBuffer.storage, identityVal);
// Reset the previously populated storage entries to the identity value. After this call, all entries in the
// storage buffer are `identityVal`
fillWithIdentityVal(prevHead, prevSize);

// Reset the tree buffer with the identity value
Arrays.fill(treeStorage, identityVal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,19 @@ public int[] remove(int count) {
* O(size).
*/
public void clear() {
internalBuffer.clear();
final long prevHead = internalBuffer.head;
final int prevSize = size();

// Reset the pointers in the ring buffer without clearing the storage array. This leaves existing `identityVal`
// entries in place for the next `evaluate()` call.
internalBuffer.head = internalBuffer.tail = 0;

calcHead = calcTail = 0;

// Reset the cleared storage entries to the identity value
Arrays.fill(internalBuffer.storage, identityVal);
// Reset the previously populated storage entries to the identity value. After this call, all entries in the
// storage buffer are `identityVal`
fillWithIdentityVal(prevHead, prevSize);

// Reset the tree buffer with the identity value
Arrays.fill(treeStorage, identityVal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,19 @@ public long[] remove(int count) {
* O(size).
*/
public void clear() {
internalBuffer.clear();
final long prevHead = internalBuffer.head;
final int prevSize = size();

// Reset the pointers in the ring buffer without clearing the storage array. This leaves existing `identityVal`
// entries in place for the next `evaluate()` call.
internalBuffer.head = internalBuffer.tail = 0;

calcHead = calcTail = 0;

// Reset the cleared storage entries to the identity value
Arrays.fill(internalBuffer.storage, identityVal);
// Reset the previously populated storage entries to the identity value. After this call, all entries in the
// storage buffer are `identityVal`
fillWithIdentityVal(prevHead, prevSize);

// Reset the tree buffer with the identity value
Arrays.fill(treeStorage, identityVal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,19 @@ public T[] remove(int count) {
* O(size).
*/
public void clear() {
internalBuffer.clear();
final long prevHead = internalBuffer.head;
final int prevSize = size();

// Reset the pointers in the ring buffer without clearing the storage array. This leaves existing `identityVal`
// entries in place for the next `evaluate()` call.
internalBuffer.head = internalBuffer.tail = 0;

calcHead = calcTail = 0;

// Reset the cleared storage entries to the identity value
Arrays.fill(internalBuffer.storage, identityVal);
// Reset the previously populated storage entries to the identity value. After this call, all entries in the
// storage buffer are `identityVal`
fillWithIdentityVal(prevHead, prevSize);

// Reset the tree buffer with the identity value
Arrays.fill(treeStorage, identityVal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,19 @@ public short[] remove(int count) {
* O(size).
*/
public void clear() {
internalBuffer.clear();
final long prevHead = internalBuffer.head;
final int prevSize = size();

// Reset the pointers in the ring buffer without clearing the storage array. This leaves existing `identityVal`
// entries in place for the next `evaluate()` call.
internalBuffer.head = internalBuffer.tail = 0;

calcHead = calcTail = 0;

// Reset the cleared storage entries to the identity value
Arrays.fill(internalBuffer.storage, identityVal);
// Reset the previously populated storage entries to the identity value. After this call, all entries in the
// storage buffer are `identityVal`
fillWithIdentityVal(prevHead, prevSize);

// Reset the tree buffer with the identity value
Arrays.fill(treeStorage, identityVal);
}
Expand Down

0 comments on commit 36756da

Please sign in to comment.