Module org.hsqldb
Package org.hsqldb.lib

## Class ArrayCounter

- java.lang.Object
- - org.hsqldb.lib.ArrayCounter

-     public final class ArrayCounter
      extends java.lang.Object

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

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ArrayCounter()` |

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `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).
    `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.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ArrayCounter

          public ArrayCounter()

  - ### Method Detail

    - #### countSegments

          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[]
        `elementCount` - int
        `segments` - int
        `interval` - int
        `start` - int
        `limit` - int
      Returns:
        int[]

    - #### rank

          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[]
        `elements` - int
        `target` - int
        `start` - int
        `limit` - int
        `margin` - int
      Returns:
        int