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/matchtable.nim | |
parent | 5cc4256a931b98ea167291397421d0db60c5d40c (diff) | |
download | gziplike-56bfed7e2cdd44dc4ad0c5e233224cf0080e05ac.tar.gz |
replace linkedlists by seqs
Diffstat (limited to 'src/lzss/matchtable.nim')
-rw-r--r-- | src/lzss/matchtable.nim | 14 |
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 | ||
17 | import tables, lists | 17 | import tables |
18 | import listpolyfill | ||
19 | 18 | ||
20 | type MatchTable*[K, V] = | 19 | type MatchTable*[K, V] = TableRef[K, seq[V]] |
21 | TableRef[K, SinglyLinkedList[V]] | ||
22 | 20 | ||
23 | proc initMatchTable*[K, V](keyType: typedesc[K], valueType: typedesc[V]): MatchTable[K, V] = | 21 | proc initMatchTable*[K, V](keyType: typedesc[K], valueType: typedesc[V]): MatchTable[K, V] = |
24 | newTable[K, SinglyLinkedList[V]]() | 22 | newTable[K, seq[V]]() |
25 | 23 | ||
26 | proc matchList*[K, V](matchTable: MatchTable[K, V], pattern: K): SinglyLinkedList[V] = | 24 | proc 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 | ||
29 | proc addMatch*[K, V](matchTable: MatchTable[K, V], pattern: K, value: V) = | 27 | proc 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 |