From 035496ae973bce0d243df063691bcb5ad455e114 Mon Sep 17 00:00:00 2001 From: Kirpal Grewal Date: Thu, 5 Dec 2024 13:20:03 +0000 Subject: [PATCH] update to be consistent with color --- .github/workflows/ci.yml | 2 +- tree_arena/README.md | 5 +++++ tree_arena/src/lib.rs | 14 +++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6495c4b74..b7071f009 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,7 +102,7 @@ jobs: - name: cargo rdme tree_arena run: | - cargo rdme --check --workspace-project=tree_arena + cargo rdme --check --heading-base-level=0 --workspace-project=tree_arena clippy-stable: name: cargo clippy diff --git a/tree_arena/README.md b/tree_arena/README.md index 03dde230c..9c4e2817c 100644 --- a/tree_arena/README.md +++ b/tree_arena/README.md @@ -4,6 +4,11 @@ [![Linebender Zulip chat.](https://img.shields.io/badge/Linebender-%23masonry-blue?logo=Zulip)](https://xi.zulipchat.com/#narrow/stream/317477-masonry) [![GitHub Actions CI status.](https://img.shields.io/github/actions/workflow/status/linebender/xilem/ci.yml?logo=github&label=CI)](https://github.com/linebender/xilem/actions) + + This crate contains two implementations of a tree for use in [Masonry], one safe and the other unsafe. The safe tree is known to work, and serves as the baseline implementation and is used by default. diff --git a/tree_arena/src/lib.rs b/tree_arena/src/lib.rs index 64a50d30c..c5f861768 100644 --- a/tree_arena/src/lib.rs +++ b/tree_arena/src/lib.rs @@ -12,16 +12,16 @@ //! //! * Otherwise, [Masonry] uses the safe version. //! -//! # Architecture +//! ## Architecture //! -//! ## Safe Tree +//! ### Safe Tree //! //! The safe tree contains a root `TreeArena` which owns the root nodes as `Vec>`, and a`parents_map` tracking the parent of every node. //! Each `TreeNode` subsequently owns its own children as `Vec>`. This model of owneship is thus checked by the rust compiler, //! but has the downside of requiring passing through every ancestor node to access the descendant - //! this requires an O(depth) determination of whether the node is a descendant, followed by O(children) time at each level to traverse the path to the child. //! -//! ## Unsafe Tree +//! ### Unsafe Tree //! //! The unsafe tree arena contains a `DataMap` which **owns** all nodes. The `DataMap` contains: //! @@ -38,24 +38,24 @@ //! The aim of this is to reduce the time needed to access node, as given a node, we only need to determine whether it is a descendant of the node being accessed mutably, //! and do not need to iterate over the children and to flatten the overall tree graph into a hash map. //! -//! ### Shared References +//! #### Shared References //! //! `ArenaRef<'arena, T>` contains the identity of the parent node, a reference to the node data, and `ArenaRefChildren<'arena, T>`. //! The `ArenaRefChildren<'arena, T>` contains the ids of the children of the node, the id of the node, and a reference to the arena. From this `ArenaRefChildren<'arena, T>` it is possible to get shared access to children of the node. //! -//! ### Exclusive References +//! #### Exclusive References //! //! `ArenaMut<'arena, T>` contains the identity of the parent node, a mutable reference to the node data, and `ArenaMutChildren<'arena, T>`. //! The `ArenaMutChildren<'arena, T>` contains the ids of the children of the node, the id of the node, and a mutable reference to the arena. //! From this `ArenaMutChildren<'arena, T>` it is possible to get exclusive access to children of the node. //! -//! ### Safety +//! #### Safety //! //! From the `ArenaMutChildren<'arena, T>`, it is important that we can only access descendants of that node, //! such that we can only ever have exclusive mutable access to the contents of a node, and never have multiple mutable references. //! This invariant is not checked by the compiler and thus relies on the logic to determine whether a node is a descendant being correct. //! -//! ## Complexity +//! ### Complexity //! //! |Operation | Safe | Unsafe | //! | --- | --- | --- |