All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.javanut.pronghorn.pipe.util.RLESparseArray Maven / Gradle / Ivy

Go to download

Ring buffer based queuing utility for applications that require high performance and/or a small footprint. Well suited for embedded and stream based processing.

There is a newer version: 1.1.27
Show newest version
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