-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
2,447 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const math = @import("std").math; | ||
|
||
// Reverse bit-by-bit a N-bit code. | ||
pub fn bitReverse(comptime T: type, value: T, N: usize) T { | ||
const r = @bitReverse(value); | ||
return r >> @as(math.Log2Int(T), @intCast(@typeInfo(T).Int.bits - N)); | ||
} | ||
|
||
test "bitReverse" { | ||
const std = @import("std"); | ||
|
||
const ReverseBitsTest = struct { | ||
in: u16, | ||
bit_count: u5, | ||
out: u16, | ||
}; | ||
|
||
const reverse_bits_tests = [_]ReverseBitsTest{ | ||
.{ .in = 1, .bit_count = 1, .out = 1 }, | ||
.{ .in = 1, .bit_count = 2, .out = 2 }, | ||
.{ .in = 1, .bit_count = 3, .out = 4 }, | ||
.{ .in = 1, .bit_count = 4, .out = 8 }, | ||
.{ .in = 1, .bit_count = 5, .out = 16 }, | ||
.{ .in = 17, .bit_count = 5, .out = 17 }, | ||
.{ .in = 257, .bit_count = 9, .out = 257 }, | ||
.{ .in = 29, .bit_count = 5, .out = 23 }, | ||
}; | ||
|
||
for (reverse_bits_tests) |h| { | ||
const v = bitReverse(u16, h.in, h.bit_count); | ||
try std.testing.expectEqual(h.out, v); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Deflate | ||
|
||
// Biggest block size for uncompressed block. | ||
pub const max_store_block_size = 65535; | ||
// The special code used to mark the end of a block. | ||
pub const end_block_marker = 256; | ||
|
||
// LZ77 | ||
|
||
// The smallest match length per the RFC section 3.2.5 | ||
pub const base_match_length = 3; | ||
// The smallest match offset. | ||
pub const base_match_offset = 1; | ||
// The largest match length. | ||
pub const max_match_length = 258; | ||
// The largest match offset. | ||
pub const max_match_offset = 1 << 15; | ||
|
||
// Huffman Codes | ||
|
||
// The largest offset code. | ||
pub const offset_code_count = 30; | ||
// Max number of frequencies used for a Huffman Code | ||
// Possible lengths are codegenCodeCount (19), offset_code_count (30) and max_num_lit (286). | ||
// The largest of these is max_num_lit. | ||
pub const max_num_frequencies = max_num_lit; | ||
// Maximum number of literals. | ||
pub const max_num_lit = 286; |
Oops, something went wrong.