Crate trait_based_collection
source · [−]Expand description
A collection of data structures that implement the Collection
trait, allowing for a common
interface for all the data structures in this crate. This crate is intended to be a proof of
concept a common interface for all the data structures in Rust. Not all the data structures
are implemented in this crate, but the ones that are implemented are:
Queue
: AFIFO
data structure based on linked nodes.Deque
: AFIFO
andLIFO
data structure based on linked nodes.CircularDeque
: AFIFO
andLIFO
data structure based on a circular array.Stack
: ALIFO
data structure based on a linked nodes.ArrayStack
: ALIFO
data structure based on a fixed size array.BinaryHeap
: APriorityQueue
data structure based on a binary heap.
The crate also contains the following traits:
Collection
: A trait that defines the common interface for all the data structures in this crate.FixedSizeCollection
: A trait that defines the common interface for all the data structures in this crate that have a fixed size.Iterators
: A trait that defines the common interface for all the iterators in this crate.DequeCollection
: A trait that defines the common interface for all the data structures in this crate that are bothFIFO
andLIFO
.
The crate also contains the following macros for easily creating data structures:
queue!
: A macro that creates aQueue
data structure.deque!
: A macro that creates aDeque
data structure.circular_deque!
: A macro that creates aCircularDeque
data structure.stack!
: A macro that creates aStack
data structure.array_stack!
: A macro that creates aArrayStack
data structure.binary_heap!
: A macro that creates aBinaryHeap
data structure.
The crate also contain extra modules for creating new data structures and for creating macros
that can be used to add functionality to the data structures in this crate. For more information
about these modules, see the documentation of macros
.
Example
use trait_based_collection::{import, Deque};
import!();
let mut deque = deque![1, 2, 3];
for i in 4..=10 {
deque.add(i);
}
for i in 1..=10 {
assert_eq!(deque.remove(), Some(i));
}
Re-exports
pub use self::collection::Collection;
pub use self::collection::ExpansionMode;
pub use self::collection::FixedSizeCollection;
pub use self::collection::Iterators;
pub use self::priority_queue::BinaryHeap;
pub use self::queue::CircularDeque;
pub use self::queue::Deque;
pub use self::queue::DequeCollection;
pub use self::queue::Queue;
pub use self::stack::ArrayStack;
pub use self::stack::Stack;
Modules
Traits, helpers, and type definitions for the collection framework.
A collection of all the procedural macros used in this crate. This macros can be divided into
two categories:
A module that contains all the traits that are used in this crate. This module is meant to be
used as a total import using the
prelude::*
syntax. The module also contains a macro that
creates the prelude for this crate allowing to also import the macros in this crate.A collection of different implementations of priority queues. The priority queue is a data
structure that allows you to insert elements into it and then retrieve them in order of
priority. The priority is determined through a comparator function that is passed to the
priority queue.
A collection of different implementations of a queue based on the
FIFO
principle. There some
structs that implement the DequeCollection
trait, which allows them to be used as both
LIFO
and FIFO
queues.A collection of different implementations of a stack based on the
LIFO
principle.Macros
Creates a
ArrayStack
containing the arguments.Creates a
BinaryHeap
containing the arguments.Creates a
CircularDeque
containing the arguments.Creates the prelude for this crate. This macro is meant to a substitute for the
use trait_based_collection::prelude::*
statement if the macros in this crate are also needed.