|
| 1 | +use crate::traits::{ConcurrentQueue, Handle}; |
| 2 | +use lprq_rs::LPRQueue; |
| 3 | + |
| 4 | +pub struct LPRQueueRSHandle<'a, T>{ |
| 5 | + queue: & 'a LPRQRS< T> |
| 6 | +} |
| 7 | + |
| 8 | +pub struct LPRQRS<T>{ |
| 9 | + pub lprqueue: LPRQueue<T> |
| 10 | +} |
| 11 | + |
| 12 | +impl <T> ConcurrentQueue<T> for LPRQRS<T>{ |
| 13 | + fn register(&self) -> impl Handle<T>{ |
| 14 | + LPRQueueRSHandle{ |
| 15 | + queue: self, |
| 16 | + } |
| 17 | + } |
| 18 | + |
| 19 | + fn get_id(&self) -> String { |
| 20 | + String::from("lprq-rs") |
| 21 | + } |
| 22 | + |
| 23 | + fn new(_size: usize) -> Self { |
| 24 | + LPRQRS { |
| 25 | + lprqueue: LPRQueue::new(), |
| 26 | + } |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +impl <T> Handle<T> for LPRQueueRSHandle<'_, T> { |
| 31 | + fn push(&mut self, value: T) -> Result<(), T> { |
| 32 | + self.queue.lprqueue.enqueue(value); |
| 33 | + Ok(()) |
| 34 | + } |
| 35 | + |
| 36 | + fn pop(&mut self) -> Option<T> { |
| 37 | + self.queue.lprqueue.dequeue() |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +#[cfg(test)] |
| 42 | +mod tests { |
| 43 | + use super::*; |
| 44 | + |
| 45 | + #[test] |
| 46 | + fn create_bq() { |
| 47 | + let q: LPRQRS<i32> = LPRQRS::new(100); |
| 48 | + q.lprqueue.push(1); |
| 49 | + assert_eq!(q.lprqueue.dequeue().unwrap(), 1); |
| 50 | + } |
| 51 | + #[test] |
| 52 | + fn register_bq() { |
| 53 | + let q: LPRQRS<i32> = LPRQRS::new(100); |
| 54 | + let mut handle = q.register(); |
| 55 | + handle.push(1).unwrap(); |
| 56 | + assert_eq!(handle.pop().unwrap(), 1); |
| 57 | + } |
| 58 | + #[test] |
| 59 | + fn test_order() { |
| 60 | + let q: LPRQRS<i32> = LPRQRS::new(100); |
| 61 | + if crate::order::benchmark_order_i32(q, 10, 5, true, 10).is_err() { |
| 62 | + panic!(); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments