This commit is contained in:
Jason Toffaletti 2013-10-08 08:09:13 -07:00 committed by Brian Anderson
parent 8c95f558d0
commit 5e91ac10b6

View File

@ -57,8 +57,12 @@ struct Queue<T> {
impl<T: Send> State<T> {
fn with_capacity(capacity: uint) -> State<T> {
let capacity = if capacity < 2 || (capacity & (capacity - 1)) != 0 {
// use next power of 2 as capacity
2f64.pow(&((capacity as f64).log2().floor()+1f64)) as uint
if capacity < 2 {
2u
} else {
// use next power of 2 as capacity
2f64.pow(&((capacity as f64).log2().ceil())) as uint
}
} else {
capacity
};