Comparing version 1.2.0 to 1.3.0
@@ -91,23 +91,10 @@ /* | ||
Automaton.prototype.getSize = function() { | ||
var ids = this.collectIds_(), | ||
numNodes = 0; | ||
ids.sort(); | ||
// Count ids, skipping duplicate entries. | ||
for (var i = 0; i < ids.length; i++) { | ||
numNodes++; | ||
while (ids[i] == ids[i + 1]) { | ||
i++; | ||
} | ||
} | ||
return numNodes; | ||
var ids = this.collectIds_(); | ||
return this.countIds_(ids); | ||
}; | ||
/** | ||
* Following transitions recursively, collect ids from | ||
* all reachable nodes. Duplicate ids will be collected. | ||
* Collect nodes' id. | ||
* | ||
* @return A list of node's ids. | ||
* @return A sorted list of node's ids (with duplicate). | ||
*/ | ||
@@ -126,6 +113,24 @@ Automaton.prototype.collectIds_ = function() { | ||
return ids; | ||
return ids.sort(); | ||
}; | ||
/** | ||
* Count nodes' id, skipping duplicates. | ||
* | ||
* @param ids A sorted array of ids. | ||
* @return The number of unique id. | ||
*/ | ||
Automaton.prototype.countIds_ = function(ids) { | ||
var count = 0; | ||
for (var i = 0; i < ids.length; i++, count++) { | ||
while (ids[i] == ids[i + 1]) { | ||
i++; // Skip duplicate. | ||
} | ||
} | ||
return count; | ||
}; | ||
module.exports = Automaton; | ||
{ | ||
"name": "dtrie", | ||
"description": "Trie implementation based on a minimal automaton.", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"author": "Mathieu Turcotte <turcotte.mat@gmail.com>", | ||
@@ -6,0 +6,0 @@ "keywords": ["trie", "prefix tree", "automaton", "automata", "fsa"], |
@@ -1,2 +0,2 @@ | ||
# Trie implementation based on a minimal automaton for Node.js | ||
# Trie implementation based on a minimal automaton for Node.js [![Build Status](https://secure.travis-ci.org/MathieuTurcotte/node-trie.png)](http://travis-ci.org/MathieuTurcotte/node-trie) | ||
@@ -3,0 +3,0 @@ Implementation based on "Incremental Construction of Minimal Acyclic |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
5778801
18
674
1