com.javanut.pronghorn.util.NOrdered Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pronghorn-pipes Show documentation
Show all versions of pronghorn-pipes Show documentation
Ring buffer based queuing utility for applications that require high performance and/or a small
footprint. Well suited for embedded and stream based processing.
package com.javanut.pronghorn.util;
import java.io.IOException;
import com.javanut.pronghorn.util.Appendables;
public class NOrdered {
private final Object[] elements;
private final long[] occurences;
private int count;
public NOrdered(int maxCount) {
elements = new Object[maxCount];
occurences = new long[maxCount];
}
public void sample(T item) {
for(int i = 0; i 0) && (occurences[j-1] < occurences[i])) {
j--;
}
if (j!=i) {
long tOcc = occurences[i];
Object tEle = elements[i];
System.arraycopy(elements, j, elements, j+1, i-j);
System.arraycopy(occurences, j, occurences, j+1, i-j);
occurences[j] = tOcc;
elements[j] = tEle;
}
return;
}
}
//if we are here just add this one on to the end
if (count
© 2015 - 2025 Weber Informatics LLC | Privacy Policy