From 11a7bf6a58776bd44fdf85dd0bc828b7440c6c34 Mon Sep 17 00:00:00 2001 From: Danil Akhtarov Date: Sun, 26 Nov 2023 22:40:46 +0300 Subject: [PATCH] refactor: add with_capacity --- src/backends/memory.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/backends/memory.rs b/src/backends/memory.rs index dacf3a8..6168c22 100644 --- a/src/backends/memory.rs +++ b/src/backends/memory.rs @@ -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)] @@ -40,6 +40,12 @@ where } } + pub fn with_capacity(capacity: usize) -> MemoryBackend { + MemoryBackend { + queue: Arc::new(Mutex::new(RefCell::new(Vec::with_capacity(capacity)))), + } + } + pub fn read(&self, score: &S) -> Vec { self.queue .lock()