mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
flate.Compress: simplify huffman node comparisons
Instead of comparing each field, nodes are now compared as 32-bit values where `freq` is in the most significant bits.
This commit is contained in:
parent
d6931b0ff5
commit
8284da2f3d
@ -993,14 +993,15 @@ const huffman = struct {
|
|||||||
const max_leafs = 286;
|
const max_leafs = 286;
|
||||||
const max_nodes = max_leafs * 2;
|
const max_nodes = max_leafs * 2;
|
||||||
|
|
||||||
const Node = struct {
|
const Node = packed struct(u32) {
|
||||||
freq: u16,
|
|
||||||
depth: u16,
|
depth: u16,
|
||||||
|
freq: u16,
|
||||||
|
|
||||||
pub const Index = u16;
|
pub const Index = u16;
|
||||||
|
|
||||||
|
/// `freq` is more significant than `depth`
|
||||||
pub fn smaller(a: Node, b: Node) bool {
|
pub fn smaller(a: Node, b: Node) bool {
|
||||||
return if (a.freq != b.freq) a.freq < b.freq else a.depth < b.depth;
|
return @as(u32, @bitCast(a)) < @as(u32, @bitCast(b));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user