Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Vec::drain, as_(mut_)view on the *Inner types, generic over Storage #500

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,22 @@ impl<T, K, const N: usize> BinaryHeap<T, K, N> {
pub fn into_vec(self) -> Vec<T, N> {
self.data
}
}

impl<T, K, S: Storage> BinaryHeapInner<T, K, S>
where
T: Ord,
K: Kind,
{
/// Get a reference to the `BinaryHeap`, erasing the `N` const-generic.
pub fn as_view(&self) -> &BinaryHeapView<T, K> {
self
S::as_binary_heap_view(self)
}
/// Get a mutable reference to the `BinaryHeap`, erasing the `N` const-generic.
pub fn as_mut_view(&mut self) -> &mut BinaryHeapView<T, K> {
self
S::as_mut_binary_heap_view(self)
}
}

impl<T, K, S: Storage> BinaryHeapInner<T, K, S>
where
T: Ord,
K: Kind,
{
/* Public API */
/// Returns the capacity of the binary heap.
pub fn capacity(&self) -> usize {
Expand Down
9 changes: 4 additions & 5 deletions src/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,18 @@ impl<T, const N: usize> Deque<T, N> {
self.back - self.front
}
}
}

impl<T, S: Storage> DequeInner<T, S> {
/// Get a reference to the `Deque`, erasing the `N` const-generic.
pub fn as_view(&self) -> &DequeView<T> {
self
S::as_deque_view(self)
}

/// Get a mutable reference to the `Deque`, erasing the `N` const-generic.
pub fn as_mut_view(&mut self) -> &mut DequeView<T> {
self
S::as_mut_deque_view(self)
}
}

impl<T, S: Storage> DequeInner<T, S> {
/// Returns the maximum number of elements the deque can hold.
pub fn storage_capacity(&self) -> usize {
self.buffer.borrow().len()
Expand Down
9 changes: 9 additions & 0 deletions src/histbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ impl<T, S: Storage> HistoryBufferInner<T, S> {
}

impl<T, S: Storage> HistoryBufferInner<T, S> {
/// Get a reference to the `HistoryBuffer`, erasing the `N` const-generic.
pub fn as_view(&self) -> &HistoryBufferView<T> {
S::as_histbuf_view(self)
}
/// Get a mutable reference to the `HistoryBuffer`, erasing the `N` const-generic.
pub fn as_mut_view(&mut self) -> &mut HistoryBufferView<T> {
S::as_mut_histbuf_view(self)
}

unsafe fn drop_contents(&mut self) {
unsafe {
ptr::drop_in_place(ptr::slice_from_raw_parts_mut(
Expand Down
14 changes: 7 additions & 7 deletions src/linear_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ impl<K, V, const N: usize> LinearMap<K, V, N> {
pub const fn new() -> Self {
Self { buffer: Vec::new() }
}
}

impl<K, V, S: Storage> LinearMapInner<K, V, S>
where
K: Eq,
{
/// Get a reference to the `LinearMap`, erasing the `N` const-generic.
pub fn as_view(&self) -> &LinearMapView<K, V> {
self
S::as_linear_map_view(self)
}

/// Get a mutable reference to the `LinearMap`, erasing the `N` const-generic.
pub fn as_mut_view(&mut self) -> &mut LinearMapView<K, V> {
self
S::as_mut_linear_map_view(self)
}
}

impl<K, V, S: Storage> LinearMapInner<K, V, S>
where
K: Eq,
{
/// Returns the number of elements that the map can hold.
///
/// Computes in *O*(1) time.
Expand Down
11 changes: 6 additions & 5 deletions src/mpmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ impl<T, const N: usize> MpMcQueue<T, N> {
enqueue_pos: AtomicTargetSize::new(0),
}
}
}

impl<T, S: Storage> MpMcQueueInner<T, S> {
/// Get a reference to the `MpMcQueue`, erasing the `N` const-generic.
///
///
Expand All @@ -196,8 +199,8 @@ impl<T, const N: usize> MpMcQueue<T, N> {
/// let view: &MpMcQueueView<u8> = &queue;
/// ```
#[inline]
pub const fn as_view(&self) -> &MpMcQueueView<T> {
self
pub fn as_view(&self) -> &MpMcQueueView<T> {
S::as_mpmc_queue_view(self)
}

/// Get a mutable reference to the `MpMcQueue`, erasing the `N` const-generic.
Expand All @@ -217,11 +220,9 @@ impl<T, const N: usize> MpMcQueue<T, N> {
/// ```
#[inline]
pub fn as_mut_view(&mut self) -> &mut MpMcQueueView<T> {
self
S::as_mut_mpmc_queue_view(self)
}
}

impl<T, S: Storage> MpMcQueueInner<T, S> {
fn mask(&self) -> UintSize {
(S::len(self.buffer.get()) - 1) as _
}
Expand Down
14 changes: 4 additions & 10 deletions src/sorted_linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,26 +197,20 @@ impl_index_and_const_new!(LinkedIndexU8, u8, new_u8, { u8::MAX as usize - 1 });
impl_index_and_const_new!(LinkedIndexU16, u16, new_u16, { u16::MAX as usize - 1 });
impl_index_and_const_new!(LinkedIndexUsize, usize, new_usize, { usize::MAX - 1 });

impl<T, Idx, K, const N: usize> SortedLinkedList<T, Idx, K, N>
impl<T, Idx, K, S> SortedLinkedListInner<T, Idx, K, S>
where
Idx: SortedLinkedListIndex,
S: Storage,
{
/// Get a reference to the `SortedLinkedList`, erasing the `N` const-generic.
pub fn as_view(&self) -> &SortedLinkedListView<T, Idx, K> {
self
S::as_sorted_linked_list_view(self)
}

/// Get a mutable reference to the `Vec`, erasing the `N` const-generic.
pub fn as_mut_view(&mut self) -> &mut SortedLinkedListView<T, Idx, K> {
self
S::as_mut_sorted_linked_list_view(self)
}
}

impl<T, Idx, K, S> SortedLinkedListInner<T, Idx, K, S>
where
Idx: SortedLinkedListIndex,
S: Storage,
{
/// Internal access helper
#[inline(always)]
fn node_at(&self, index: usize) -> &Node<T, Idx> {
Expand Down
8 changes: 4 additions & 4 deletions src/spsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,19 @@ impl<T, const N: usize> Queue<T, N> {
pub const fn capacity(&self) -> usize {
N - 1
}
}

impl<T, S: Storage> QueueInner<T, S> {
/// Get a reference to the `Queue`, erasing the `N` const-generic.
pub fn as_view(&self) -> &QueueView<T> {
self
S::as_queue_view(self)
}

/// Get a mutable reference to the `Queue`, erasing the `N` const-generic.
pub fn as_mut_view(&mut self) -> &mut QueueView<T> {
self
S::as_mut_queue_view(self)
}
}

impl<T, S: Storage> QueueInner<T, S> {
#[inline]
fn increment(&self, val: usize) -> usize {
(val + 1) % self.n()
Expand Down
Loading
Loading