Constructors

  • 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

Accessors

  • get end(): number
  • The function returns the value of the protected variable _end.

    Returns number

    The value of the protected property _end.

  • get start(): number
  • The function returns the value of the protected variable _start.

    Returns number

    The start value, which is of type number.

  • get values(): number[]
  • The function returns an array of numbers.

    Returns number[]

    An array of numbers is being returned.

Methods

  • 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.

    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 want to build a segment tree.

    Returns SegmentTreeNode

    a SegmentTreeNode object.

  • 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.

  • 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 value: number

      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 void

    The function does not return anything.

Generated using TypeDoc