aboutsummaryrefslogtreecommitdiff
path: root/src/lzss/matchtable.nim
diff options
context:
space:
mode:
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