@pranavpatel.ca/algo-kombin
Version:
KombiN is a library for bijectively mapping all ordered pairs from two finite sets into a single linear index. It orders pairs by ascending weight (sum of indices) using a three-region zig-zag algorithm, enabling O(1) bidirectional lookups between pairs a
55 lines (54 loc) • 2.11 kB
TypeScript
/**
* Table provides O(1) bijective mapping between ordered pairs from two finite sets and a unique linear index.
* All possible combination pairs are sorted by their weight (sum of indices) in ascending order.
* Supports both zero-based and one-based indexing.
*/
export declare class Table {
/**
* Initializes a new instance of the Table class.
* @param lengthOfA Number of elements in the first set.
* @param lengthOfB Number of elements in the second set.
* @param zeroBasedIndex True for zero-based indexing, false for one-based indexing.
* @throws Error if lengthOfA or lengthOfB is 0 or less.
*/
constructor(lengthOfA: number, lengthOfB: number, zeroBasedIndex: boolean);
/** Length of Set A */
LengthOfA: number;
/** Length of Set B */
LengthOfB: number;
/** Lower length of both sets */
LowerLength: number;
/** Maximum Sum for Range 1 */
MaxSumRange1: number;
/** Maximum Sum for Range 2 */
MaxSumRange2: number;
/** Maximum Sum for Range 3 */
MaxSumRange3: number;
/** Maximum Index for Range 1 */
MaxIndexRange1: number;
/** Maximum Index for Range 2 */
MaxIndexRange2: number;
/** Maximum Index for Range 3 */
MaxIndexRange3: number;
/** Zero based indexing or not */
ZeroBasedIndex: boolean;
/**
* Computes and sets internal values used for index and pair calculations.
*/
private Abstract;
/**
* Returns the unique index value for the given combination pair (ai, bi).
* @param ai Element index of set A.
* @param bi Element index of set B.
* @returns Index value for the given combination pair.
* @throws Error if ai or bi has invalid value.
*/
GetIndexOfElements(ai: number, bi: number): number;
/**
* Returns the combination pair corresponding to the given index value.
* @param index Index value of the combination pair.
* @returns Tuple [ai, bi] representing the combination pair.
* @throws Error if index has invalid value.
*/
GetElementsAtIndex(index: number): [number, number];
}