Skip to main content

tree module package

Project description

Work in Progess, please ignore this project for now.

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.1-cp312-cp312-macosx_11_0_arm64.whl (264.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

pyo3Tree-0.1.1-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.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyo3Tree-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4b41c19e71941795c56ec851d3440b7a2e455419ea8688ea6286faf22c69a7b1
MD5 0906913cab626694dda7dd7370023e1e
BLAKE2b-256 0f8a6a6069f2f4ab08ed8d11770551a9112347d545dab2739f39eb831c2f48c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyo3Tree-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1fd4c08126ef8637d5542240b5123128fc7a5fe38e716d43fc4ec3796ad9ac36
MD5 aa8973b6de9a6252ef929817a70d4aa0
BLAKE2b-256 93f68a82a4281104f3d38ca74e360b7a865a8e9302b2a7e628ea40a75a85afb5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyo3Tree-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 da2e4a16af1f23fbde859066f402d290412895a1b607872991918dcb1f193e27
MD5 9ba5f919e6a071edcf86e91da247e911
BLAKE2b-256 b751f726de03bc0f673944288098c55aa0689391fae72e76942c2494a4e232ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyo3Tree-0.1.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 36acd4ef58a65154929b4c830fe72e0264100064847687e0490c9ae15d5feedd
MD5 9842105bb63b0fd2bef2fcec62ed9659
BLAKE2b-256 96b88a2a171881c315e5795bcd75a8e761cb9f6f1d3b5ca86ea5500a8c14de31

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