Socket
Socket
Sign inDemoInstall

graphology-traversal

Package Overview
Dependencies
4
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 0.1.0

bfs.d.ts

4

dfs.d.ts

@@ -1,3 +0,3 @@

import Graph, {NodeIterationCallback} from 'graphology-types';
import Graph, {Attributes, NodeIterationCallback} from 'graphology-types';
export default function dfs(graph: Graph, callback: NodeIterationCallback): void;
export function dfs<N extends Attributes = Attributes>(graph: Graph<N>, callback: NodeIterationCallback<N>): void;

@@ -15,3 +15,3 @@ /**

*/
module.exports = function dfs(graph, callback) {
function dfs(graph, callback) {
if (!isGraph(graph))

@@ -23,6 +23,9 @@ throw new Error('graphology-traversal/dfs: expecting a graphology instance.');

// Early termination
if (graph.order === 0 || graph.size === 0)
return;
var seen = new Set();
var stack = [];
var attrs = [];
var n, a;
var r, n, a;

@@ -33,4 +36,4 @@ function neighborCallback(neighbor, an) {

stack.push(neighbor);
attrs.push(an);
seen.add(neighbor);
stack.push([neighbor, an]);
}

@@ -42,10 +45,10 @@

stack.push(node);
attrs.push(attr);
seen.add(node);
stack.push([node, attr]);
while (stack.length !== 0) {
n = stack.pop();
a = attrs.pop();
r = stack.pop();
n = r[0];
a = r[1];
seen.add(n);
callback(n, a);

@@ -56,2 +59,4 @@

});
};
}
exports.dfs = dfs;

@@ -1,1 +0,2 @@

export {default as dfs} from './dfs';
export * from './bfs';
export * from './dfs';

@@ -1,1 +0,10 @@

exports.dfs = require('./dfs.js');
var bfsModule = require('./bfs.js');
var dfsModule = require('./dfs.js');
var k;
for (k in bfsModule)
exports[k] = bfsModule[k];
for (k in dfsModule)
exports[k] = dfsModule[k];
{
"name": "graphology-traversal",
"version": "0.0.1",
"version": "0.1.0",
"description": "Traversal functions for graphology.",

@@ -8,2 +8,3 @@ "main": "index.js",

"*.d.ts",
"bfs.js",
"index.js",

@@ -44,2 +45,3 @@ "dfs.js"

"graphology": "^0.19.2",
"graphology-generators": "^0.11.0",
"graphology-types": "0.19.0",

@@ -58,4 +60,5 @@ "mocha": "^8.2.1"

"dependencies": {
"graphology-utils": "^1.8.0"
"graphology-utils": "^1.8.0",
"mnemonist": "^0.38.0"
}
}

@@ -15,10 +15,33 @@ [![Build Status](https://travis-ci.org/graphology/graphology-traversal.svg)](https://travis-ci.org/graphology/graphology-traversal)

* [bfs](#bfs)
* [dfs](#dfs)
### bfs
Perform a BFS (Breadth-First Search) over the given graph using a callback.
```js
import {bfs} from 'graphology-traversal';
// Alternatively, to only load the relevant code
import {bfs} from 'graphology-traversal/bfs';
bfs(graph, function(node, attr) {
console.log(node, attr);
});
```
*Arguments*
* **graph** *Graph*: a graphology instance.
* **callback** *function*: iteration callback taking the traversed node and its attributes.
### dfs
Perform a DFS over the given graph using a callback.
Perform a DFS (Depth-First Search) over the given graph using a callback.
```js
import {dfs} from 'graphology-traversal';
// Alternatively, to only load the relevant code
import {dfs} from 'graphology-traversal/dfs';

@@ -25,0 +48,0 @@ dfs(graph, function(node, attr) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc