-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated structure LineInfo for more effective CSV hanling
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "FenwickTree.h" | ||
#include <Windows.h> | ||
|
||
// Constructor: Initialize with 0 size. | ||
FenwickTree::FenwickTree() : _size(0) {} | ||
|
||
// Initialize the Fenwick Tree with a given size (1-based indexing). | ||
void FenwickTree::init(size_t n) { | ||
_size = n; | ||
fenwicksum.assign(n + 1, 0); // 1 extra for 1-based indexing | ||
} | ||
|
||
// Update: Add 'delta' to all elements >= index (1-based indexing). | ||
void FenwickTree::update(size_t index, LRESULT delta) { | ||
while (index <= _size) { | ||
fenwicksum[index] += delta; | ||
index += static_cast<size_t>(index & -static_cast<std::make_signed_t<size_t>>(index)); // move to the next node | ||
} | ||
} | ||
|
||
// Query: Get the prefix sum from 1 to index (1-based indexing). | ||
LRESULT FenwickTree::prefixSum(size_t index) const { | ||
LRESULT result = 0; | ||
while (index > 0) { | ||
result += fenwicksum[index]; | ||
index -= static_cast<size_t>(index & -static_cast<std::make_signed_t<size_t>>(index)); // move to the parent node | ||
} | ||
return result; | ||
} | ||
|
||
// Get the size of the Fenwick Tree. | ||
size_t FenwickTree::size() const { | ||
return _size; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef FENWICKTREE_H | ||
#define FENWICKTREE_H | ||
|
||
#include <vector> | ||
#include <cstddef> // for size_t | ||
#include <Windows.h> | ||
|
||
// FenwickTree (Binary Indexed Tree) for efficient prefix sum calculations. | ||
class FenwickTree { | ||
private: | ||
std::vector<LRESULT> fenwicksum; | ||
size_t _size; | ||
|
||
public: | ||
FenwickTree(); | ||
void init(size_t n); | ||
void update(size_t index, LRESULT delta); | ||
LRESULT prefixSum(size_t index) const; | ||
size_t size() const; | ||
}; | ||
|
||
#endif // FENWICKTREE_H |