Skip to main content

CloberSegmentedSegmentTree

CloberSegmentedSegmentTree

uint64 values are stored here to efficiently query the sum of a given range. A total of 32768 values can be stored in the segment tree. A query will require at most 14 storage reads, and an update to the tree will require 4 storage writes. The sum of all nodes should not exceed uint64.

update

function update(uint256 index, uint64 value) external returns (uint64)

Updates the value at the specified index in the segment tree.

Parameters

NameTypeDescription
indexuint256The index of the value to update.
valueuint64The value to update with.

Return Values

NameTypeDescription
[0]uint64The value that was replaced by the update.

get

function get(uint256 index) external view returns (uint64)

Gets the value at the specified index in the segment tree.

Parameters

NameTypeDescription
indexuint256The index of the value to get.

Return Values

NameTypeDescription
[0]uint64The value at the specified index in the segment tree.

total

function total() external view returns (uint256)

Calculates the sum of all values in the segment tree.

Return Values

NameTypeDescription
[0]uint256The sum of all values in the segment tree.

query

function query(uint256 left, uint256 right) external view returns (uint256)

Calculates the sum of the values in the segment tree within the specified range.

Parameters

NameTypeDescription
leftuint256The starting index (inclusive) of the values to sum.
rightuint256The ending index (exclusive) of the values to sum.

Return Values

NameTypeDescription
[0]uint256The sum of the values in the segment tree within the specified range.