Top Description Constructors Methods
org.hsqldb.lib

public final Class ArrayCounter

extends Object
Class Inheritance

Collection of routines for counting the distribution of the values in an int[] array.
Author
Fred Toussi (fredt@users dot sourceforge.net)
Since
1.7.2
Version
1.7.2

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv static int

Returns:

int
calcInterval
(int
int
segments
,
int
int
start
,
int
int
limit
)

Helper method to calculate the span of the sub-interval.

public static int[]

Returns:

int[]
countSegments
(int[]
int[]
array
,
int
int
elementCount
,
int
int
segments
,
int
int
interval
,
int
int
start
,
int
int
limit
)

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

public static int

Returns:

int
rank
(int[]
int[]
array
,
int
int
elements
,
int
int
target
,
int
int
start
,
int
int
limit
,
int
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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ArrayCounterback to summary
public ArrayCounter()

Method Detail

calcIntervalback to summary
pack-priv static int calcInterval(int segments, int start, int limit)

Helper method to calculate the span of the sub-interval. Simply returns the ceiling of ((limit - start) / segments) and accounts for invalid start and limit combinations.

Parameters
segments:int

int

start:int

int

limit:int

int

Returns:int

int

countSegmentsback to summary
public static int[] countSegments(int[] array, int elementCount, int segments, int interval, int start, int limit)

Returns an int[] array of length segments containing the distribution count of the elements in unsorted int[] array with values between min and max (range). Values outside the min-max range are ignored

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. People above the age of 79 are excluded. If the range is not a multiple of segments, the last segment will be cover a smaller sub-range than the rest.

Parameters
array:int[]

int[]

elementCount:int

int

segments:int

int

interval:int

int

start:int

int

limit:int

int

Returns:int[]

int[]

rankback to summary
public static int rank(int[] array, int elements, 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. Parameter margin indicates the margin of error in target

In statistics, this can be used to calculate a median or quartile 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, c, 6000, 18, 65, 0) 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 to 6000.

Parameters
array:int[]

int[]

elements:int

int

target:int

int

start:int

int

limit:int

int

margin:int

int

Returns:int

int