Traverser

Traverser

Represents a traverser which searches/traverses the tree in BFS and DFS fashion.

Constructor

new Traverser(tree)

Parameters:
Name Type Description
tree Tree that has to be traversed or search.
Source:

Methods

searchBFS(criteria) → {object}

Searches a tree in BFS fashion. Requires a search criteria to be provided.
Parameters:
Name Type Description
criteria function MUST BE a callback function that specifies the search criteria. Criteria callback here receives TreeNode#_data in parameter and MUST return boolean indicating whether that data satisfies your criteria.
Source:
Returns:
- first TreeNode in tree that matches the given criteria.
Type
object
Example
// Search BFS
var node = tree.traverser().searchBFS(function(data){
 return data.key === '#greenapple';
});

searchDFS(criteria) → {object}

Searches a tree in DFS fashion. Requires a search criteria to be provided.
Parameters:
Name Type Description
criteria function MUST BE a callback function that specifies the search criteria. Criteria callback here receives TreeNode#_data in parameter and MUST return boolean indicating whether that data satisfies your criteria.
Source:
Returns:
- first TreeNode in tree that matches the given criteria.
Type
object
Example
// Search DFS
var node = tree.traverser().searchDFS(function(data){
 return data.key === '#greenapple';
});

traverseBFS(callback)

Traverses an entire tree in BFS fashion.
Parameters:
Name Type Description
callback function Gets triggered when node is explored. Explored node is passed as parameter to callback.
Source:
Example
// Traverse BFS
tree.traverser().traverseBFS(function(node){
 console.log(node.data);
});

traverseDFS(callback)

Traverses an entire tree in DFS fashion.
Parameters:
Name Type Description
callback function Gets triggered when @{link TreeNode} is explored. Explored node is passed as parameter to callback.
Source:
Example
// Traverse DFS
tree.traverser().traverseDFS(function(node){
 console.log(node.data);
});