UNPKG

doubly-linked-list-typed

Version:
175 lines (174 loc) 8.54 kB
/** * */ export declare class BinaryIndexedTree { protected readonly _freq: number; protected readonly _max: number; /** * The constructor initializes the properties of an object, including default frequency, maximum * value, a freqMap data structure, the most significant bit, and the count of negative frequencies. * @param - - `frequency`: The default frequency value. It is optional and has a default * value of 0. */ constructor({ frequency, max }: { frequency?: number; max: number; }); protected _freqMap: Record<number, number>; /** * The function returns the frequency map of numbers. * @returns The `_freqMap` property, which is a record with number keys and number values, is being * returned. */ get freqMap(): Record<number, number>; protected _msb: number; /** * The function returns the value of the _msb property. * @returns The `_msb` property of the object. */ get msb(): number; protected _negativeCount: number; /** * The function returns the value of the _negativeCount property. * @returns The method is returning the value of the variable `_negativeCount`, which is of type * `number`. */ get negativeCount(): number; /** * The above function returns the value of the protected variable `_freq`. * @returns The frequency value stored in the protected variable `_freq`. */ get freq(): number; /** * The above function returns the maximum value. * @returns The maximum value stored in the variable `_max`. */ get max(): number; /** * The function "readSingle" reads a single number from a specified index. * @param {number} index - The `index` parameter is a number that represents the index of an element in a * collection or array. * @returns a number. */ readSingle(index: number): number; /** * The "update" function updates the value at a given index by adding a delta and triggers a callback * to notify of the change. * @param {number} position - The `index` parameter represents the index of the element that needs to be * updated in the data structure. * @param {number} change - The "delta" parameter represents the change in value that needs to be * applied to the frequency at the specified index. */ update(position: number, change: number): void; /** * The function "writeSingle" checks the index and writes a single value with a given frequency. * @param {number} index - The `index` parameter is a number that represents the index of an element. It * is used to identify the specific element that needs to be written. * @param {number} freq - The `freq` parameter represents the frequency value that needs to be * written. */ writeSingle(index: number, freq: number): void; /** * The read function takes a count parameter, checks if it is an integer, and returns the result of * calling the _read function with the count parameter clamped between 0 and the maximum value. * @param {number} count - The `count` parameter is a number that represents the number of items to * read. * @returns a number. */ read(count: number): number; /** * The function returns the lower bound of a non-descending sequence that sums up to a given number. * @param {number} sum - The `sum` parameter is a number that represents the target sum that we want * to find in the sequence. * @returns The lowerBound function is returning a number. */ lowerBound(sum: number): number; /** * The upperBound function returns the index of the first element in a sequence that is greater than * or equal to a given sum. * @param {number} sum - The "sum" parameter is a number that represents the target sum that we want * to find in the sequence. * @returns The upperBound function is returning a number. */ upperBound(sum: number): number; /** * The function calculates the prefix sum of an array using a binary indexed tree. * @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the * array for which we want to calculate the prefix sum. * @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index * `i`. */ getPrefixSum(i: number): number; /** * The function returns the value of a specific index in a freqMap data structure, or a default value if * the index is not found. * @param {number} index - The `index` parameter is a number that represents the index of a node in a * freqMap data structure. * @returns a number. */ protected _getFrequency(index: number): number; /** * The function _updateFrequency adds a delta value to the element at the specified index in the freqMap array. * @param {number} index - The index parameter is a number that represents the index of the freqMap * element that needs to be updated. * @param {number} delta - The `delta` parameter represents the change in value that needs to be * added to the freqMap at the specified `index`. */ protected _updateFrequency(index: number, delta: number): void; /** * The function checks if the given index is valid and within the range. * @param {number} index - The parameter "index" is of type number and represents the index value * that needs to be checked. */ protected _checkIndex(index: number): void; /** * The function calculates the sum of elements in an array up to a given index using a binary indexed * freqMap. * @param {number} index - The `index` parameter is a number that represents the index of an element in a * data structure. * @returns a number. */ protected _readSingle(index: number): number; /** * The function `_updateNegativeCount` updates a counter based on changes in frequency values. * @param {number} freqCur - The current frequency value. * @param {number} freqNew - The freqNew parameter represents the new frequency value. */ protected _updateNegativeCount(freqCur: number, freqNew: number): void; /** * The `_update` function updates the values in a binary indexed freqMap starting from a given index and * propagating the changes to its parent nodes. * @param {number} index - The `index` parameter is a number that represents the index of the element in * the data structure that needs to be updated. * @param {number} delta - The `delta` parameter represents the change in value that needs to be * applied to the elements in the data structure. */ protected _update(index: number, delta: number): void; /** * The `_writeSingle` function updates the frequency at a specific index and triggers a callback if * the frequency has changed. * @param {number} index - The `index` parameter is a number that represents the index of the element * being modified or accessed. * @param {number} freq - The `freq` parameter represents the new frequency value that needs to be * written to the specified index `index`. */ protected _writeSingle(index: number, freq: number): void; /** * The `_read` function calculates the sum of values in a binary freqMap up to a given count. * @param {number} count - The `count` parameter is a number that represents the number of elements * to read from the freqMap. * @returns the sum of the values obtained from calling the `_getFrequency` method for each index in the * range from `count` to 1. */ protected _read(count: number): number; /** * The function `_binarySearch` performs a binary search to find the largest number that satisfies a given * condition. * @param {number} sum - The sum parameter is a number that represents the target sum value. * @param before - The `before` parameter is a function that takes two numbers `x` and `y` as * arguments and returns a boolean value. It is used to determine if `x` is less than or equal to * `y`. The purpose of this function is to compare two numbers and determine their order. * @returns the value of the variable "left". */ protected _binarySearch(sum: number, before: (x: number, y: number) => boolean): number; }