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

com.javanut.pronghorn.util.NOrdered 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.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