-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Queue type (which just wraps deque) #so
- Loading branch information
Showing
3 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod queue; | ||
pub use self::queue::Queue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod collection; | ||
|
||
pub mod strtype; | ||
|
||
pub mod numtype; | ||
|