org.hsqldb.lib
Class ArrayCounter

java.lang.Object
  extended byorg.hsqldb.lib.ArrayCounter

public class ArrayCounter
extends Object

Collection of routines for counting the distribution of the values in an int[] array.

Since:
1.7.2
Version:
1.7.2
Author:
fredt@users

Constructor Summary
ArrayCounter()
           
 
Method Summary
static int[] countSegments(int[] array, int segments, int start, int limit)
          Returns an int[] array of length segments containing the distribution count of elements in unsorted int[] array with values between min and max (range).
static int rank(int[] array, int target, int start, int limit, int margin)
          With an unsorted int[] array and with target a positive integer in the range (1,array.length), finds the value in the range (start,limit) of the largest element (rank) where the count of all smaller elements in that range is less than or equals target.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayCounter

public ArrayCounter()
Method Detail

countSegments

public static int[] countSegments(int[] array,
                                  int segments,
                                  int start,
                                  int limit)
Returns an int[] array of length segments containing the distribution count of elements in unsorted int[] array with values between min and max (range).

A usage example is determining the count of people of each age group in a large int[] array containing the age of each person. Called with (array, 16,0,79), it will return an int[16] with the first element the count of people aged 0-4, the second element the count of those aged 5-9, and so on. If the range is not a multiple of segments, the last segment will be smaller that the rest.


rank

public static int rank(int[] array,
                       int target,
                       int start,
                       int limit,
                       int margin)
With an unsorted int[] array and with target a positive integer in the range (1,array.length), finds the value in the range (start,limit) of the largest element (rank) where the count of all smaller elements in that range is less than or equals target.

In statistics, this can be used to calculate a median or quadrile value. A usage example applied to an array of age values is to determine, the maximum age of a given number of people. With the example array given in countSegments, rank(array, 6000, 18, 65) will return an age value between 18-64 (inclusive) and the count of all people aged between 18 and the returned value(exclusive) will be less than or equal 6000.



Copyright © 2001 - 2004 HSQL Development Group. All Rights Reserved.