1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! Internal hybrid codec dispatcher for variable-length integer codes on write path.
//!
//! This module provides [`CodecWriter`], a two-stage dispatcher that optimizes
//! writing to compressed bitstreams while maintaining compatibility with all
//! codecs supported by [`dsi-bitstream`](https://crates.io/crates/dsi-bitstream).
//!
//! The design prioritizes performance for common codecs while providing a robust
//! fallback for exotic parameter combinations, ensuring that any validly resolved
//! codec can be written without panicking.
use ;
/// A hybrid dispatcher for writing compression codes.
///
/// This enum acts as a two-stage dispatcher to write values to a compressed
/// bitstream. It is designed to handle all valid codecs supported by
/// [`dsi-bitstream`](https://crates.io/crates/dsi-bitstream), ensuring
/// correctness while maximizing performance.
///
/// # Dispatch Strategy
///
/// 1. **Fast Path ([`CodecWriter::Fast`])**: For common codecs (e.g., Gamma,
/// Delta, or Zeta with small parameters), [`dsi-bitstream`](https://crates.io/crates/dsi-bitstream)
/// provides pre-compiled function pointers via [`FuncCodeWriter`]. This path
/// avoids the overhead of a `match` statement on every write operation, as the
/// correct function is resolved once at creation time.
///
/// 2. **Slow Path ([`CodecWriter::Slow`])**: For codecs with parameters outside
/// of the pre-compiled set (e.g., `Golomb { b: 15 }`), the fast path is not
/// available. In this case, the dispatcher falls back to storing the [`Codes`]
/// enum variant directly. Each write operation then uses a `match` statement to
/// call the appropriate encoding function. While slightly slower due to the
/// runtime dispatch, this ensures that any validly resolved codec can be written.
///
/// This hybrid approach guarantees that the writer will never panic due to an
/// "unsupported code" error. The [`new`](Self::new) constructor automatically
/// selects the appropriate path.
///
/// # Type Parameters
///
/// - `E`: The endianness used for writing bits to the bitstream.
/// - `W`: The bitstream writer type implementing [`CodesWrite`].
pub