{"id":21399325,"url":"https://github.com/streamr-dev/quick-dijkstra","last_synced_at":"2025-10-08T16:24:33.299Z","repository":{"id":47360161,"uuid":"252675665","full_name":"streamr-dev/quick-dijkstra","owner":"streamr-dev","description":"Dijkstra's algorithm as a native C++ library for NodeJS, and as a WebAssembly library for the browsers","archived":false,"fork":false,"pushed_at":"2024-02-28T20:23:13.000Z","size":670,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-20T14:15:34.006Z","etag":null,"topics":["algorithm","dijkstra","graph"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/streamr-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-03T08:33:06.000Z","updated_at":"2021-11-05T08:01:38.000Z","dependencies_parsed_at":"2022-08-31T22:23:00.465Z","dependency_job_id":null,"html_url":"https://github.com/streamr-dev/quick-dijkstra","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamr-dev%2Fquick-dijkstra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamr-dev%2Fquick-dijkstra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamr-dev%2Fquick-dijkstra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamr-dev%2Fquick-dijkstra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/streamr-dev","download_url":"https://codeload.github.com/streamr-dev/quick-dijkstra/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235217913,"owners_count":18954520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","dijkstra","graph"],"created_at":"2024-11-22T15:14:06.383Z","updated_at":"2025-10-08T16:24:28.242Z","avatar_url":"https://github.com/streamr-dev.png","language":"JavaScript","readme":"# quick-dijkstra\n\nquick-dijkstra implements the Dijkstra's algorithm as a native C++ library for NodeJS, and as a \nWebAssembly library for the browsers. Speed tests indicate that the native NodeJS library is approximately 10x faster than the js-graph-algorithms Dijkstra implementation written in pure Javascript. The native NodeJS library is distributed as NPM package @streamr/quick-dijkstra, \nand the WebAssembly version as @streamr/quick-dijkstra-wasm. Both versions are build from the same codebase (https://github.com/streamr-dev/quick-dijkstra) \n\n## NodeJS native library\n\n### Installation\n\nThe native library gets compiled automatically with npm install\n\n```\nnpm install @streamr/quick-dijkstra\n```\n\n### Usage from Javascript\n\n```\nconst QuickDijkstra = require('@streamr/quick-dijkstra');\nlet result = QuickDijkstra.calculateShortestPaths([ [0,1,1], [1,2,1], [2,3,1], [3,4,1] ] );\nconsole.log(JSON.stringify(result));\n```\n\n### Usage from TypeScript \n\n```\nimport * as QuickDijkstra from '@streamr/quick-dijkstra';\n\nlet result = QuickDijkstra.calculateShortestPaths([ [2,3,1], [0,2,3], [2,1,4] ]);\nconsole.log(JSON.stringify(result));\n```\n\n### Complete usage example\n\nSee the examples/native for a complete example of using the native NodeJS library.\n\n### Running the unit test\n\n```\nnpm test\n```\n\n### Running the speed test\n\nRuns a speed test against a pure JS Dijkstra implementation of js-graph-algorithms.\n\n```\nnpm run speedtest\n```\n\n### Api documentation\n\n[Api documentation](doc/native/modules.md)\n\n\n## WebAssembly library\n\n### Installation\n\n```\nnpm install @streamr/quick-dijkstra-wasm\n```\n\n### Compiling\n\nPre-compiled WebAssembly files are provided in the NPM package, so compiling the webassembly library\nis not strictly necessary.\n\nIf you wish to compile the webassembly files, first download and install the [Emscripten toolkit](https://emscripten.org/docs/getting_started/downloads.html)\n\nThen you can compile the webassembly library by issuing the commands\n\n```\ngit clone https://github.com/streamr-dev/quick-dijkstra\ncd quick-dijkstra\nnpm install\nnpm run npm run wasm-compile\n```\n\n### Running the speed test\n\n```\nnpm run wasm-speedtest\n```\n\n### Usage on web with a script tag\n\n```\n\u003cscript src=\"dijkstraengine.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"quickdijkstra-wasm.js\"\u003e\u003c/script\u003e\n\n...\n\n\u003cscript\u003e\n\nQuickDijkstraWasm.calculateShortestPaths([ [2,3,1], [0,2,3], [2,1,4] ], ret =\u003e \n\t{\n\tconsole.log(ret);\n\t}\t\n\n\u003c/script\u003e\n\n```\nSee the complete [example](examples/wasm/javascript-web) at examples/wasm/javascript-web\n\n### Usage in React project generated using create-react-app\n\nInstallation\n\n```\nnpm install @streamr/quick-dijkstra-wasm\n```\n\nA project created with create-react-app uses webpack under the hood, and the webpack config needs to be made editable\nin order to be able to use quick-dijkstra-wasm. This can be achieved with the react-app-rewired package.\n\nInstall react-app-rewired and required webpack plugins:\n\n```\nnpm i -D react-app-rewired\nnpm i -D copy-webpack-plugin@6.2.1\nnpm i -D write-file-webpack-plugin\nnpm i -D exports-loader@1.1.1\n```\n\nThe react-app-revired uses the file config-overrides.js in the root directory of the project for \nmodifying the webpack config. Create config-overrides.js in the root directory of the project with the following\ncontent:\n\n```\nconst CopyWebpackPlugin = require('copy-webpack-plugin');\nconst WriteFilePlugin = require('write-file-webpack-plugin');\n\nmodule.exports = function override(config, env) {\n    if (!config.plugins) {\n        config.plugins = [];\n\t}\n\tconfig.module.rules[0] = { parser: { requireEnsure: true } };\n\tconsole.log(config.module.rules);\n\n    config.plugins.push(new CopyWebpackPlugin({patterns: [{from: 'node_modules/\\@streamr/quick-dijkstra-wasm/dijkstraengine.wasm', to: 'static/js'}]}));\n\tconfig.plugins.push(new WriteFilePlugin());\n\n\tconfig.module.rules.push(\t{\n\t\ttest: /dijkstraengine\\.js$/,\n\t\tloader: \"exports-loader\",\n\t\toptions: {\n\t\t\texports: \"Module\",\n\t\t}\n\t});\n\n\tconfig.module.rules.push( {\n\t\ttest: /dijkstraengine\\.wasm$/,\n\t\tloader: \"file-loader\",\n\t\toptions: {\n\t\t  publicPath: \"build/static/js\"\n\t\t}\n\t});\n\n\tconfig.output.futureEmitAssets=false;\n\n    return config;\n}\n```\n\nEdit package.json to use react-app-rewired instead of react-scripts or react-scripts-ts:\n\n```\n// package.json\n\"scripts\": {\n -   \"start\":\"react-scripts-ts start\",\n +   \"start\": \"react-app-rewired start --scripts-version react-scripts-ts\",\n -   \"build\" \"react-scripts-ts build\",\n +   \"build\": \"react-app-rewired build --scripts-version react-scripts-ts\",\n -   \"test\": \"react-scripts-ts test --env=jsdom\",\n +   \"test\": \"react-app-rewired test --env=jsdom --scripts-version react-scripts-ts\",\n     \"eject\": \"react-scripts-ts eject\"\n  }\n```\n\nSee the complete [example](examples/wasm/typescript-react) at examples/wasm/typescript-react\n\n### Complete Usage examples\n\nThe folder examples/wasm contains complete examples of using the WebAssembly library in various environments: \n * javascript-node is an example of using the WebAssembly library on NodeJS with JavaScript\n * typescript-node is an example of using the WebAssembly library on NodeJS with TypeScript\n * javascript-web is an example of using the WebAssembly library imported using the script tag on web\n * typescript-webpack is an example of using the WebAssembly library in a TypeScript project with webpack\n * typescript-react is an example of using the WebAssembly library in a React TypeScript project generated using create-react-app\n\nThe most complete example is the typescript-webpackit, as it includes an example of converting a network graph into the format \nrequired by the library. Pay attention to the webpack.config.js file; custom rules are neede in order to use the\nWebAssembly library in a WebPack project. Also note that the .wasm file needs to be served by the web server from the same folder together with \nthe bundled JavaScript file.\n\n### Api documentation\n\n[Api documentation](doc/wasm/modules.md)\n\n## Acknowledgments\n\nThe C++ algorithm was inspired by the GeeksforGeeks tutorial by Shubham Agrawal https://www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-using-priority_queue-stl and the Dijkstra's implementation posted by Michal Forišek\nat https://www.quora.com/What-is-the-most-simple-efficient-C++-code-for-Dijkstras-shortest-path-algorithm\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreamr-dev%2Fquick-dijkstra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstreamr-dev%2Fquick-dijkstra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreamr-dev%2Fquick-dijkstra/lists"}