Rust port of the Python stdlib graphlib modules
Project description
graphlib2
This is a Rust port of Python's stdlib graphlib. It passes all of the standard libraries tests and is a drop in replacement. This also happens to be Python 3.7 compatible, so it can be used as a backport. Since usage is exactly the same as the standard libraries, please refer to their documentation for usage details.
See this project on GitHub.
Example
from graphlib2 import TopologicalSorter
graph = {0: [1], 1: [2]} # 0 depends on 1, 1 depends on 2
ts = TopologicalSorter(graph)
ts.prepare()
while ts.is_active():
ready_nodes = ts.get_ready()
ts.done(*ready_nodes) # all at a time or one by one
Motivation
This was primarily written for di and for me to learn Rust. In other words: please vet the code yourself before using this.
Differences with the stdlib implementation
- Added
TopologicalSorter.copy()
which copies a prepared or unprepared graph so that it can be executed multiple times. - Pretty solid performance improvements (see benchmarks).
- Returns generic iterables from
TopologicalSorter.get_ready()
andTopologicalSorter.static_order()
instead of a tuple and generator respectively like the standard library does. Currently, these are both lists, but this should be considered an implementation detail. - Misc improvements, like working generics without postponed evaluateion (
ToplologicalSorter[int]
works at runtime).
Performance
The implementation was designed for the specific use case of adding all nodes, calling prepare()
then copying and executing in a loop:
from graphlib2 import TopologicalSorter
graph = {0: [1], 1: [2]}
ts = TopologicalSorter(graph)
ts.prepare()
while True: # hot loop
t = ts.copy()
while t.is_active():
ready_nodes = t.get_ready()
t.done(*ready_nodes)
This means that the focus is on the performance of TopologicalSorter.get_ready()
and TopologicalSorter.done()
, and only minimal effort was put into other methods (prepare()
, add()
and get_static_order()
), although these are still quite performant.
Contributing
- Clone the repo.
- Run
make init
- Run
make test
- Make your changes
- Push and open a pull request
- Wait for CI to run.
If your pull request gets approved and merged, it will automatically be relased to PyPi (every commit to main
is released).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for graphlib2-0.2.13-pp38-pypy38_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9dd966a8516041ab5a903903f50e750addf339dc02d310f58666bf0d40fdf35 |
|
MD5 | dfae40a8bd18de0dbe8be6a0ea3264e1 |
|
BLAKE2b-256 | 9fc6c8dbca806036408f3fbeb67cf9219a2526a4ef64fd80b49ff73fb285c19c |
Hashes for graphlib2-0.2.13-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7d45dedc5ff85273fa1c6f4c0ed236d8e889469886b9e2ed0c59349b55bc081 |
|
MD5 | ea2108b02cd0c211cf38badaa1e30dc8 |
|
BLAKE2b-256 | 1c9fd5670957aef820a69aea62f092993e3adf09c3fc3a184eda791650d279ee |
Hashes for graphlib2-0.2.13-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aade5a944efb7d042d5e900c403de02b5ffc14d1636d499755d8909f08573d61 |
|
MD5 | 06a3f9429d32b62843715b2e2b135a59 |
|
BLAKE2b-256 | 6724cc6f0dea9f199dfcf42aaab7f625bc76bc0822d9a48607e04d9a6e9d6646 |
Hashes for graphlib2-0.2.13-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c81d765a3821204b332950c5bc70f4fedc4a10b0ab91dc4954a0e63995f2e2d6 |
|
MD5 | d22ff528093d7fdfa83d2818e5a63b9e |
|
BLAKE2b-256 | 129011b6707ed36867a0c0f230c7baae6626a5029fb648e428ea65585e02e6da |
Hashes for graphlib2-0.2.13-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c4aa5b4e516fd8e2b81b84a91aeaa166f20d05253cef92bbcd89485739cf5c1 |
|
MD5 | 0c9cdbe209417f1d552e2d1bfd240329 |
|
BLAKE2b-256 | e6d85142b7f9386131fa3a18cfd4ffda90ea9b0cc1c9b5a905e765e50e2b0f63 |
Hashes for graphlib2-0.2.13-pp37-pypy37_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88027d07d54c891bbeb8b1e98ea2396cea041b3dd9d5944c6e8693aa0dd0d653 |
|
MD5 | 0645f5ba73fd1cc38fcb1d4c5de393ec |
|
BLAKE2b-256 | 385cdef64e466e20ed87eec87840d65a3ef55e098a841123fd37264b9be0e936 |
Hashes for graphlib2-0.2.13-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95f925b9c449951f5519c3ca8fe534176e00bb18e64816c38b5643ddbfbbefbe |
|
MD5 | ecc185f0550243aaa27ca2668e6f13bc |
|
BLAKE2b-256 | c1184df9dd787a45104899410cf1831c20fde16aa2040326a32a4be7d09ef321 |
Hashes for graphlib2-0.2.13-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df77891b475857afb7303170df4122400094f0002fcd61dda777425adefb4800 |
|
MD5 | a71ee2ea5f3411a3f7be04e060f92990 |
|
BLAKE2b-256 | e121bed3ebd6578c547b731125ae41052214ed61a703708f35b482e31fd08b42 |
Hashes for graphlib2-0.2.13-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44c14ef7a83f41d5b27b4a3a61d6e52da088a6faf65309a2218483d2037a69d3 |
|
MD5 | aedf79f3ab8e006cfbc622781e12a250 |
|
BLAKE2b-256 | 966aafffb85c5ffb82149f29491138baf2d1f975cdf4555838b963352505455b |
Hashes for graphlib2-0.2.13-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9af9e2b2584e5f3f6d4409956ce65eb6dc364b054f776fc2bd0ddf362e5ce6b |
|
MD5 | 1a2303c1ca8a9a0b8d2d255519945684 |
|
BLAKE2b-256 | a586e5968ba44ca5e6f116a97b4df4c02a321dd6c863e38281e4ab3d2d8ed229 |
Hashes for graphlib2-0.2.13-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd9023a0d7708c681b256609b493920edbc40c79f05e819f9bb178256167fd01 |
|
MD5 | 887b0238061a421f82c73ecb9a138dcd |
|
BLAKE2b-256 | c3203545232e0e0c2f50ff5b2308e64fd7362ed41da0b86f1d60baaa662440e4 |
Hashes for graphlib2-0.2.13-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd70daea212f16064596d66fa53152edfb47b0fe56bb083d59aa3b79881c1e4f |
|
MD5 | a80235a01efd0c4f172a5afa11c18365 |
|
BLAKE2b-256 | 6289aa5cfd65d7869adcd23062518fb798f475e78d26b85dcb1e9c6b94dfd930 |
Hashes for graphlib2-0.2.13-cp37-abi3-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06a0bcc27558f99abb226197ccd47afa217be668c54082625b82703374417e97 |
|
MD5 | 235eb9c6764ed758e5ab33f8c4420060 |
|
BLAKE2b-256 | 01527c3811e6b3cd1a75bfd84cf4d0880c4ad2a2760e00ba0d1741d9b791f501 |
Hashes for graphlib2-0.2.13-cp37-abi3-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99238b8ff342a307cc466722cc2c81e3e910b0ffdf36135d0c28bb1c4272764e |
|
MD5 | 923603312cad42a45f357c7b7c9867d6 |
|
BLAKE2b-256 | b9c667f1ea3d7095a060e1022b0c356e73d16c3d2e57227524bb95befaef6436 |
Hashes for graphlib2-0.2.13-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9db3e436b322c1ed27635a7a42af7cde97a94a4f84c980de6bcf9a568448d1eb |
|
MD5 | 4e42c3b2d6f713aea21caa4ea77d8b57 |
|
BLAKE2b-256 | dc205bb30b9556c09501a43fe083d5920a0a68663c2a04db27c5dc552436e797 |
Hashes for graphlib2-0.2.13-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2afcd1e5c888f42a44e9bde95cf70cd676354b38fbb3b5eb9ff4c2447c68f9e2 |
|
MD5 | ecdf72f827eaa0adb46ac1073c1d2bb6 |
|
BLAKE2b-256 | 151307c6831696d505ed625e33169a371bfbe347c37c55e18d4cca1a8d12291c |
Hashes for graphlib2-0.2.13-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 855dac2f17cf336443a43864e7f40b6c5f1a02886ea7285ca6212dff2491a66d |
|
MD5 | dea7c278f31a64fde3a345f5f5ade435 |
|
BLAKE2b-256 | 0bb641abfec6fab8d510244c111fa9fdb507999ad1802e0b6f92e7801f192bba |
Hashes for graphlib2-0.2.13-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89c16367723f9cd71cccb3852d2c55cc9fce2e02ea4999497bf91ed6f7709ec4 |
|
MD5 | fb39d1850a8a12603564e581398f1ac9 |
|
BLAKE2b-256 | 750a69ff2fef4007bbdae29654b0aaad2d1b0555c35689ae7f979e56eec60cf4 |