use std::ops::IndexMut;
use std::ptr;
#[cfg(feature = "arc")]
use std::sync::Arc;
#[cfg(feature = "arc")]
pub type Ref<A> = Arc<A>;
#[cfg(not(feature = "arc"))]
use std::rc::Rc;
#[cfg(not(feature = "arc"))]
pub type Ref<A> = Rc<A>;
pub fn clone_ref<A>(r: Ref<A>) -> A
where
A: Clone,
{
Ref::try_unwrap(r).unwrap_or_else(|r| (*r).clone())
}
pub fn swap_indices<V>(vector: &mut V, a: usize, b: usize)
where
V: IndexMut<usize>,
V::Output: Sized,
{
if a == b {
return;
}
unsafe {
let pa: *mut V::Output = &mut vector[a];
let pb: *mut V::Output = &mut vector[b];
ptr::swap(pa, pb);
}
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Side {
Left,
Right,
}