com.javanut.pronghorn.pipe.util.RLESparseArray 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.pipe.util;
public class RLESparseArray {
public static long[] rlEncodeSparseArray(long[] data) {
//countTransitions
int transitionCount = 1; //the first one counts
int i = data.length;
long lastValue = data[i-1];
while (--i>=0) {
long thisValue = data[i];
if (thisValue!=lastValue) {
transitionCount++;
}
lastValue = thisValue;
}
//copy the data
int length = (transitionCount * 2) + 1;
long[] result = new long[length];
int resultPos = 0;
result[resultPos++] = data.length;
int runLength = 0;
lastValue = data[0];
for(int j = 0; j=0) {
result[resultPos++] = value;
}
}
return result;
}
public static int[] rlEncodeSparseArray(int[] data) {
//countTransitions
int transitionCount = 1; //the first one counts
int i = data.length;
int lastValue = data[i-1];
while (--i>=0) {
int thisValue = data[i];
if (thisValue!=lastValue) {
transitionCount++;
}
lastValue = thisValue;
}
//copy the data
int length = (transitionCount * 2) + 1; //one for leading full count
int[] result = new int[length];
int resultPos = 0;
result[resultPos++] = data.length;
int runLength = 0;
lastValue = data[0];
for(int j = 0; j=0) {
result[resultPos++] = value;
}
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy