Use TableRef instead of copying tables all the time
This commit is contained in:
parent
b04df0cce1
commit
510fd64c4a
1 changed files with 8 additions and 8 deletions
|
|
@ -3,8 +3,8 @@ import parseopt, tables, strutils
|
|||
import neo
|
||||
|
||||
proc predict(word:string, matrix:Matrix[uint16],
|
||||
word2int:Table[string, int],
|
||||
int2word:Table[int, string]):string =
|
||||
word2int:TableRef[string, int],
|
||||
int2word:TableRef[int, string]):string =
|
||||
if not word2int.hasKey(word):
|
||||
return ""
|
||||
let
|
||||
|
|
@ -20,8 +20,8 @@ proc predict(word:string, matrix:Matrix[uint16],
|
|||
return int2word[maxI]
|
||||
|
||||
proc updateMatrix(matrix:var Matrix[uint16], word1:string, word2:string,
|
||||
word2int:var Table[string, int],
|
||||
int2word:var Table[int, string]) =
|
||||
word2int:var TableRef[string, int],
|
||||
int2word:var TableRef[int, string]) =
|
||||
if not word2int.hasKey(word1):
|
||||
let newIndex = len(word2int)
|
||||
word2int[word1] = newIndex
|
||||
|
|
@ -37,8 +37,8 @@ proc updateMatrix(matrix:var Matrix[uint16], word1:string, word2:string,
|
|||
matrix[w1, w2] += 1
|
||||
|
||||
proc interactive(matrix:Matrix[uint16],
|
||||
word2int:Table[string, int],
|
||||
int2word:Table[int, string]) =
|
||||
word2int:TableRef[string, int],
|
||||
int2word:TableRef[int, string]) =
|
||||
echo "-= Interactive prediction =-"
|
||||
for line in stdin.lines:
|
||||
echo predict(line, matrix, word2int, int2word)
|
||||
|
|
@ -51,8 +51,8 @@ proc main() =
|
|||
word = "I"
|
||||
texts:seq[string]
|
||||
matrix = zeros(20000, 20000, uint16)
|
||||
word2int = initTable[string, int]()
|
||||
int2word = initTable[int, string]()
|
||||
word2int = newTable[string, int]()
|
||||
int2word = newTable[int, string]()
|
||||
|
||||
# Parse arguments
|
||||
while true:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue