Skip to main content

tree module package

Project description

Requires Rust installed to build.

To build the python module:

$ cd s_tree
$ cd tree_py
$ python -m venv .env
$ source .env/bin/activate
$ pip install maturin
$ maturin develop # Does the magic for building the module
$ maturin develop --release # builds an optimised version of the code (runs much quicker but builds slower)

When running python, import and load as follows:

from tree import Tree
from tree import Node

NOTES:

  • Constructing a tree creates a python object containing a reference to the rust object. The nodes can hold any Python object (which will be tracked by Pythons memory mananger). The rest of the tree should be managed by Rust, on a combination of the stack and the heap. If I understand it correctly, each node and tree instance will exist on the stack, whereas all the Vectors and reference counters will live on the heap.
  • the file tree_py.rs is a wrapper of tree_rs.rs and provides the interfaces to the rust objects and their attributes.
  • Node and Tree are compatible with threading (pyo3 wasn't allowing the rust single thread reference implementation).
  • The rust implementation uses 'Atomic Reference counters' to determine whether to drop objects, each python owned reference to a rust owned Node or Tree adds to the reference counter.
  • Each piece of data stored is fully owned by Python, the rust implementation stores a reference to the Python object, which I presumes adds to Pythons reference count for that object.

Current functions:

Node

  • Node(data) - returns a Python owned reference to a rust owned Node containing a reference to the python object passed in as data.
  • Node has four attributes: id, data, children[], parent.
  • node.id - returns a python owned string with the nodes uuid
  • node.data - returns a python owned reference to the python owned object stored as data
  • node.children - returns a python owned vector containing python owned references to the rust owned children nodes
  • node.parent - returns a python owned reference to the rust owned parent node

Tree

  • Tree() - builds an empty tree with a root node containing no data
  • Tree(node) - builds a tree with the specified node as root
  • Tree.import(pythonDictionary) - imports the specified python tree (which should be of type PyDict) and returns a reference to the rust Tree.
  • tree.find_by_id("uuid") - returns a python owned reference to the rust owned Node with id "uuid"
  • tree.add(node) - Adds the node to the trees root node
  • tree.add(node, parentNode) - adds the node as a child of the parent node
  • tree.get_root - returns a python owned reference to the rust owned root node
  • tree.move_node(tgt_node, parent_node) - moves the tgt_node to the parent node. This throws an error if the parent node is an ancestor of the child node. Note: 'move' is a reserved word in rust and functions cannot be named 'move'
  • tree.get_ancestors(node) - returns a python owned vector of python owned references to the rust owned ancestors to the specified node.
  • tree.export() - returns a completely python owned dictionary representation of the Tree.

This is roughly as fast as the python tree implementations, however 'find_node_by_id' is much faster ~10x. It seems like the initial object generation is roughly the same speed as the python implementations.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyo3tree-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (263.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyo3tree-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (265.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyo3tree-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (265.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyo3tree-0.1.0-cp39-cp39-macosx_11_0_arm64.whl (265.2 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

pyo3Tree-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (264.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyo3Tree-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (265.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyo3Tree-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (265.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyo3Tree-0.1.0-cp39-cp39-macosx_11_0_arm64.whl (265.2 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file pyo3tree-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyo3tree-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9016487e4c33ad2ef718eb764628d5b147b626d4363deb3150e7dca0702f0c32
MD5 1ea0ff6ebd8bba9d59c3a130c7276489
BLAKE2b-256 3109fc1b4d98617325432102f64e63331dee3e1b2067bc264a37235704c57de1

See more details on using hashes here.

File details

Details for the file pyo3tree-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyo3tree-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e6a36176e6564651184d1a1a10390ba747c5546b60e7e59a4e28a62cdf50d7d2
MD5 68924f4511984733f42c80ff237ac79e
BLAKE2b-256 295ff929697fcbf02ac5af88ce0686a9943a808444ccbad74a6e71244dbcf888

See more details on using hashes here.

File details

Details for the file pyo3tree-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyo3tree-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e10e150e563ea1bb61466406ddc167bbbff3925be7e1dd236ff83aa680858ec6
MD5 6ad6731c62634d5681653bd89c0868d8
BLAKE2b-256 6330937f7fdf0a898f8d9c4ad5088c1a2b6d464d0288337d48c9826d8c5e5b07

See more details on using hashes here.

File details

Details for the file pyo3tree-0.1.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyo3tree-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bb29b2ace37dd2a0bb7e8b3a8c0e1a533cc346779a36fc594ff9b6b4e5e04500
MD5 b2ae4d199914c317bb816eee07f75aea
BLAKE2b-256 d169b0d8630549bfa06bf3b8c039658a78f22c6372fa936087f11cfb29defb7d

See more details on using hashes here.

File details

Details for the file pyo3Tree-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyo3Tree-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 524c2672b368cad89b18ca1cfa4774718b65851e5a7d092be79c40a3c6883a38
MD5 5fe9c592099b4243e35584545aa24bf5
BLAKE2b-256 ef7b3b162cae736e52be80412bfddc514d6c29d24b8638309a0f9f96bc90740b

See more details on using hashes here.

File details

Details for the file pyo3Tree-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyo3Tree-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d4eff8b7bbdb1267d8cf5cbb56f2e090d7aa47602583bac003f2153235772e0c
MD5 8b6d73cf5aa31abe13b5c297fc32bf0b
BLAKE2b-256 2d5e6ca1a637dedb8e0d5e41c658bced34a63d77cab653928b50deaff15b5299

See more details on using hashes here.

File details

Details for the file pyo3Tree-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyo3Tree-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 743a224dc543a9c194a38b36333858f1fb15960aafab46f57b0a1169ea77a611
MD5 2dd46ac321097a83d5aae46cfe7c5e26
BLAKE2b-256 a97b94a78d3929a2fc0591444f214b05e805f71fbcac915cd85918d2899613e1

See more details on using hashes here.

File details

Details for the file pyo3Tree-0.1.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyo3Tree-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 db9863e2f19c7a995fda597dbd25b145925feed241049bdd4a3241c1013fede8
MD5 d64054144535033b7c3d0810cf4176e8
BLAKE2b-256 be32dce314e617403363dbf05b158c3dbd89149aa346bdab003ebb0f28674a8c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page