explodethosebits 0.3.0__cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- etb/__init__.py +351 -0
- etb/__init__.pyi +976 -0
- etb/_etb.cpython-39-x86_64-linux-gnu.so +0 -0
- etb/_version.py +34 -0
- etb/py.typed +2 -0
- explodethosebits-0.3.0.dist-info/METADATA +405 -0
- explodethosebits-0.3.0.dist-info/RECORD +88 -0
- explodethosebits-0.3.0.dist-info/WHEEL +6 -0
- explodethosebits-0.3.0.dist-info/licenses/LICENSE +21 -0
- explodethosebits-0.3.0.dist-info/sboms/auditwheel.cdx.json +1 -0
- explodethosebits.libs/libcudart-c3a75b33.so.12.8.90 +0 -0
- include/etb/bit_coordinate.hpp +45 -0
- include/etb/bit_extraction.hpp +79 -0
- include/etb/bit_pruning.hpp +122 -0
- include/etb/config.hpp +284 -0
- include/etb/cuda/arch_optimizations.cuh +358 -0
- include/etb/cuda/blackwell_optimizations.cuh +300 -0
- include/etb/cuda/cuda_common.cuh +265 -0
- include/etb/cuda/etb_cuda.cuh +200 -0
- include/etb/cuda/gpu_memory.cuh +406 -0
- include/etb/cuda/heuristics_kernel.cuh +315 -0
- include/etb/cuda/path_generator_kernel.cuh +272 -0
- include/etb/cuda/prefix_pruner_kernel.cuh +370 -0
- include/etb/cuda/signature_kernel.cuh +328 -0
- include/etb/early_stopping.hpp +246 -0
- include/etb/etb.hpp +20 -0
- include/etb/heuristics.hpp +165 -0
- include/etb/memoization.hpp +285 -0
- include/etb/path.hpp +86 -0
- include/etb/path_count.hpp +87 -0
- include/etb/path_generator.hpp +175 -0
- include/etb/prefix_trie.hpp +339 -0
- include/etb/reporting.hpp +437 -0
- include/etb/scoring.hpp +269 -0
- include/etb/signature.hpp +190 -0
- include/gmock/gmock-actions.h +2297 -0
- include/gmock/gmock-cardinalities.h +159 -0
- include/gmock/gmock-function-mocker.h +518 -0
- include/gmock/gmock-matchers.h +5623 -0
- include/gmock/gmock-more-actions.h +658 -0
- include/gmock/gmock-more-matchers.h +120 -0
- include/gmock/gmock-nice-strict.h +277 -0
- include/gmock/gmock-spec-builders.h +2148 -0
- include/gmock/gmock.h +96 -0
- include/gmock/internal/custom/README.md +18 -0
- include/gmock/internal/custom/gmock-generated-actions.h +7 -0
- include/gmock/internal/custom/gmock-matchers.h +37 -0
- include/gmock/internal/custom/gmock-port.h +40 -0
- include/gmock/internal/gmock-internal-utils.h +487 -0
- include/gmock/internal/gmock-port.h +139 -0
- include/gmock/internal/gmock-pp.h +279 -0
- include/gtest/gtest-assertion-result.h +237 -0
- include/gtest/gtest-death-test.h +345 -0
- include/gtest/gtest-matchers.h +923 -0
- include/gtest/gtest-message.h +252 -0
- include/gtest/gtest-param-test.h +546 -0
- include/gtest/gtest-printers.h +1161 -0
- include/gtest/gtest-spi.h +250 -0
- include/gtest/gtest-test-part.h +192 -0
- include/gtest/gtest-typed-test.h +331 -0
- include/gtest/gtest.h +2321 -0
- include/gtest/gtest_pred_impl.h +279 -0
- include/gtest/gtest_prod.h +60 -0
- include/gtest/internal/custom/README.md +44 -0
- include/gtest/internal/custom/gtest-port.h +37 -0
- include/gtest/internal/custom/gtest-printers.h +42 -0
- include/gtest/internal/custom/gtest.h +37 -0
- include/gtest/internal/gtest-death-test-internal.h +307 -0
- include/gtest/internal/gtest-filepath.h +227 -0
- include/gtest/internal/gtest-internal.h +1560 -0
- include/gtest/internal/gtest-param-util.h +1026 -0
- include/gtest/internal/gtest-port-arch.h +122 -0
- include/gtest/internal/gtest-port.h +2481 -0
- include/gtest/internal/gtest-string.h +178 -0
- include/gtest/internal/gtest-type-util.h +220 -0
- lib/libetb_core.a +0 -0
- lib64/cmake/GTest/GTestConfig.cmake +33 -0
- lib64/cmake/GTest/GTestConfigVersion.cmake +43 -0
- lib64/cmake/GTest/GTestTargets-release.cmake +49 -0
- lib64/cmake/GTest/GTestTargets.cmake +139 -0
- lib64/libgmock.a +0 -0
- lib64/libgmock_main.a +0 -0
- lib64/libgtest.a +0 -0
- lib64/libgtest_main.a +0 -0
- lib64/pkgconfig/gmock.pc +10 -0
- lib64/pkgconfig/gmock_main.pc +10 -0
- lib64/pkgconfig/gtest.pc +9 -0
- lib64/pkgconfig/gtest_main.pc +10 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#ifndef ETB_BIT_EXTRACTION_HPP
|
|
2
|
+
#define ETB_BIT_EXTRACTION_HPP
|
|
3
|
+
|
|
4
|
+
#include "path.hpp"
|
|
5
|
+
#include <vector>
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
|
|
8
|
+
namespace etb {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Bit Extraction Engine - CPU Reference Implementation
|
|
12
|
+
*
|
|
13
|
+
* Provides functions for converting between paths (bit coordinates) and byte sequences.
|
|
14
|
+
* This is the core functionality for extracting and reconstructing bit combinations.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Extract a single bit from a byte array at the given coordinate.
|
|
19
|
+
* @param data The input byte array
|
|
20
|
+
* @param coord The bit coordinate to extract
|
|
21
|
+
* @return The bit value (0 or 1)
|
|
22
|
+
* @throws std::out_of_range if coordinate is out of bounds
|
|
23
|
+
*/
|
|
24
|
+
uint8_t extract_bit(const std::vector<uint8_t>& data, const BitCoordinate& coord);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Extract a single bit from a byte array at the given coordinate.
|
|
28
|
+
* @param data Pointer to the input byte array
|
|
29
|
+
* @param data_length Length of the input byte array
|
|
30
|
+
* @param coord The bit coordinate to extract
|
|
31
|
+
* @return The bit value (0 or 1)
|
|
32
|
+
* @throws std::out_of_range if coordinate is out of bounds
|
|
33
|
+
*/
|
|
34
|
+
uint8_t extract_bit(const uint8_t* data, size_t data_length, const BitCoordinate& coord);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Extract bits at specified path coordinates from a byte array.
|
|
38
|
+
* Returns the extracted bit values in order.
|
|
39
|
+
*
|
|
40
|
+
* @param data The input byte array
|
|
41
|
+
* @param path The path containing coordinates to extract
|
|
42
|
+
* @return Vector of bit values (0 or 1) in path order
|
|
43
|
+
* @throws std::out_of_range if any coordinate is out of bounds
|
|
44
|
+
*/
|
|
45
|
+
std::vector<uint8_t> extract_bits_from_path(const std::vector<uint8_t>& data, const Path& path);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Convert a sequence of bits to a byte array.
|
|
49
|
+
* Bits are packed into bytes with the first bit going to the MSB of the first byte.
|
|
50
|
+
* If the number of bits is not a multiple of 8, the last byte is zero-padded on the right.
|
|
51
|
+
*
|
|
52
|
+
* @param bits Vector of bit values (0 or 1)
|
|
53
|
+
* @return Packed byte array
|
|
54
|
+
*/
|
|
55
|
+
std::vector<uint8_t> bits_to_bytes(const std::vector<uint8_t>& bits);
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Convert a path with associated bit values to a byte array.
|
|
59
|
+
* This extracts bits from the source data at path coordinates and packs them into bytes.
|
|
60
|
+
*
|
|
61
|
+
* @param source_data The source byte array to extract bits from
|
|
62
|
+
* @param path The path specifying which bit coordinates to extract
|
|
63
|
+
* @return Packed byte array of extracted bits
|
|
64
|
+
* @throws std::out_of_range if any coordinate is out of bounds
|
|
65
|
+
*/
|
|
66
|
+
std::vector<uint8_t> path_to_bytes(const std::vector<uint8_t>& source_data, const Path& path);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Convert a byte array to a sequence of bits.
|
|
70
|
+
* Each byte is unpacked to 8 bits, MSB first.
|
|
71
|
+
*
|
|
72
|
+
* @param bytes The input byte array
|
|
73
|
+
* @return Vector of bit values (0 or 1)
|
|
74
|
+
*/
|
|
75
|
+
std::vector<uint8_t> bytes_to_bits(const std::vector<uint8_t>& bytes);
|
|
76
|
+
|
|
77
|
+
} // namespace etb
|
|
78
|
+
|
|
79
|
+
#endif // ETB_BIT_EXTRACTION_HPP
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#ifndef ETB_BIT_PRUNING_HPP
|
|
2
|
+
#define ETB_BIT_PRUNING_HPP
|
|
3
|
+
|
|
4
|
+
#include <cstdint>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <vector>
|
|
7
|
+
#include <optional>
|
|
8
|
+
|
|
9
|
+
namespace etb {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Bit pruning modes that control which bit positions are explored.
|
|
13
|
+
* These modes reduce the search space from O(8^d) to smaller complexities.
|
|
14
|
+
*/
|
|
15
|
+
enum class BitPruningMode {
|
|
16
|
+
EXHAUSTIVE, // All 8 bit positions (O(8^d)) - bit_mask = 0xFF
|
|
17
|
+
MSB_ONLY, // Only bits 4-7 (O(4^d)) - bit_mask = 0xF0
|
|
18
|
+
SINGLE_BIT, // Only 2 configured bit positions (O(2^d))
|
|
19
|
+
CUSTOM // User-defined bit mask
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Configuration for the bit pruning system.
|
|
24
|
+
* Controls which bit positions are allowed during path generation.
|
|
25
|
+
*/
|
|
26
|
+
struct BitPruningConfig {
|
|
27
|
+
BitPruningMode mode;
|
|
28
|
+
uint8_t bit_mask; // Bitmask of allowed positions (bit N set = position N allowed)
|
|
29
|
+
std::vector<uint8_t> single_bits; // For SINGLE_BIT mode: which 2 positions to use
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Default constructor - exhaustive mode (all bits allowed).
|
|
33
|
+
*/
|
|
34
|
+
BitPruningConfig();
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Construct with a specific mode.
|
|
38
|
+
*/
|
|
39
|
+
explicit BitPruningConfig(BitPruningMode mode);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Construct with a custom bit mask.
|
|
43
|
+
*/
|
|
44
|
+
explicit BitPruningConfig(uint8_t custom_mask);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Construct single-bit mode with specified positions.
|
|
48
|
+
* @param bit1 First bit position (0-7)
|
|
49
|
+
* @param bit2 Second bit position (0-7)
|
|
50
|
+
*/
|
|
51
|
+
BitPruningConfig(uint8_t bit1, uint8_t bit2);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Check if a bit position is allowed by this configuration.
|
|
55
|
+
* @param bit_pos Bit position (0-7)
|
|
56
|
+
* @return true if the position is allowed
|
|
57
|
+
*/
|
|
58
|
+
bool is_bit_allowed(uint8_t bit_pos) const;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Get the number of allowed bit positions.
|
|
62
|
+
* @return Count of set bits in the mask
|
|
63
|
+
*/
|
|
64
|
+
uint8_t allowed_bit_count() const;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get all allowed bit positions.
|
|
68
|
+
* @return Vector of allowed positions (0-7)
|
|
69
|
+
*/
|
|
70
|
+
std::vector<uint8_t> get_allowed_positions() const;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get the effective branching factor for complexity analysis.
|
|
74
|
+
* @return Number of choices per byte level
|
|
75
|
+
*/
|
|
76
|
+
uint8_t branching_factor() const;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get a human-readable description of the configuration.
|
|
80
|
+
*/
|
|
81
|
+
std::string description() const;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Validate the configuration.
|
|
85
|
+
* @return true if configuration is valid
|
|
86
|
+
*/
|
|
87
|
+
bool is_valid() const;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get the bit mask for use with PathGeneratorConfig.
|
|
91
|
+
*/
|
|
92
|
+
uint8_t get_mask() const { return bit_mask; }
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Parse a bit pruning mode from a string.
|
|
97
|
+
* @param mode_str Mode string: "exhaustive", "msb_only", "single_bit", "custom"
|
|
98
|
+
* @return Parsed mode, or std::nullopt if invalid
|
|
99
|
+
*/
|
|
100
|
+
std::optional<BitPruningMode> parse_bit_pruning_mode(const std::string& mode_str);
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Convert a bit pruning mode to string.
|
|
104
|
+
*/
|
|
105
|
+
std::string bit_pruning_mode_to_string(BitPruningMode mode);
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Create a BitPruningConfig from a mode string and optional mask.
|
|
109
|
+
* @param mode_str Mode string
|
|
110
|
+
* @param custom_mask Optional custom mask (used when mode is "custom")
|
|
111
|
+
* @param single_bits Optional single bit positions (used when mode is "single_bit")
|
|
112
|
+
* @return Configured BitPruningConfig, or std::nullopt if invalid
|
|
113
|
+
*/
|
|
114
|
+
std::optional<BitPruningConfig> create_bit_pruning_config(
|
|
115
|
+
const std::string& mode_str,
|
|
116
|
+
std::optional<uint8_t> custom_mask = std::nullopt,
|
|
117
|
+
std::optional<std::pair<uint8_t, uint8_t>> single_bits = std::nullopt
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
} // namespace etb
|
|
121
|
+
|
|
122
|
+
#endif // ETB_BIT_PRUNING_HPP
|
include/etb/config.hpp
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
#ifndef ETB_CONFIG_HPP
|
|
2
|
+
#define ETB_CONFIG_HPP
|
|
3
|
+
|
|
4
|
+
#include <cstdint>
|
|
5
|
+
#include <cstddef>
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <vector>
|
|
8
|
+
#include <optional>
|
|
9
|
+
#include <mutex>
|
|
10
|
+
#include <functional>
|
|
11
|
+
#include <atomic>
|
|
12
|
+
#include "heuristics.hpp"
|
|
13
|
+
#include "early_stopping.hpp"
|
|
14
|
+
#include "bit_pruning.hpp"
|
|
15
|
+
#include "scoring.hpp"
|
|
16
|
+
#include "memoization.hpp"
|
|
17
|
+
|
|
18
|
+
namespace etb {
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Error codes for configuration operations.
|
|
22
|
+
*/
|
|
23
|
+
enum class ConfigError {
|
|
24
|
+
NONE = 0,
|
|
25
|
+
FILE_NOT_FOUND,
|
|
26
|
+
PARSE_ERROR,
|
|
27
|
+
INVALID_VALUE,
|
|
28
|
+
MISSING_REQUIRED_FIELD,
|
|
29
|
+
TYPE_MISMATCH,
|
|
30
|
+
OUT_OF_RANGE
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Result of a configuration operation.
|
|
35
|
+
*/
|
|
36
|
+
struct ConfigResult {
|
|
37
|
+
bool success;
|
|
38
|
+
ConfigError error;
|
|
39
|
+
std::string message;
|
|
40
|
+
|
|
41
|
+
ConfigResult() : success(true), error(ConfigError::NONE) {}
|
|
42
|
+
ConfigResult(ConfigError err, const std::string& msg)
|
|
43
|
+
: success(false), error(err), message(msg) {}
|
|
44
|
+
|
|
45
|
+
static ConfigResult ok() { return ConfigResult(); }
|
|
46
|
+
static ConfigResult fail(ConfigError err, const std::string& msg) {
|
|
47
|
+
return ConfigResult(err, msg);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Output configuration options.
|
|
53
|
+
*/
|
|
54
|
+
struct OutputConfig {
|
|
55
|
+
uint32_t top_n_results; // Number of top results to return (default: 10)
|
|
56
|
+
bool save_partials; // Save partial matches (default: false)
|
|
57
|
+
bool include_paths; // Include reconstruction paths in output (default: true)
|
|
58
|
+
std::string metrics_verbosity; // "minimal", "standard", "full" (default: "full")
|
|
59
|
+
|
|
60
|
+
OutputConfig()
|
|
61
|
+
: top_n_results(10)
|
|
62
|
+
, save_partials(false)
|
|
63
|
+
, include_paths(true)
|
|
64
|
+
, metrics_verbosity("full") {}
|
|
65
|
+
|
|
66
|
+
bool is_valid() const;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Performance configuration options.
|
|
71
|
+
*/
|
|
72
|
+
struct PerformanceConfig {
|
|
73
|
+
uint32_t max_parallel_workers; // CPU threads for host coordination (default: 8)
|
|
74
|
+
uint32_t cuda_streams; // Concurrent CUDA streams (default: 4)
|
|
75
|
+
uint32_t batch_size; // Paths per kernel launch (default: 65536)
|
|
76
|
+
|
|
77
|
+
PerformanceConfig()
|
|
78
|
+
: max_parallel_workers(8)
|
|
79
|
+
, cuda_streams(4)
|
|
80
|
+
, batch_size(65536) {}
|
|
81
|
+
|
|
82
|
+
bool is_valid() const;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Complete configuration for the etb library.
|
|
88
|
+
* Aggregates all component configurations.
|
|
89
|
+
*/
|
|
90
|
+
struct EtbConfig {
|
|
91
|
+
// Paths
|
|
92
|
+
std::string signature_dictionary_path;
|
|
93
|
+
|
|
94
|
+
// Component configurations
|
|
95
|
+
EarlyStoppingConfig early_stopping;
|
|
96
|
+
HeuristicWeights heuristic_weights;
|
|
97
|
+
ScoringWeights scoring_weights;
|
|
98
|
+
BitPruningConfig bit_pruning;
|
|
99
|
+
MemoizationConfig memoization;
|
|
100
|
+
OutputConfig output;
|
|
101
|
+
PerformanceConfig performance;
|
|
102
|
+
|
|
103
|
+
// Entropy thresholds (separate from early stopping for clarity)
|
|
104
|
+
float entropy_min; // Below this = repeated pattern garbage (default: 0.1)
|
|
105
|
+
float entropy_max; // Above this = random/encrypted (default: 7.9)
|
|
106
|
+
|
|
107
|
+
// Text detection thresholds
|
|
108
|
+
float min_printable_ratio; // For text detection (default: 0.95)
|
|
109
|
+
uint32_t max_null_run; // Max consecutive nulls before penalty (default: 16)
|
|
110
|
+
|
|
111
|
+
EtbConfig();
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Validate the entire configuration.
|
|
115
|
+
* @return ConfigResult with success/failure and error details
|
|
116
|
+
*/
|
|
117
|
+
ConfigResult validate() const;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Callback type for configuration change notifications.
|
|
122
|
+
*/
|
|
123
|
+
using ConfigChangeCallback = std::function<void(const EtbConfig&)>;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Configuration loader and manager.
|
|
127
|
+
* Supports JSON and YAML formats, runtime updates, and hot-reload.
|
|
128
|
+
*
|
|
129
|
+
* Requirements: 11.1, 11.2, 11.3, 11.4, 2.7
|
|
130
|
+
*/
|
|
131
|
+
class ConfigManager {
|
|
132
|
+
public:
|
|
133
|
+
/**
|
|
134
|
+
* Get the singleton instance.
|
|
135
|
+
*/
|
|
136
|
+
static ConfigManager& instance();
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Load configuration from a JSON file.
|
|
140
|
+
* @param filepath Path to the JSON configuration file
|
|
141
|
+
* @return ConfigResult with success/failure and error details
|
|
142
|
+
*/
|
|
143
|
+
ConfigResult load_json(const std::string& filepath);
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Load configuration from a JSON string.
|
|
147
|
+
* @param json_content JSON content as string
|
|
148
|
+
* @return ConfigResult with success/failure and error details
|
|
149
|
+
*/
|
|
150
|
+
ConfigResult load_json_string(const std::string& json_content);
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Load configuration from a YAML file.
|
|
154
|
+
* @param filepath Path to the YAML configuration file
|
|
155
|
+
* @return ConfigResult with success/failure and error details
|
|
156
|
+
*/
|
|
157
|
+
ConfigResult load_yaml(const std::string& filepath);
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Load configuration from a YAML string.
|
|
161
|
+
* @param yaml_content YAML content as string
|
|
162
|
+
* @return ConfigResult with success/failure and error details
|
|
163
|
+
*/
|
|
164
|
+
ConfigResult load_yaml_string(const std::string& yaml_content);
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Get the current configuration (thread-safe read).
|
|
168
|
+
* @return Copy of the current configuration
|
|
169
|
+
*/
|
|
170
|
+
EtbConfig get_config() const;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Set the configuration (thread-safe write).
|
|
174
|
+
* @param config New configuration to set
|
|
175
|
+
* @return ConfigResult with validation result
|
|
176
|
+
*/
|
|
177
|
+
ConfigResult set_config(const EtbConfig& config);
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Update a specific configuration value at runtime.
|
|
181
|
+
* Only certain parameters support hot-reload.
|
|
182
|
+
* @param key Configuration key (e.g., "early_stopping.level1_threshold")
|
|
183
|
+
* @param value New value as string
|
|
184
|
+
* @return ConfigResult with success/failure
|
|
185
|
+
*/
|
|
186
|
+
ConfigResult update_value(const std::string& key, const std::string& value);
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Register a callback for configuration changes.
|
|
190
|
+
* @param callback Function to call when configuration changes
|
|
191
|
+
* @return ID for unregistering the callback
|
|
192
|
+
*/
|
|
193
|
+
size_t register_change_callback(ConfigChangeCallback callback);
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Unregister a configuration change callback.
|
|
197
|
+
* @param id Callback ID returned by register_change_callback
|
|
198
|
+
*/
|
|
199
|
+
void unregister_change_callback(size_t id);
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Reload configuration from the last loaded file.
|
|
203
|
+
* @return ConfigResult with success/failure
|
|
204
|
+
*/
|
|
205
|
+
ConfigResult reload();
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Check if a configuration file has been loaded.
|
|
209
|
+
*/
|
|
210
|
+
bool is_loaded() const { return loaded_.load(); }
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Get the path of the last loaded configuration file.
|
|
214
|
+
*/
|
|
215
|
+
std::string get_loaded_path() const;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Reset to default configuration.
|
|
219
|
+
*/
|
|
220
|
+
void reset_to_defaults();
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Save current configuration to a JSON file.
|
|
224
|
+
* @param filepath Path to save to
|
|
225
|
+
* @return ConfigResult with success/failure
|
|
226
|
+
*/
|
|
227
|
+
ConfigResult save_json(const std::string& filepath) const;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Save current configuration to a YAML file.
|
|
231
|
+
* @param filepath Path to save to
|
|
232
|
+
* @return ConfigResult with success/failure
|
|
233
|
+
*/
|
|
234
|
+
ConfigResult save_yaml(const std::string& filepath) const;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Get configuration as JSON string.
|
|
238
|
+
*/
|
|
239
|
+
std::string to_json_string() const;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Get configuration as YAML string.
|
|
243
|
+
*/
|
|
244
|
+
std::string to_yaml_string() const;
|
|
245
|
+
|
|
246
|
+
private:
|
|
247
|
+
ConfigManager();
|
|
248
|
+
~ConfigManager() = default;
|
|
249
|
+
ConfigManager(const ConfigManager&) = delete;
|
|
250
|
+
ConfigManager& operator=(const ConfigManager&) = delete;
|
|
251
|
+
|
|
252
|
+
mutable std::mutex mutex_;
|
|
253
|
+
EtbConfig config_;
|
|
254
|
+
std::string loaded_path_;
|
|
255
|
+
std::atomic<bool> loaded_;
|
|
256
|
+
std::vector<std::pair<size_t, ConfigChangeCallback>> callbacks_;
|
|
257
|
+
size_t next_callback_id_;
|
|
258
|
+
|
|
259
|
+
void notify_callbacks();
|
|
260
|
+
ConfigResult parse_json_object(const std::string& json_content);
|
|
261
|
+
ConfigResult parse_yaml_content(const std::string& yaml_content);
|
|
262
|
+
|
|
263
|
+
// Helper functions for parsing
|
|
264
|
+
static bool parse_bool(const std::string& value, bool& out);
|
|
265
|
+
static bool parse_float(const std::string& value, float& out);
|
|
266
|
+
static bool parse_uint32(const std::string& value, uint32_t& out);
|
|
267
|
+
static bool parse_size_t(const std::string& value, size_t& out);
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Helper function to load configuration from file (auto-detects format).
|
|
272
|
+
* @param filepath Path to configuration file (.json or .yaml/.yml)
|
|
273
|
+
* @return ConfigResult with success/failure
|
|
274
|
+
*/
|
|
275
|
+
ConfigResult load_config(const std::string& filepath);
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Get the default configuration.
|
|
279
|
+
*/
|
|
280
|
+
EtbConfig get_default_config();
|
|
281
|
+
|
|
282
|
+
} // namespace etb
|
|
283
|
+
|
|
284
|
+
#endif // ETB_CONFIG_HPP
|