arithmetic_coder 1.0.5
arithmetic_coder: ^1.0.5 copied to clipboard
Adaptive arithmetic coding for efficient lossless compression of bytes in pure Dart.
1.0.5 #
- Performance: optimized encode/decode for order-1, order-2 (and order-3) context models.
ContextModelandContextState:- Added
_LazyContextModelbase class that allocates oneFenwicktree per context lazily, on first use, instead of eagerly creating a tree for every possible context. init/resetnow cost is proportional to the contexts actually used rather than to the full context space (size²for order-2, more for order-3), eliminating millions of wasted operations per call.- Recycled trees are reused via an internal pool to avoid re-allocation across encode/decode runs.
ContextModelOrder1/Order2/Order3now extend_LazyContextModeland flatten their context space into a single slot table; output is byte-identical to the previous implementation.
- Added
Fenwick:- Maintains a parallel direct-frequency array, so single-symbol frequency
lookups (
freqOf) are O(1). This removes one of the two cumulative tree walks per symbol inencode. - Added
findWithLow, which decodes a symbol and returns its lower cumulative bound (sum(symbol - 1)) in a single descent, removing two tree walks per symbol indecode. initnow builds the all-ones tree directly in O(n) (each nodeiholdsi & -i) instead of O(n log n), the dominant cost when many contexts are visited (e.g. high-order models on high-entropy data: ~4–5x faster).rescaleandtoFrequencyListnow use the direct-frequency array (O(n) instead of O(n log n)).
- Maintains a parallel direct-frequency array, so single-symbol frequency
lookups (
- Added
benchmark/arithmetic_coder_benchmark.dartto track compression ratio and encode/decode throughput across orders and datasets for future metrics. - Tests:
- Added
test/fenwick_test.dartcovering the direct-frequency array,freqOf,findWithLow, the O(n)init,rescale/rebuild/resetsync, and thesum/cumulative invariants (including through many rescales). - Added
test/context_model_test.dartcovering the factory,totalSize,contextIndexmapping, lazy allocation, order-3 bucketing, and pool reuse acrossreset/init. - Extended
test/arithmetic_coder_test.dartwith cached-model reuse across sequential calls, deterministic re-encoding, and rescale-triggering inputs.
- Added
1.0.4 #
-
ArithmeticCoder:- Exposed
buildContextModelmethod to allow customization of the context model creation. - Renamed
_buildModelsto_buildContextModelCachedand updated to usebuildContextModel. - Updated
decodemethod to usemodels.eofsymbol dynamically instead of hardcoded256.
- Exposed
-
ContextModelandContextState:- Added support for order-3 context model:
- Added
ContextStateOrder3with three previous symbols. - Added
ContextModelOrder3with a 3D Fenwick tree structure and a shrink factor to reduce memory usage.
- Added
- Added
ordergetter toContextStateandContextModelto indicate the model order. - Added static
maxContextOrderconstant (value 3) toContextModel. - Updated factory constructor in
ContextModelto support order 3. - Updated all context state classes to implement
ordergetter. - Updated all context model classes to implement
ordergetter. ContextModelOrder3:- Uses a 3D list of Fenwicks with size reduction on the 3rd dimension.
- Added support for order-3 context model:
1.0.3 #
Fenwick- reduce memory usage:- Updated
_treefield initialization to use typed lists (Uint8List,Uint16List,Uint32List,Uint64List) based on the bit length ofmaxTotalfor memory efficiency. - Added private static method
_buildIntListto create appropriate typed list for frequency storage. - Adjusted
computeMaxTotalto return(1 << (precision ~/ 2)) - 1instead of1 << (precision ~/ 2)to correctly compute maximum total frequency. - Changed
_treeinitialization fromList.filledto use_buildIntListin constructor.
- Updated
1.0.2 #
-
Added context modeling support to
ArithmeticCoder:- Added
orderparameter to specify finite-order Markov models (0, 1, or 2). - Integrated
ContextModelabstraction with adaptive Fenwick trees per context. - Updated encoding and decoding to use context-dependent frequency models.
- Added
toStringoverride toArithmeticCodershowing order and model size.
- Added
-
ContextModel:- Introduced abstract
ContextModelwith factory constructor for orders 0, 1, and 2. - Implemented
ContextModelOrder0,ContextModelOrder1, andContextModelOrder2with correspondingContextStateclasses. - Each model maintains Fenwick trees for symbol frequencies per context.
- Adaptive frequency updates and context state transitions implemented.
- Introduced abstract
-
arithmetic_coder.dart:- Refactored to use
ContextModelfor symbol frequency management. - Encoding and decoding now maintain and update context states.
- Added detailed comments on algorithm and context modeling.
- Refactored to use
-
example/arithmetic_coder_example.dart:- Updated example to use
ArithmeticCoder(order: 2). - Increased input repetition count for better compression demonstration.
- Added output of compression ratio and integrity check.
- Added helper
_listEqualsfor byte list comparison.
- Updated example to use
-
test/arithmetic_coder_test.dart:- Parameterized tests to run for orders 0, 1, and 2.
- Removed redundant
ArithmeticCoderinstantiations inside tests. - Verified encode-decode correctness and compression ratio for all orders.
-
pubspec.yaml:- Bumped version to
1.0.1.
- Bumped version to
1.0.0 #
- Initial version.