diff options
author | pacien | 2018-12-02 00:38:12 +0100 |
---|---|---|
committer | pacien | 2018-12-02 00:38:12 +0100 |
commit | 56bfed7e2cdd44dc4ad0c5e233224cf0080e05ac (patch) | |
tree | d42919fdf57f7f014ca0c0db1a7a55e1465a0135 /src/lzss/lzsschain.nim | |
parent | 5cc4256a931b98ea167291397421d0db60c5d40c (diff) | |
download | gziplike-56bfed7e2cdd44dc4ad0c5e233224cf0080e05ac.tar.gz |
replace linkedlists by seqs
Diffstat (limited to 'src/lzss/lzsschain.nim')
-rw-r--r-- | src/lzss/lzsschain.nim | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/lzss/lzsschain.nim b/src/lzss/lzsschain.nim index 8ebcb1a..ab03655 100644 --- a/src/lzss/lzsschain.nim +++ b/src/lzss/lzsschain.nim | |||
@@ -14,26 +14,23 @@ | |||
14 | # You should have received a copy of the GNU Affero General Public License | 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/>. | 15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | 16 | ||
17 | import lists, tables, sugar | 17 | import tables, sugar |
18 | import ../bitio/integers | 18 | import ../bitio/integers |
19 | import listpolyfill, lzssnode | 19 | import lzssnode |
20 | 20 | ||
21 | const maxChainByteLength = 32_000 * wordBitLength | 21 | const maxChainByteLength = 32_000 |
22 | 22 | ||
23 | type LzssChain* = | 23 | type LzssChain* = seq[LzssNode] |
24 | SinglyLinkedList[LzssNode] | ||
25 | 24 | ||
26 | proc lzssChain*(): LzssChain = | 25 | proc lzssChain*(): LzssChain = |
27 | initSinglyLinkedList[LzssNode]() | 26 | newSeq[LzssNode]() |
28 | 27 | ||
29 | proc lzssChain*(chainArray: openArray[LzssNode]): LzssChain = | 28 | proc lzssChain*(chainArray: openArray[LzssNode]): LzssChain = |
30 | var chain = lzssChain() | 29 | @chainArray |
31 | for node in chainArray: chain.append(node) | ||
32 | chain | ||
33 | 30 | ||
34 | proc decode*(lzssChain: LzssChain): seq[uint8] = | 31 | proc decode*(lzssChain: LzssChain): seq[uint8] = |
35 | result = newSeqOfCap[uint8](maxChainByteLength) | 32 | result = newSeqOfCap[uint8](maxChainByteLength) |
36 | for node in lzssChain.items: | 33 | for node in lzssChain: |
37 | case node.kind: | 34 | case node.kind: |
38 | of character: | 35 | of character: |
39 | result.add(node.character) | 36 | result.add(node.character) |