node-fpgrowth
Advanced tools
Comparing version
@@ -104,3 +104,3 @@ import { FPNode } from './fpnode'; | ||
*/ | ||
private _getPrefixPaths(node, onPushingNewItem?, prefixPaths?); | ||
private _getPrefixPaths(node, count, onPushingNewItem?, prefixPaths?); | ||
/** | ||
@@ -113,3 +113,3 @@ * RECURSIVE CALL - Returns the prefix path (as a set of items) of the tree from a given node. | ||
*/ | ||
private _getPrefixPath(node, onPushingNewItem?); | ||
private _getPrefixPath(node, count, onPushingNewItem?); | ||
/** | ||
@@ -116,0 +116,0 @@ * RECURSIVE CALL - Returns the single path of the tree, if it is one. Else, it returns null. |
@@ -112,3 +112,3 @@ "use strict"; | ||
// function is called, allowing us to update the item support. | ||
var prefixPaths = this._getPrefixPaths(start, function (i, count) { | ||
var prefixPaths = this._getPrefixPaths(start, start.support, function (i, count) { | ||
conditionalTreeSupports[JSON.stringify(i)] = (conditionalTreeSupports[JSON.stringify(i)] || 0) + count; | ||
@@ -137,3 +137,3 @@ }); | ||
return []; | ||
return this._getPrefixPaths(start); | ||
return this._getPrefixPaths(start, start.support); | ||
}; | ||
@@ -151,3 +151,3 @@ /** | ||
throw new Error('Error building the FPTree'); | ||
var path = this._getPrefixPath(node, onPushingNewItem); | ||
var path = this._getPrefixPath(node, node.support, onPushingNewItem); | ||
if (path.length === 0) | ||
@@ -210,3 +210,3 @@ return; | ||
*/ | ||
FPTree.prototype._getPrefixPaths = function (node, onPushingNewItem, prefixPaths) { | ||
FPTree.prototype._getPrefixPaths = function (node, count, onPushingNewItem, prefixPaths) { | ||
if (prefixPaths === void 0) { prefixPaths = []; } | ||
@@ -218,3 +218,3 @@ var prefixPath = this.getPrefixPath(node, onPushingNewItem); | ||
return prefixPaths; | ||
return this._getPrefixPaths(node.nextSameItemNode, onPushingNewItem, prefixPaths); | ||
return this._getPrefixPaths(node.nextSameItemNode, count, onPushingNewItem, prefixPaths); | ||
}; | ||
@@ -228,7 +228,7 @@ /** | ||
*/ | ||
FPTree.prototype._getPrefixPath = function (node, onPushingNewItem) { | ||
FPTree.prototype._getPrefixPath = function (node, count, onPushingNewItem) { | ||
if (node.parent && node.parent.parent) { | ||
if (onPushingNewItem) | ||
onPushingNewItem(node.parent.item, node.parent.support); | ||
return [node.parent.item].concat(this._getPrefixPath(node.parent, onPushingNewItem)); | ||
onPushingNewItem(node.parent.item, count); | ||
return [node.parent.item].concat(this._getPrefixPath(node.parent, count, onPushingNewItem)); | ||
} | ||
@@ -235,0 +235,0 @@ return []; |
{ | ||
"name": "node-fpgrowth", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "FPGrowth Algorithm implementation in TypeScript / JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "dist/fpgrowth.js", |
@@ -129,3 +129,3 @@ import { FPNode } from './fpnode'; | ||
// function is called, allowing us to update the item support. | ||
let prefixPaths: IPrefixPath<T>[] = this._getPrefixPaths(start, (i: T, count: number) => { | ||
let prefixPaths: IPrefixPath<T>[] = this._getPrefixPaths(start, start.support, (i: T, count: number) => { | ||
conditionalTreeSupports[JSON.stringify(i)] = (conditionalTreeSupports[JSON.stringify(i)] || 0) + count; | ||
@@ -155,3 +155,3 @@ }); | ||
if(!start) return []; | ||
return this._getPrefixPaths(start); | ||
return this._getPrefixPaths(start,start.support); | ||
} | ||
@@ -170,3 +170,3 @@ | ||
let path: T[] = this._getPrefixPath(node,onPushingNewItem); | ||
let path: T[] = this._getPrefixPath(node,node.support,onPushingNewItem); | ||
if( path.length === 0 ) return; | ||
@@ -232,3 +232,3 @@ return { | ||
*/ | ||
private _getPrefixPaths( node: FPNode<T>, onPushingNewItem?: (item: T, count: number) => void, prefixPaths: IPrefixPath<T>[] = []): IPrefixPath<T>[] { | ||
private _getPrefixPaths( node: FPNode<T>, count: number, onPushingNewItem?: (item: T, count: number) => void, prefixPaths: IPrefixPath<T>[] = []): IPrefixPath<T>[] { | ||
let prefixPath: IPrefixPath<T> = this.getPrefixPath(node,onPushingNewItem); | ||
@@ -238,3 +238,3 @@ if(prefixPath) prefixPaths.push(prefixPath); | ||
if(!node.nextSameItemNode) return prefixPaths; | ||
return this._getPrefixPaths(node.nextSameItemNode,onPushingNewItem,prefixPaths); | ||
return this._getPrefixPaths(node.nextSameItemNode,count,onPushingNewItem,prefixPaths); | ||
} | ||
@@ -249,6 +249,6 @@ | ||
*/ | ||
private _getPrefixPath( node: FPNode<T>, onPushingNewItem?: (item: T, count: number) => void ): T[] { | ||
private _getPrefixPath( node: FPNode<T>, count: number, onPushingNewItem?: (item: T, count: number) => void ): T[] { | ||
if(node.parent && node.parent.parent) { | ||
if(onPushingNewItem) onPushingNewItem(node.parent.item, node.parent.support); | ||
return [node.parent.item].concat(this._getPrefixPath(node.parent,onPushingNewItem)); | ||
if(onPushingNewItem) onPushingNewItem(node.parent.item,count); | ||
return [node.parent.item].concat(this._getPrefixPath(node.parent,count,onPushingNewItem)); | ||
} | ||
@@ -255,0 +255,0 @@ return []; |
56822
0.25%