Skip to content

Commit

Permalink
refactor: add with_capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
daxartio committed Nov 26, 2023
1 parent d9cadde commit 11a7bf6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/backends/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ where
val: T,
}

/// Memory backend.
/// Memory backend. O(n). This backend is not recommended for production use.
///
/// New in version 0.8.0.
#[derive(Clone, Default)]
Expand All @@ -40,6 +40,12 @@ where
}
}

pub fn with_capacity(capacity: usize) -> MemoryBackend<T, S> {
MemoryBackend {
queue: Arc::new(Mutex::new(RefCell::new(Vec::with_capacity(capacity)))),
}
}

pub fn read(&self, score: &S) -> Vec<T> {
self.queue
.lock()
Expand Down

0 comments on commit 11a7bf6

Please sign in to comment.