# SegmentTree | data-structure-typed
Documentation for data-structure-typed

# Class SegmentTree

#### Hierarchy

- SegmentTree

- Defined in src/data-structures/binary-tree/segment-tree.ts:79

#####
Index

### Constructors

constructor

### Properties

_end
_root
_start
_values

### Accessors

end
root
start
values

### Methods

_setEnd
_setRoot
_setStart
_setValues
build
querySumByRange
updateNode

## Constructors

### constructor

- new SegmentTree(values, start?, end?): SegmentTree

- The constructor initializes the values, start, end, and root properties of an object.

  #### Parameters

  - ##### values: number[]

    An array of numbers that will be used to build a binary search tree.

  - ##### `Optional` start: number

    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.

  - ##### `Optional` end: number

    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.

  #### Returns SegmentTree

  - Defined in src/data-structures/binary-tree/segment-tree.ts:89

## Properties

### `Private` _end

_end: number

- Defined in src/data-structures/binary-tree/segment-tree.ts:109

### `Private` _root

_root: null | SegmentTreeNode

- Defined in src/data-structures/binary-tree/segment-tree.ts:115

### `Private` _start

_start: number = 0

- Defined in src/data-structures/binary-tree/segment-tree.ts:104

### `Private` _values

_values: number[] = []

- Defined in src/data-structures/binary-tree/segment-tree.ts:98

## Accessors

### end

- get end(): number

- #### Returns number

  - Defined in src/data-structures/binary-tree/segment-tree.ts:111

### root

- get root(): null | SegmentTreeNode

- #### Returns null | SegmentTreeNode

  - Defined in src/data-structures/binary-tree/segment-tree.ts:117

### start

- get start(): number

- #### Returns number

  - Defined in src/data-structures/binary-tree/segment-tree.ts:105

### values

- get values(): number[]

- #### Returns number[]

  - Defined in src/data-structures/binary-tree/segment-tree.ts:100

## Methods

### `Protected` _setEnd

- _setEnd(value): void

- #### Parameters

  - ##### value: number

  #### Returns void

  - Defined in src/data-structures/binary-tree/segment-tree.ts:235

### `Protected` _setRoot

- _setRoot(v): void

- #### Parameters

  - ##### v: null | SegmentTreeNode

  #### Returns void

  - Defined in src/data-structures/binary-tree/segment-tree.ts:239

### `Protected` _setStart

- _setStart(value): void

- #### Parameters

  - ##### value: number

  #### Returns void

  - Defined in src/data-structures/binary-tree/segment-tree.ts:231

### `Protected` _setValues

- _setValues(value): void

- #### Parameters

  - ##### value: number[]

  #### Returns void

  - Defined in src/data-structures/binary-tree/segment-tree.ts:227

### build

- build(start, end): SegmentTreeNode

- The function builds a segment tree by recursively dividing the given range into smaller segments and creating nodes for each segment.

  #### Parameters

  - ##### start: number

    The `start` parameter represents the starting index of the segment or range for which we are building the segment tree.

  - ##### end: number

    The `end` parameter represents the ending index of the segment or range for which we are building the segment tree.

  #### Returns SegmentTreeNode

  a SegmentTreeNode object.

  - Defined in src/data-structures/binary-tree/segment-tree.ts:130

### querySumByRange

- querySumByRange(indexA, indexB): number

- The function `querySumByRange` calculates the sum of values within a given range in a segment tree.

  #### Parameters

  - ##### indexA: number

    The starting index of the range for which you want to calculate the sum.

  - ##### indexB: number

    The parameter `indexB` represents the ending index of the range for which you want to calculate the sum.

  #### Returns number

  The function `querySumByRange` returns a number.

  - Defined in src/data-structures/binary-tree/segment-tree.ts:189

### updateNode

- updateNode(index, sum, val?): void

- The function updates the value of a node in a segment tree and recalculates the sum of its children if they exist.

  #### Parameters

  - ##### index: number

    The index parameter represents the index of the node in the segment tree that needs to be updated.

  - ##### sum: number

    The `sum` parameter represents the new value that should be assigned to the `sum` property of the `SegmentTreeNode` at the specified `index`.

  - ##### `Optional` val: number

    The `val` parameter is an optional value that can be assigned to the `val` property of the `SegmentTreeNode` object. It is not currently used in the code, but you can uncomment the line `// cur.val = val;` and pass a value for `val` in the

  #### Returns void

  The function does not return anything.

  - Defined in src/data-structures/binary-tree/segment-tree.ts:153

Generated using TypeDoc