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).
- 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.16-pp38-pypy38_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 129e2b3ff43ea4b9f34b60a5b086b4b270f1f6bd068fd6bee24278732a50d422 |
|
MD5 | c505a9fcb1818f9b7bd1ffbd7b816070 |
|
BLAKE2b-256 | b2badf0263f7b167e371d50a5425bd954f3cc6da488754e5be6922eb86e58c25 |
Hashes for graphlib2-0.2.16-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dfed6a4a5feb3581a2da845c3dd5a8e57c9251117ee0fe80f446f907aa865e0 |
|
MD5 | 3379b4389c2790a3b0e1ae778ef88ad2 |
|
BLAKE2b-256 | 0904de4a9199560d4a6205701117fb1cdd9888e9e67bb2309af8de34a13f8eae |
Hashes for graphlib2-0.2.16-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bc5e0a6f80bbd19af99c2011f735ccc3be0d6ea5e47aa601420a6167f0e8039 |
|
MD5 | 86ac386377610df3f781f41ca78a74d7 |
|
BLAKE2b-256 | b4d6ed7e88d4fdece4b9e5ad39a54e4e65d37a931ecb1f1cdf5cf0f343dc2649 |
Hashes for graphlib2-0.2.16-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1a8911112fc8c6881155a9d91a94a1a5f36bca8300fc61b6305a7999f6909fc |
|
MD5 | 88f7d54b67d2f1b767e5f4caaf2abf6e |
|
BLAKE2b-256 | c437bd79671add64ae4bb6e55af36f30859a51a8f72c7d761db8fa55b3899b6e |
Hashes for graphlib2-0.2.16-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e22c4986e49f3d32f49c1df0a5c4b484d9a64e88ebd9cdf7d5bf2ac7372b2809 |
|
MD5 | c76bc4b886fa545411a3bc47872f05ea |
|
BLAKE2b-256 | 6428027c3850edcd11d4fbcf6038f4bfdd94ab61051089ab9b7ca5371381af19 |
Hashes for graphlib2-0.2.16-pp37-pypy37_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3709f27ced16f5c48258e35ec774907e7fed336609e56fa914ca9a66db29879 |
|
MD5 | 80d1c32f55245b22cb693e7d4c274463 |
|
BLAKE2b-256 | 22b7e5d505fc65b597921e4c5c891f47f33706e04643a7099fdbd6048dfbcef0 |
Hashes for graphlib2-0.2.16-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57ca1875bdd17cdd4ac64bc1bccf4ea9bee8800532644fc56ce32501e03b1c7c |
|
MD5 | e512aa7905b611d8bbdc3d8d0eda4d3b |
|
BLAKE2b-256 | b864e6b4af9c710106bb9366646aa0b608232b8ff8373cd74776e7e419a79d7d |
Hashes for graphlib2-0.2.16-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e1d475cb759498fcb1379d8603a64259fc39753d90ea4d8c0b5ee0a42caac00 |
|
MD5 | cdb3d8b031807cdba9a35445b791549e |
|
BLAKE2b-256 | 4b4929585b4c42eacf2cd0404b3974269e1e7a7445a4a41f5d36897df5eed8b2 |
Hashes for graphlib2-0.2.16-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6fabf68f06a00535a28819fec935419c4ed5b3345de4ce343ccd8be18e50f16 |
|
MD5 | dd71c9a3bf66ecd04a9a86946bc05c56 |
|
BLAKE2b-256 | 6fb65006ffc12fd978230a75d2e415173ebe4a7dbbe82da76175b2eddca92356 |
Hashes for graphlib2-0.2.16-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26044611f933c9232dfac88fee41b5dcd34aa202bf2cdc86ed6f78c67118f76e |
|
MD5 | 1bdf13cfa265c06069a13348d948ac29 |
|
BLAKE2b-256 | 12df5be66b980e295a4ecd74976b1e3afd8c5c969371e1ea9565ee1e25f87039 |
Hashes for graphlib2-0.2.16-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d40015dc634f45088ec8fb7f8e7d53b7ff204a75677717991e1c6e1fea67f0a |
|
MD5 | 3ad13b2dc7ca5f1fe6a2005f45b55d6d |
|
BLAKE2b-256 | 4e9686af66e70367065217a973ea3ba2200943891cac49269db207d7e6e573ec |
Hashes for graphlib2-0.2.16-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a719a079375c138f338b91e78348b4c379e47f1e181f63626daa14be5ba3afad |
|
MD5 | 94a3c6bdd90abd0ea9d097361908db88 |
|
BLAKE2b-256 | 039439c27bad17b4fd9b89ce4b8506b58f4d97f2088de13eeba683172ab78ebd |
Hashes for graphlib2-0.2.16-cp37-abi3-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b78a6d072b6309150a6a8ec63bb31c53925e185185e55dc6609c7f33cc15b871 |
|
MD5 | c3ebca78cdb0f593a708fc6a9afd13fa |
|
BLAKE2b-256 | 0a4380f073b0f36c37c38fb4d9619955ede85532050e6ef84ad55ed5faa1c1b0 |
Hashes for graphlib2-0.2.16-cp37-abi3-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d8b055316c17fa08994e71841481615f0443c2bf2bf00f247599bb93f10e246 |
|
MD5 | f79189b679b1f32bfa2cb11f10484c0c |
|
BLAKE2b-256 | cc84ef45e65f5ef73dac6b7a9030d2383536992d5c4222308cd20ee7dfcd62ad |
Hashes for graphlib2-0.2.16-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa6adddfda4080deb6e6037ea1c6af4a4bb20e8c3c4767ec9568e72db39af2b3 |
|
MD5 | ad5b8780fc0ad39425e02314d27cd182 |
|
BLAKE2b-256 | 75733cd11aa1b5565aebf170940942eb2cde5e0805b472a3f2bd28695706a970 |
Hashes for graphlib2-0.2.16-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9e950c6acbea5ecd9c47ab4a3ce8c159cd4d0fddac02165a058bf9039fcb449 |
|
MD5 | 237215eb4a0b2611f7d9f640980705ec |
|
BLAKE2b-256 | 39824ad27ae7c06896e9bfd7bcbc95e26d47eda4ba40074b0f79644ed14d0c67 |
Hashes for graphlib2-0.2.16-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c50cf2b942f69729aa1e904b8f0140bcd59b11b26aff1d23847c80597fc1f077 |
|
MD5 | 9814623be6e97b3df8bb62bb6cc11089 |
|
BLAKE2b-256 | a96c10e2b3e58a6cb7fff4512a165eb5d853c9c4b0e000c3ba36a53e18bc44a6 |
Hashes for graphlib2-0.2.16-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b7c8d6a77c1d3f60da21b01e51e603ab973dd8986b5d644e08b85fc7e38f7df |
|
MD5 | 1e71431d4c8578d2b4b6de1d7c542128 |
|
BLAKE2b-256 | 57f0e954d36a3b8b64c61d9ff70964c00d7d527bb57dd00a347b0805bd73f7bb |