Comparing version 0.0.5 to 0.0.6
89
index.js
@@ -271,3 +271,3 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
regeneratorRuntime.mark(function _callee() { | ||
var bucket, distance, radius, _this$options, tickMs, nIterationsBetweenTickChecks, strs, bins, strToBin, t1, i, _i, a, aCount, _i2, b, t2, d, bCount, bin, maxCount; | ||
var bucket, distance, radius, _this$options, tickMs, nIterationsBetweenTickChecks, strs, nStrs, bins, t1, i, nComparisons, ai, a, aCount, bin, bi, t2, b, d, maxCount, bCount; | ||
@@ -281,30 +281,31 @@ return regeneratorRuntime.wrap(function _callee$(_context) { | ||
strs = Object.keys(bucket); | ||
nStrs = strs.length; | ||
bins = []; | ||
strToBin = {}; // a => bin, only if buckets has >1 element | ||
t1 = new Date(); | ||
i = 0; | ||
_i = 0; | ||
nComparisons = Math.max(0, nStrs * (nStrs - 1)); | ||
ai = 0; | ||
case 8: | ||
if (!(_i < strs.length)) { | ||
_context.next = 38; | ||
case 9: | ||
if (!(ai < nStrs)) { | ||
_context.next = 34; | ||
break; | ||
} | ||
a = strs[_i]; | ||
a = strs[ai]; | ||
aCount = bucket[a]; | ||
_i2 = 0; | ||
bin = null; // set iff any b clusters with a | ||
case 12: | ||
if (!(_i2 < strs.length)) { | ||
_context.next = 35; | ||
bi = ai + 1; | ||
case 14: | ||
if (!(bi < nStrs)) { | ||
_context.next = 31; | ||
break; | ||
} | ||
b = strs[_i2]; | ||
i += 1; | ||
if (!((i & nIterationsBetweenTickChecks) === 0)) { | ||
_context.next = 24; | ||
_context.next = 25; | ||
break; | ||
@@ -316,13 +317,13 @@ } | ||
if (!(t2 - t1 >= tickMs)) { | ||
_context.next = 24; | ||
_context.next = 25; | ||
break; | ||
} | ||
this.progress = (i - 1) / (strs.length * strs.length); | ||
_context.next = 21; | ||
this.progress = (i - 1) / nComparisons; | ||
_context.next = 22; | ||
return tick(); | ||
case 21: | ||
case 22: | ||
if (!this.canceled) { | ||
_context.next = 23; | ||
_context.next = 24; | ||
break; | ||
@@ -333,36 +334,10 @@ } | ||
case 23: | ||
case 24: | ||
t1 = new Date(); | ||
case 24: | ||
if (!(a === b)) { | ||
_context.next = 26; | ||
break; | ||
} | ||
return _context.abrupt("continue", 32); | ||
case 26: | ||
if (!(a in strToBin && b in strToBin[a].bucket)) { | ||
_context.next = 28; | ||
break; | ||
} | ||
return _context.abrupt("continue", 32); | ||
case 28: | ||
if (!(b in strToBin && a in strToBin[b].bucket)) { | ||
_context.next = 30; | ||
break; | ||
} | ||
return _context.abrupt("continue", 32); | ||
case 30: | ||
case 25: | ||
b = strs[bi]; | ||
d = distance(a, b); | ||
if (d <= radius) { | ||
bCount = bucket[b]; | ||
bin = strToBin[a]; | ||
if (!bin) { | ||
@@ -374,3 +349,2 @@ bin = { | ||
}; | ||
strToBin[a] = bin; | ||
bins.push(bin); | ||
@@ -380,2 +354,3 @@ } | ||
maxCount = bin.bucket[bin.name]; | ||
bCount = bucket[b]; | ||
@@ -390,17 +365,17 @@ if (bCount > maxCount || bCount === maxCount && b.localeCompare(bin.name) < 0) { | ||
case 32: | ||
_i2++; | ||
_context.next = 12; | ||
case 28: | ||
bi++; | ||
_context.next = 14; | ||
break; | ||
case 35: | ||
_i++; | ||
_context.next = 8; | ||
case 31: | ||
ai++; | ||
_context.next = 9; | ||
break; | ||
case 38: | ||
case 34: | ||
this.progress = 1; | ||
return _context.abrupt("return", bins); | ||
case 40: | ||
case 36: | ||
case "end": | ||
@@ -407,0 +382,0 @@ return _context.stop(); |
{ | ||
"name": "clustring", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Algorithms for clustering strings", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,12 +23,15 @@ import { tick } from '../util' | ||
const strs = Object.keys(bucket) | ||
const nStrs = strs.length | ||
const bins = [] | ||
const strToBin = {} // a => bin, only if buckets has >1 element | ||
let t1 = new Date() | ||
let i = 0 | ||
const nComparisons = Math.max(0, nStrs * (nStrs - 1)) | ||
for (const a of strs) { | ||
for (let ai = 0; ai < nStrs; ai++) { | ||
const a = strs[ai] | ||
const aCount = bucket[a] | ||
let bin = null // set iff any b clusters with a | ||
for (const b of strs) { | ||
for (let bi = ai + 1; bi < nStrs; bi++) { | ||
i += 1 | ||
@@ -38,3 +41,3 @@ if ((i & nIterationsBetweenTickChecks) === 0) { | ||
if (t2 - t1 >= tickMs) { | ||
this.progress = (i - 1) / (strs.length * strs.length) | ||
this.progress = (i - 1) / nComparisons | ||
@@ -52,10 +55,6 @@ await tick() | ||
if (a === b) continue | ||
if (a in strToBin && b in strToBin[a].bucket) continue | ||
if (b in strToBin && a in strToBin[b].bucket) continue | ||
const b = strs[bi] | ||
const d = distance(a, b) | ||
const d = distance(a, b) | ||
if (d <= radius) { | ||
const bCount = bucket[b] | ||
let bin = strToBin[a] | ||
if (!bin) { | ||
@@ -67,3 +66,2 @@ bin = { | ||
} | ||
strToBin[a] = bin | ||
bins.push(bin) | ||
@@ -73,2 +71,3 @@ } | ||
const maxCount = bin.bucket[bin.name] | ||
const bCount = bucket[b] | ||
if (bCount > maxCount || (bCount === maxCount && b.localeCompare(bin.name) < 0)) { | ||
@@ -75,0 +74,0 @@ bin.name = b |
@@ -53,7 +53,7 @@ import clusterByKnn from './clusterByKnn' | ||
tickMs: 0, | ||
nIterationsBetweenTickChecks: 0x3 | ||
nIterationsBetweenTickChecks: 0x1 | ||
}) | ||
expect(clusterer.progress).toEqual(0) | ||
await clusterer.cluster() | ||
expect(progressReport).toEqual(3 / 9) | ||
expect(progressReport).toEqual(1 / 6) | ||
expect(clusterer.progress).toEqual(1) | ||
@@ -67,3 +67,3 @@ }) | ||
tickMs: 0, | ||
nIterationsBetweenTickChecks: 0x3 | ||
nIterationsBetweenTickChecks: 0x1 | ||
}) | ||
@@ -70,0 +70,0 @@ setTimeout((() => clusterer.cancel()), 0) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98573
1328