| java.lang.Object org.hsqldb.lib.ArrayCounter
ArrayCounter | public class ArrayCounter (Code) | | Collection of routines for counting the distribution of the values
in an int[] array.
author: fredt@users version: 1.7.2 since: 1.7.2 |
Method Summary | |
static long | calcInterval(int segments, int start, int limit) Helper method to calculate the span of the sub-interval. | public static int[] | countSegments(int[] array, int elements, int segments, 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). | 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. |
calcInterval | static long calcInterval(int segments, int start, int limit)(Code) | | Helper method to calculate the span of the sub-interval. Simply returns
the cieling of ((limit - start) / segments) and accounts for invalid
start and limit combinations.
|
countSegments | public static int[] countSegments(int[] array, int elements, int segments, int start, int limit)(Code) | | 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 reange 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.
|
rank | public static int rank(int[] array, int elements, int target, int start, int limit, int margin)(Code) | | 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 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, 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
6000.
|
|
|