indextree-ng

Crates.ioindextree-ng
lib.rsindextree-ng
version1.0.5
sourcesrc
created_at2017-12-12 21:17:25.266167
updated_at2018-01-02 14:30:03.620065
descriptionArena based tree structure by using indices instead of reference counted pointers. Fork of indextree by Sascha Grunert which allows to remove nodes
homepagehttps://github.com/raymontag/indextree
repositoryhttps://github.com/raymontag/indextree
max_upload_size
id42884
size29,033
GrayFox (raymontag)

documentation

https://docs.rs/indextree-ng

README

indextree-ng

Build Status

Arena based tree structure with multithreading support

This is a fork of the indextree crate which allows to remove nodes. The original version was not capable of removing nodes as the initial idea was to drop all nodes at the same time if the lifetime of the underlying memory arena has ended.

The arena tree structure is using a single Vec, a HashMap and numerical identifiers. Every node holds an id which is mapped to an index of the vector via the HashMap. This allows to drop single nodes before the lifetime of the arena hash ended.

There is no RefCell and mutability is handled in a way much more idiomatic to Rust through unique (&mut) access to the arena.

Example usage

use indextree_ng::Arena;

// Create a new arena
let arena = &mut Arena::new();

// Add some new nodes to the arena
let a = arena.new_node(1);
let b = arena.new_node(2);

// Append b to a
a.append(b, arena);
assert_eq!(b.ancestors(arena).into_iter().count(), 2);

//Access a node
assert_eq!(arena[b], 2);

// Remove a node
arena.remove_node(a);
assert_eq!(b.ancestors(arena).into_iter().count(), 1);

Commit count: 24

cargo fmt