Advanced Chunk Processing Library 0.2.0
A comprehensive C++ library for advanced data chunking strategies and processing operations
Loading...
Searching...
No Matches
wavelet_chunking.hpp
Go to the documentation of this file.
1template <typename T>
3public:
4 WaveletChunking(size_t window_size, double threshold)
5 : window_size_(window_size), threshold_(threshold) {
6 if (window_size == 0) {
7 throw std::invalid_argument("Window size cannot be zero");
8 }
9 }
10
11 void set_window_size(size_t new_size) {
12 if (new_size == 0) {
13 throw std::invalid_argument("Window size cannot be zero");
14 }
15 window_size_ = new_size;
16 }
17
18 void set_threshold(double new_threshold) {
19 threshold_ = new_threshold;
20 }
21
22 std::vector<std::vector<T>> chunk(const std::vector<T>& data) {
23 if (data.empty()) {
24 throw std::invalid_argument("Cannot chunk empty data");
25 }
26
27 std::vector<std::vector<T>> result;
28 std::vector<T> current_chunk;
29
30 for (size_t i = 0; i < data.size(); ++i) {
31 current_chunk.push_back(data[i]);
32
33 if (current_chunk.size() >= window_size_) {
34 // Perform wavelet analysis to detect boundaries
35 if (detect_boundary(current_chunk)) {
36 result.push_back(current_chunk);
37 current_chunk.clear();
38 }
39 }
40 }
41
42 if (!current_chunk.empty()) {
43 result.push_back(current_chunk);
44 }
45
46 return result;
47 }
48
49private:
51 double threshold_;
52
53 bool detect_boundary(const std::vector<T>& window) {
54 if (window.size() < 2)
55 return false;
56
57 // Simple boundary detection based on value differences
58 double max_diff = 0.0;
59 for (size_t i = 1; i < window.size(); ++i) {
60 max_diff = std::max(max_diff, std::abs(static_cast<double>(window[i] - window[i - 1])));
61 }
62 return max_diff > threshold_;
63 }
64};
#define CHUNK_EXPORT
bool detect_boundary(const std::vector< T > &window)
std::vector< std::vector< T > > chunk(const std::vector< T > &data)
void set_window_size(size_t new_size)
void set_threshold(double new_threshold)
WaveletChunking(size_t window_size, double threshold)