Comparing version 0.0.8 to 0.0.9
10
index.js
@@ -123,2 +123,4 @@ 'use strict'; | ||
nIterationsBetweenTickChecks = _this$options.nIterationsBetweenTickChecks; | ||
const usedStrs = {}; // strs that have been placed in a cluster already | ||
const strs = Object.keys(bucket); | ||
@@ -133,2 +135,8 @@ const nStrs = strs.length; | ||
const a = strs[ai]; | ||
if (a in usedStrs) { | ||
i += nStrs - ai - 1; | ||
continue; | ||
} | ||
const aCount = bucket[a]; | ||
@@ -157,2 +165,3 @@ let bin = null; // set iff any b clusters with a | ||
const b = strs[bi]; | ||
if (b in usedStrs) continue; | ||
const d = distance(a, b); | ||
@@ -181,2 +190,3 @@ | ||
bin.bucket[b] = bCount; | ||
usedStrs[b] = null; | ||
} | ||
@@ -183,0 +193,0 @@ } |
{ | ||
"name": "clustring", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Algorithms for clustering strings", | ||
@@ -8,3 +8,4 @@ "main": "index.js", | ||
"build": "rollup -c", | ||
"prepublish": "npm run build", | ||
"prepublishOnly": "npm test", | ||
"prepare": "npm run build", | ||
"test": "jest" | ||
@@ -11,0 +12,0 @@ }, |
@@ -22,2 +22,3 @@ import { tick } from '../util' | ||
const usedStrs = {} // strs that have been placed in a cluster already | ||
const strs = Object.keys(bucket) | ||
@@ -33,2 +34,8 @@ const nStrs = strs.length | ||
const a = strs[ai] | ||
if (a in usedStrs) { | ||
i += (nStrs - ai - 1) | ||
continue | ||
} | ||
const aCount = bucket[a] | ||
@@ -56,2 +63,5 @@ let bin = null // set iff any b clusters with a | ||
const b = strs[bi] | ||
if (b in usedStrs) continue | ||
const d = distance(a, b) | ||
@@ -76,2 +86,3 @@ | ||
bin.bucket[b] = bCount | ||
usedStrs[b] = null | ||
} | ||
@@ -78,0 +89,0 @@ } |
@@ -32,2 +32,15 @@ import clusterByKnn from './clusterByKnn' | ||
it('should not put a value into two clusters', async () => { | ||
const bucket = { a: 1, b: 1, c: 1, d: 1 } | ||
const distance = (a, b) => 1 | ||
const bins = await clusterByKnn(bucket, distance, 1).cluster() | ||
expect(bins).toEqual([ | ||
{ | ||
name: 'a', | ||
count: 4, | ||
bucket: { a: 1, b: 1, c: 1, d: 1 } | ||
} | ||
]) | ||
}) | ||
it('should pick highest-count name', async () => { | ||
@@ -34,0 +47,0 @@ const bucket = { a: 3, b: 4 } |
@@ -18,3 +18,3 @@ import levenshtein from './levenshtein' | ||
[ '', 'left empty', 10 ], | ||
[ 'accentś', 'accėnts', 2 ], | ||
[ 'accentś', 'accėnts', 2 ] | ||
] | ||
@@ -21,0 +21,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
95294
1167