C# Class Utils.tree.FenwickTree

Datei anzeigen Open project: eric7237cire/CodeJam

Public Methods

Method Description
AdjustIndexBy ( int index, int valueToAdd, int mod = int.MaxValue ) : void
FenwickTree ( int n ) : System
SumFromTo ( int left, int right, int mod = int.MaxValue ) : int
SumTo ( int ft, int right, int mod = int.MaxValue ) : int

Returns cumulative sum from [1, right]

findAnyIndexWithFreq ( int cumFre ) : int
findLowestIndexWithFreq ( int cumFre ) : int

Private Methods

Method Description
SubtractLeastSignificantBit ( int S ) : int
msb32 ( int x ) : int

Given a binary integer value x, the most significant 1 bit (highest numbered element of a bit set) can be computed using a SWAR algorithm that recursively "folds" the upper bits into the lower bits. This process yields a bit vector with the same most significant 1 as x, but all 1's below it. Bitwise AND of the original value with the complement of the "folded" value shifted down by one yields the most significant bit. For a 32-bit value:

Method Details

AdjustIndexBy() public method

public AdjustIndexBy ( int index, int valueToAdd, int mod = int.MaxValue ) : void
index int
valueToAdd int
mod int
return void

FenwickTree() public method

public FenwickTree ( int n ) : System
n int
return System

SumFromTo() public method

public SumFromTo ( int left, int right, int mod = int.MaxValue ) : int
left int
right int
mod int
return int

SumTo() public static method

Returns cumulative sum from [1, right]
public static SumTo ( int ft, int right, int mod = int.MaxValue ) : int
ft int
right int
mod int
return int

findAnyIndexWithFreq() public method

public findAnyIndexWithFreq ( int cumFre ) : int
cumFre int
return int

findLowestIndexWithFreq() public method

public findLowestIndexWithFreq ( int cumFre ) : int
cumFre int
return int