w2v-server.pl: copy neighbour strings only once
diff --git a/w2v-server.pl b/w2v-server.pl
index 2bc555f..138decd 100644
--- a/w2v-server.pl
+++ b/w2v-server.pl
@@ -135,7 +135,7 @@
for (a = 0; a < N; a++) bestw[a][0] = 0;
for (c = 0; c < words; c++) {
a = 0;
-// don not skip taget word
+// do not skip taget word
// for (b = 0; b < cn; b++) if (bi[b] == c) a = 1;
// if (a == 1) continue;
dist = 0;
@@ -144,17 +144,18 @@
if (dist > bestd[a]) {
for (d = N - 1; d > a; d--) {
bestd[d] = bestd[d - 1];
- strcpy(bestw[d], bestw[d - 1]);
+ besti[d] = besti[d - 1];
}
bestd[a] = dist;
besti[a] = c;
- strcpy(bestw[a], &vocab[c * max_w]);
break;
}
}
}
+
AV* array = newAV();
for (a = 0; a < N; a++) {
+ strcpy(bestw[a], &vocab[besti[a] * max_w]);
HV* hash = newHV();
hv_store(hash, "word", strlen("word"), newSVpvf(bestw[a], 0), 0);
hv_store(hash, "dist", strlen("dist"), newSVnv(bestd[a]), 0);