pub(crate) use crate::fat_array_ptr::FatPtrArray;
pub use crate::prelude::*;
pub(crate) use std::sync::atomic::{AtomicUsize, Ordering};
pub struct RcStruct<T> {
counter: usize,
pub data: T,
}
impl<T> RcStruct<T> {
#[inline]
pub fn new(data: T) -> Self {
Self { counter: 1, data }
}
#[inline]
pub fn decrement(&self) -> usize {
unsafe {
*(&self.counter as *const usize as *mut usize) -= 1;
}
self.counter
}
#[inline]
pub fn increment(&self) -> usize {
unsafe {
*(&self.counter as *const usize as *mut usize) += 1;
}
self.counter
}
}
pub struct ArcStruct<T> {
counter: AtomicUsize,
pub data: T,
}
impl<T> ArcStruct<T> {
#[inline]
pub fn new(data: T) -> Self {
Self {
counter: AtomicUsize::new(1),
data,
}
}
#[inline]
pub fn decrement(&self) -> usize {
self.counter.fetch_sub(1, Ordering::Relaxed) - 1
}
#[inline]
pub fn increment(&self) -> usize {
self.counter.fetch_add(1, Ordering::Relaxed) + 1
}
}