aboutsummaryrefslogtreecommitdiff
path: root/src/tree.rs
diff options
context:
space:
mode:
authorJJ2023-10-27 07:51:37 +0000
committerJJ2023-10-27 07:51:37 +0000
commit6017d62db7600af491592e4f0d78611f33dc6b5e (patch)
treec2f42e4264692f92b0eded551617bf8bd8b1c948 /src/tree.rs
parent2ea4fd4c09ad71c4ac648cf3645426476dd7521f (diff)
minor updates
Diffstat (limited to 'src/tree.rs')
-rw-r--r--src/tree.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/tree.rs b/src/tree.rs
index 02dc749..8e2e1d0 100644
--- a/src/tree.rs
+++ b/src/tree.rs
@@ -1,4 +1,4 @@
-/// A simple append-only tree data structure. Represented as a Vec.
+/// A simple flat append-only tree data structure. Represented as a Vec.
pub struct Tree<T>(Vec<Node<T>>);
/// The associated Node to the Tree.
@@ -12,11 +12,16 @@ pub struct Node<T> {
data: T
}
+/// Nodes themselves are not held onto and used, instead we use a NodeId,
+/// only valid in the context of a particular Tree. There is not a great
+/// way to enforce this validity that I know of, unfortunately.
#[derive(Copy, Clone)]
pub struct NodeId(usize);
impl<T> Tree<T> {
/// Create a new Tree with a root element.
+ /// You should only make one Tree in any given context.
+ /// Otherwise there are safety risks with using the wrong NodeId for a Tree.
pub fn new(data: T) -> Tree<T> {
Tree(vec![Node {
parent: None, previous_sibling: None,