Skip to content

Commit

Permalink
Add a Queue type (which just wraps deque) #so
Browse files Browse the repository at this point in the history
  • Loading branch information
mverleg committed May 22, 2018
1 parent 97f7f30 commit f33692b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/mango/util/collection/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod queue;
pub use self::queue::Queue;
23 changes: 23 additions & 0 deletions src/mango/util/collection/queue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::collections::VecDeque;

/// A one-ended queue.
/// This is just a wrapper around deque so nobody pushes or pops the wrong end.
pub struct Queue<T> {
deque: VecDeque<T>,
}

impl<T> Queue<T> {
pub fn new() -> Self {
Queue {
deque: VecDeque::with_capacity(16),
}
}

pub fn push(&mut self, value: T) {
self.deque.push_back(value)
}

pub fn pop(&mut self) -> Option<T> {
self.deque.pop_front()
}
}
2 changes: 2 additions & 0 deletions src/mango/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod collection;

pub mod strtype;

pub mod numtype;
Expand Down

0 comments on commit f33692b

Please sign in to comment.