Fortune for parapop's current commit: Future small blessing − 末小吉master
parent
6a4b2e918d
commit
c7932794f0
@ -0,0 +1,28 @@
|
||||
//! Helper functions & types
|
||||
use super::*;
|
||||
|
||||
/// Like PhantomData but for a lifetime. Essentially PhantomData &'a ()
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Copy)]
|
||||
#[repr(transparent)]
|
||||
pub struct PhantomLifetime<'a>(std::marker::PhantomData<&'a ()>);
|
||||
|
||||
impl<'a> PhantomLifetime<'a>
|
||||
{
|
||||
#[inline(always)]
|
||||
pub const fn new() -> Self { Self (std::marker::PhantomData) }
|
||||
}
|
||||
|
||||
unsafe impl<'a> Send for PhantomLifetime<'a>{}
|
||||
unsafe impl<'a> Sync for PhantomLifetime<'a>{}
|
||||
impl<'a> private::Sealed for PhantomLifetime<'a>{}
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn address_eq_overlap<'t, 'u, T, U>(a: &'t T, b: &'u U) -> bool
|
||||
{
|
||||
std::ptr::eq(a as *const _, b as *const _ as *const T)
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn address_eq<'a, 'b, T: ?Sized>(a: &'a T, b: &'b T) -> bool
|
||||
{
|
||||
std::ptr::eq(a as *const _, b as *const _)
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
//! Single-index references.
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug)] // PartialEq, PartialOrd
|
||||
pub struct Ref<'re, 'a, T: 'a>
|
||||
{
|
||||
pub(super) pop: &'re Populator<'a, T>,
|
||||
pub(super) idx: usize,
|
||||
//TODO: Maybe add inserted bool, or state representing if this Ref has made a change to the populator. The value will be loaded on creation of the Ref, and will be used as a cached version of `completes[idx].load()`
|
||||
//TODO: OR: Hold a reference to the actual AtomicBool at `idx` itself?
|
||||
}
|
||||
|
||||
|
||||
impl<'re, 'a, T: 'a> PartialEq for Ref<'re, 'a, T>
|
||||
{
|
||||
#[inline]
|
||||
fn eq(&self, other: &Self) -> bool
|
||||
{
|
||||
address_eq(self.pop, other.pop) && self.idx == other.idx
|
||||
}
|
||||
}
|
||||
|
||||
impl<'re, 'a, T: 'a> PartialOrd for Ref<'re, 'a, T>
|
||||
{
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
if address_eq(self.pop, other.pop) {
|
||||
self.idx.partial_cmp(&other.idx)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'re, 'a, T: 'a> Ref<'re, 'a, T>
|
||||
{
|
||||
/// The index that this `Ref` refers to.
|
||||
#[inline]
|
||||
pub fn slot(&self) -> usize
|
||||
{
|
||||
self.idx
|
||||
}
|
||||
/// Checks if the references item currently exists.
|
||||
#[inline]
|
||||
pub fn exists(&self) -> bool
|
||||
{
|
||||
self.pop.exists(self.idx)
|
||||
}
|
||||
/// Try to insert `value` at the referred slot.
|
||||
///
|
||||
/// If the slot already has a value, then `Err(value)` is returned, otherwise, `value` is inserted into the table and the number of items now populated is returned.
|
||||
#[inline]
|
||||
pub fn try_insert(&self, value: T) -> Result<usize, T>
|
||||
{
|
||||
self.pop.try_insert(self.idx, value)
|
||||
}
|
||||
/// Insert `value` at the referred slot.
|
||||
///
|
||||
/// # Panics
|
||||
/// If the slot has a value.
|
||||
#[inline]
|
||||
pub fn insert(&self, value: T) -> usize
|
||||
{
|
||||
self.pop.insert(self.idx, value)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//TODO: OwnedRef: From Arc<Self> receiver of Arc<Populator<'static, T>>
|
||||
//TODO: RefEx: Exclusive reference, holds &'ref mut Populator<'a, T>
|
Loading…
Reference in new issue