aboutsummaryrefslogtreecommitdiff
path: root/src/lzsshuffman/lzsshuffmansymbol.nim
diff options
context:
space:
mode:
Diffstat (limited to 'src/lzsshuffman/lzsshuffmansymbol.nim')
-rw-r--r--src/lzsshuffman/lzsshuffmansymbol.nim34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lzsshuffman/lzsshuffmansymbol.nim b/src/lzsshuffman/lzsshuffmansymbol.nim
new file mode 100644
index 0000000..cfd3fe4
--- /dev/null
+++ b/src/lzsshuffman/lzsshuffmansymbol.nim
@@ -0,0 +1,34 @@
1# gzip-like LZSS compressor
2# Copyright (C) 2018 Pacien TRAN-GIRARD
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as
6# published by the Free Software Foundation, either version 3 of the
7# License, or (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17import lists
18import ../lzss/lzssnode, ../lzss/lzssencoder
19
20type Symbol* = uint16
21
22const endSymbol* = 256.Symbol
23
24proc isEndMarker*(symbol: Symbol): bool =
25 symbol == endSymbol
26
27proc isCharacter*(symbol: Symbol): bool =
28 symbol < endSymbol
29
30proc unpackLzssReference*(symbol: Symbol, position: uint16): LzssNode =
31 lzssReference(symbol.int - endSymbol.int - 1 + matchGroupLength, position.int)
32
33proc shiftLzssLength*(length: int): uint16 =
34 (length + endSymbol.int + 1 - matchGroupLength).uint16