doubly-linked-list-typed
Version:
Doubly Linked List
161 lines (160 loc) • 7.68 kB
TypeScript
/**
* data-structure-typed
*
* @author Pablo Zeng
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
* @license MIT License
*/
import type { SegmentTreeNodeVal } from '../../types';
export declare class SegmentTreeNode {
/**
* The constructor initializes the properties of a SegmentTreeNode object.
* @param {number} start - The `start` parameter represents the starting index of the segment covered
* by this node in a segment tree.
* @param {number} end - The `end` parameter represents the end index of the segment covered by this
* node in a segment tree.
* @param {number} sum - The `sum` parameter represents the sum of the values in the range covered by
* the segment tree node.
* @param {SegmentTreeNodeVal | undefined} [value] - The `value` parameter is an optional parameter
* of type `SegmentTreeNodeVal`. It represents the value associated with the segment tree node.
*/
constructor(start: number, end: number, sum: number, value?: SegmentTreeNodeVal | undefined);
protected _start: number;
/**
* The function returns the value of the protected variable _start.
* @returns The start value, which is of type number.
*/
get start(): number;
/**
* The above function sets the value of the "start" property.
* @param {number} value - The value parameter is of type number.
*/
set start(value: number);
protected _end: number;
/**
* The function returns the value of the protected variable `_end`.
* @returns The value of the protected property `_end`.
*/
get end(): number;
/**
* The above function sets the value of the "end" property.
* @param {number} value - The value parameter is a number that represents the new value for the end
* property.
*/
set end(value: number);
protected _value: SegmentTreeNodeVal | undefined;
/**
* The function returns the value of a segment tree node.
* @returns The value being returned is either a `SegmentTreeNodeVal` object or `undefined`.
*/
get value(): SegmentTreeNodeVal | undefined;
/**
* The function sets the value of a segment tree node.
* @param {SegmentTreeNodeVal | undefined} value - The `value` parameter is of type
* `SegmentTreeNodeVal` or `undefined`.
*/
set value(value: SegmentTreeNodeVal | undefined);
protected _sum: number;
/**
* The function returns the value of the sum property.
* @returns The method is returning the value of the variable `_sum`.
*/
get sum(): number;
/**
* The above function sets the value of the sum property.
* @param {number} value - The parameter "value" is of type "number".
*/
set sum(value: number);
protected _left: SegmentTreeNode | undefined;
/**
* The function returns the left child of a segment tree node.
* @returns The `left` property of the `SegmentTreeNode` object is being returned. It is of type
* `SegmentTreeNode` or `undefined`.
*/
get left(): SegmentTreeNode | undefined;
/**
* The function sets the value of the left property of a SegmentTreeNode object.
* @param {SegmentTreeNode | undefined} value - The value parameter is of type SegmentTreeNode or
* undefined.
*/
set left(value: SegmentTreeNode | undefined);
protected _right: SegmentTreeNode | undefined;
/**
* The function returns the right child of a segment tree node.
* @returns The `getRight()` method is returning a value of type `SegmentTreeNode` or `undefined`.
*/
get right(): SegmentTreeNode | undefined;
/**
* The function sets the right child of a segment tree node.
* @param {SegmentTreeNode | undefined} value - The `value` parameter is of type `SegmentTreeNode |
* undefined`. This means that it can accept either a `SegmentTreeNode` object or `undefined` as its
* value.
*/
set right(value: SegmentTreeNode | undefined);
}
export declare class SegmentTree {
/**
* The constructor initializes the values, start, end, and root properties of an object.
* @param {number[]} values - An array of numbers that will be used to build a binary search tree.
* @param {number} [start] - The `start` parameter is the index of the first element in the `values` array that should
* be included in the range. If no value is provided for `start`, it defaults to 0, which means the range starts from
* the beginning of the array.
* @param {number} [end] - The "end" parameter is the index of the last element in the "values" array that should be
* included in the range. If not provided, it defaults to the index of the last element in the "values" array.
*/
constructor(values: number[], start?: number, end?: number);
protected _values: number[];
/**
* The function returns an array of numbers.
* @returns An array of numbers is being returned.
*/
get values(): number[];
protected _start: number;
/**
* The function returns the value of the protected variable _start.
* @returns The start value, which is of type number.
*/
get start(): number;
protected _end: number;
/**
* The function returns the value of the protected variable `_end`.
* @returns The value of the protected property `_end`.
*/
get end(): number;
protected _root: SegmentTreeNode | undefined;
/**
* The function returns the root node of a segment tree.
* @returns The `root` property of the class `SegmentTreeNode` or `undefined` if it is not defined.
*/
get root(): SegmentTreeNode | undefined;
/**
* The build function creates a segment tree by recursively dividing the given range into smaller segments and assigning
* the sum of values to each segment.
* @param {number} start - The `start` parameter represents the starting index of the segment or range for which we are
* building the segment tree.
* @param {number} end - The "end" parameter represents the ending index of the segment or range for which we want to
* build a segment tree.
* @returns a SegmentTreeNode object.
*/
build(start: number, end: number): SegmentTreeNode;
/**
* The function updates the value of a node in a segment tree and recalculates the sum of its children if they exist.
* @param {number} index - The index parameter represents the index of the node in the segment tree that needs to be
* updated.
* @param {number} sum - The `sum` parameter represents the new value that should be assigned to the `sum` property of
* the `SegmentTreeNode` at the specified `index`.
* @param {SegmentTreeNodeVal} [value] - The `value` parameter is an optional value that can be assigned to the `value`
* property of the `SegmentTreeNode` object. It is not currently used in the code, but you can uncomment the line `//
* cur.value = value;` and pass a value for `value` in the
* @returns The function does not return anything.
*/
updateNode(index: number, sum: number, value?: SegmentTreeNodeVal): void;
/**
* The function `querySumByRange` calculates the sum of values within a given range in a segment tree.
* @param {number} indexA - The starting index of the range for which you want to calculate the sum.
* @param {number} indexB - The parameter `indexB` represents the ending index of the range for which you want to
* calculate the sum.
* @returns The function `querySumByRange` returns a number.
*/
querySumByRange(indexA: number, indexB: number): number;
}