aboutsummaryrefslogtreecommitdiff
path: root/src/lzss/matchtable.nim
diff options
context:
space:
mode:
authorpacien2018-12-02 00:38:12 +0100
committerpacien2018-12-02 00:38:12 +0100
commit56bfed7e2cdd44dc4ad0c5e233224cf0080e05ac (patch)
treed42919fdf57f7f014ca0c0db1a7a55e1465a0135 /src/lzss/matchtable.nim
parent5cc4256a931b98ea167291397421d0db60c5d40c (diff)
downloadgziplike-56bfed7e2cdd44dc4ad0c5e233224cf0080e05ac.tar.gz
replace linkedlists by seqs
Diffstat (limited to 'src/lzss/matchtable.nim')
-rw-r--r--src/lzss/matchtable.nim14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/lzss/matchtable.nim b/src/lzss/matchtable.nim
index b17ce68..94fe208 100644
--- a/src/lzss/matchtable.nim
+++ b/src/lzss/matchtable.nim
@@ -14,19 +14,17 @@
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
17import tables, lists 17import tables
18import listpolyfill
19 18
20type MatchTable*[K, V] = 19type MatchTable*[K, V] = TableRef[K, seq[V]]
21 TableRef[K, SinglyLinkedList[V]]
22 20
23proc initMatchTable*[K, V](keyType: typedesc[K], valueType: typedesc[V]): MatchTable[K, V] = 21proc initMatchTable*[K, V](keyType: typedesc[K], valueType: typedesc[V]): MatchTable[K, V] =
24 newTable[K, SinglyLinkedList[V]]() 22 newTable[K, seq[V]]()
25 23
26proc matchList*[K, V](matchTable: MatchTable[K, V], pattern: K): SinglyLinkedList[V] = 24proc matchList*[K, V](matchTable: MatchTable[K, V], pattern: K): seq[V] =
27 matchTable.getOrDefault(pattern, initSinglyLinkedList[V]()) 25 matchTable.getOrDefault(pattern, newSeq[V]())
28 26
29proc addMatch*[K, V](matchTable: MatchTable[K, V], pattern: K, value: V) = 27proc addMatch*[K, V](matchTable: MatchTable[K, V], pattern: K, value: V) =
30 var matchList = matchTable.matchList(pattern) 28 var matchList = matchTable.matchList(pattern)
31 listpolyfill.prepend(matchList, value) 29 matchList.insert(value)
32 matchTable[pattern] = matchList 30 matchTable[pattern] = matchList