Compatibility: Vector

perennial@0.1.0Updated 10 min readView as markdown

Spec: docs/spec/vector-1.md, docs/spec/vector-2.md, docs/spec/ordering-and-equality.md. Decisions: docs/design/01-interface.md. Legend, status vocabulary and the 01: labels are defined in ../COMPAT.md. GenericVector rows are in crate.md, RRBPool rows in features.md; HashSet: From<Vector<A>> rows are in hashset.md (the target type's file owns a conversion).

Unless a row says otherwise, the impl block is impl<A: Clone> Vector<A> and every row holds for perennial (Arc) and perennial-rc (Rc) alike.

Type and construction

item im 15.1 imbl 7 perennial status test
Vector<A> (type) struct alias of GenericVector<A, DefaultSharedPtr> alias of GenericVector<A, P> with the crate's pointer kind (01:generic) same tests/compat_vector.rs::vector_type
new() -> Self empty, O(1) as im as im same tests/compat_vector.rs::new
unit(a: A) -> Self one element as im as im same tests/compat_vector.rs::unit
with_pool(pool: &RRBPool<A>) -> Self im-rc, feature pool absent provided; pool is a size-only handle, allocation unchanged differs: pool does not pool allocations (01:pools) tests/compat_vector_features.rs::with_pool
pool(&self) -> &RRBPool<A> im-rc pool; size-0 pool if none given absent provided as a size-only handle differs: handle only, no pooled memory (01:pools) tests/compat_vector_features.rs::pool
len(&self) -> usize O(1) as im as im same tests/compat_vector.rs::len
is_empty(&self) -> bool len() == 0 as im as im same tests/compat_vector.rs::is_empty
is_inline(&self) -> bool true while held in the struct; capacity implementation-defined (observed 0..=12 for i32) as im true only when empty: no elements are stored in the struct itself differs: no inline storage (01:no-inline) tests/compat_vector.rs::is_inline
ptr_eq(&self, other: &Self) -> bool O(1) identity; never true for inline; two new() → false as im (Vector: false) false for empty vectors (01:ptr_eq-empty); true for any non-empty vector and its unmodified clone, small ones included differs: a small vector shares heap storage with its clone (01:no-inline) tests/compat_vector.rs::ptr_eq
clear(&mut self) drop all, O(n) as im as im same tests/compat_vector.rs::clear
item im 15.1 imbl 7 perennial status test
get(&self, i: usize) -> Option<&A> None when i >= len as im as im same tests/compat_vector.rs::get
get_mut(&mut self, i: usize) -> Option<&mut A> copy-on-write; None out of range as im as im same tests/compat_vector.rs::get_mut
front(&self) -> Option<&A> first element as im as im same tests/compat_vector.rs::front
head(&self) -> Option<&A> alias of front as im as im same tests/compat_vector.rs::head
front_mut(&mut self) -> Option<&mut A> as im as im same tests/compat_vector.rs::front_mut
back(&self) -> Option<&A> last element as im as im same tests/compat_vector.rs::back
last(&self) -> Option<&A> alias of back as im as im same tests/compat_vector.rs::last
back_mut(&mut self) -> Option<&mut A> as im as im same tests/compat_vector.rs::back_mut
index_of(&self, v: &A) -> Option<usize> (A: PartialEq) first equal position, O(n) as im as im same tests/compat_vector.rs::index_of
contains(&self, v: &A) -> bool (A: PartialEq) linear search as im as im same tests/compat_vector.rs::contains
binary_search(&self, v: &A) -> Result<usize, usize> (A: Ord) slice contract; which of several equal matches is returned is unspecified as im slice contract; equal-match index may differ from the observed one same tests/compat_vector.rs::binary_search
binary_search_by(&self, f: FnMut(&A) -> Ordering) -> Result<usize, usize> slice contract as im as im same tests/compat_vector.rs::binary_search_by
binary_search_by_key(&self, b: &B, f: FnMut(&A) -> B) -> Result<usize, usize> slice contract as im as im same tests/compat_vector.rs::binary_search_by_key

Writing single elements

item im 15.1 imbl 7 perennial status test
set(&mut self, i: usize, v: A) -> A returns old; i >= len panics Vector::index_mut: index out of bounds as im as im same tests/compat_vector.rs::set
update(&self, i: usize, v: A) -> Self persistent set; same panic text as im as im same tests/compat_vector.rs::update
swap(&mut self, i: usize, j: usize) same panic text if either out of range as im as im same tests/compat_vector.rs::swap
insert(&mut self, i: usize, v: A) i == len appends; i > len panics assertion failed: index < self.len() as im as im same tests/compat_vector.rs::insert
remove(&mut self, i: usize) -> A i >= len (also empty) panics assertion failed: index < self.len() as im as im same tests/compat_vector.rs::remove
insert_ord(&mut self, item: A) (A: Ord) keeps order; goes after existing equal elements as im as im same tests/compat_vector.rs::insert_ord
insert_ord_by(&mut self, item: A, f: FnMut(&A, &A) -> Ordering) absent present provided (01 "imbl additions kept") added (imbl API) tests/compat_vector.rs::insert_ord_by
insert_ord_by_key(&mut self, item: A, f: FnMut(&A) -> B) absent present provided (01 "imbl additions kept") added (imbl API) tests/compat_vector.rs::insert_ord_by_key

Ends

item im 15.1 imbl 7 perennial status test
push_front(&mut self, v: A) O(1)* as im as im same tests/compat_vector.rs::push_front
push_back(&mut self, v: A) O(1)* as im as im same tests/compat_vector.rs::push_back
pop_front(&mut self) -> Option<A> None when empty as im as im same tests/compat_vector.rs::pop_front
pop_back(&mut self) -> Option<A> None when empty as im as im same tests/compat_vector.rs::pop_back

Whole-vector operations

item im 15.1 imbl 7 perennial status test
append(&mut self, other: Self) concatenate, O(log n) as im as im same tests/compat_vector.rs::append
split_at(self, i: usize) -> (Self, Self) i > len panics assertion failed: index <= self.len() as im as im same tests/compat_vector.rs::split_at
split_off(&mut self, i: usize) -> Self same panic; split_off(len) → empty as im as im same tests/compat_vector.rs::split_off
skip(&self, n: usize) -> Self n > len panics assertion failed: index <= self.len() n > len → empty as imbl: empty, no panic differs: no panic past the end (01:skip-truncate-split) tests/compat_vector.rs::skip
take(&self, n: usize) -> Self n > len panics assertion failed: index <= self.len() as im (panics) as im same tests/compat_vector.rs::take
truncate(&mut self, len: usize) len > current panics assertion failed: index <= self.len() no-op (≥ 2.0.3) as imbl: no-op differs: no panic past the end (01:skip-truncate-split) tests/compat_vector.rs::truncate
slice(&mut self, r: impl RangeBounds<usize>) -> Self removes and returns the range; inverted → empty, self unchanged; start ≥ len → empty; end > len panics assertion failed: index <= self.len() as im as im same tests/compat_vector.rs::slice
retain(&mut self, f: FnMut(&A) -> bool) keeps order, O(n) as im as im same tests/compat_vector.rs::retain
sort(&mut self) (A: Ord) unstable; Miri flags it at 140 elements as im stable; Miri-clean; a panicking Clone while sorting a shared vector leaves that handle empty differs: stable sort (01:sort); panicking Clone empties the handle (01:sort-clone-panic) tests/compat_vector.rs::sort
sort_by(&mut self, cmp: Fn(&A, &A) -> Ordering) unstable; note Fn, not FnMut as im stable; same Fn bound; panicking Clone as sort differs: stable sort (01:sort); panicking Clone empties the handle (01:sort-clone-panic) tests/compat_vector.rs::sort_by

Views and iteration entry points

item im 15.1 imbl 7 perennial status test
iter(&self) -> Iter<'_, A> O(1) to create as im as im same tests/compat_vector.rs::iter
iter_mut(&mut self) -> IterMut<'_, A> copy-on-write as visited as im as im same tests/compat_vector.rs::iter_mut
leaves(&self) -> Chunks<'_, A> contiguous slices in order covering the vector; slice lengths implementation-defined as im order and coverage as im; slice lengths are perennial's own same tests/compat_vector.rs::leaves
leaves_mut(&mut self) -> ChunksMut<'_, A> as leaves, mutable as im as leaves same tests/compat_vector.rs::leaves_mut
focus(&self) -> Focus<'_, A> read cursor (Focus section below) as im as im same tests/compat_vector.rs::focus
focus_mut(&mut self) -> FocusMut<'_, A> write cursor as im as im same tests/compat_vector.rs::focus_mut

Debug-feature methods

item im 15.1 imbl 7 perennial status test
assert_invariants(&self) (feature debug) panics on an inconsistent tree as im perennial's own consistency check under this name (spec permits) same tests/compat_vector.rs::assert_invariants
dot(&self, w: impl Write) -> Result<()> (feature debug) absent graphviz dump; format not contractual not provided not provided: imbl-only, not in im's API; not in 0.1 (01:imbl-only) —

Focus (read cursor; im: enum with hidden variants; imbl adds P)

item im 15.1 imbl 7 perennial status test
Focus<'a, A> (type) opaque cursor over a vector or sub-range Focus<'a, A, P> opaque cursor; generic over P behind the alias (01:generic) same tests/compat_vector.rs::focus_type
Focus::new(v: &'a Vector<A>) -> Self same as v.focus() as im as im same tests/compat_vector.rs::focus_new
Focus::len(&self) -> usize length of the viewed range as im as im same tests/compat_vector.rs::focus_len
Focus::is_empty(&self) -> bool as im as im same tests/compat_vector.rs::focus_is_empty
Focus::get(&mut self, i: usize) -> Option<&A> index relative to the view as im as im same tests/compat_vector.rs::focus_get
Focus::index(&mut self, i: usize) -> &A out of range panics index out of bounds as im as im same tests/compat_vector.rs::focus_index
Focus::chunk_at(&mut self, i: usize) -> (Range<usize>, &[A]) slice holding i and its view-relative range; out of range panics vector::Focus::chunk_at: index out of bounds as im as im; chunk boundaries are perennial's own (observed 64-wide chunks are not contractual) same tests/compat_vector.rs::focus_chunk_at
Focus::narrow(self, r: impl RangeBounds<usize>) -> Self outside the view panics range end index 9 out of range for slice of length 3 (slice-style text) panics vector::Focus::narrow: range out of bounds im's text (01:panic-text); an empty range inside or at the end of the view is accepted and gives an empty focus, as slices and imbl do differs: empty ranges accepted (01:narrow-empty) tests/compat_vector.rs::focus_narrow
Focus::split_at(self, i: usize) -> (Self, Self) i >= len panics vector::Focus::split_at: index out of bounds (even i == len) i == len → (all, empty); panics only for i > len, same text as imbl differs: split_at(len) allowed (01:skip-truncate-split) tests/compat_vector.rs::focus_split_at
impl Clone for Focus yes yes yes same tests/compat_vector.rs::focus_impl_clone
impl From<FocusMut<'a, A>> for Focus<'a, A> yes yes yes same tests/compat_vector.rs::focus_impl_from_focus_mut
impl IntoIterator for Focus (Item &'a A) iterates the view as im as im same tests/compat_vector.rs::focus_impl_into_iterator

FocusMut (write cursor; holds &mut Vector, splittable)

item im 15.1 imbl 7 perennial status test
FocusMut<'a, A> (type) opaque adds P opaque; generic over P (01:generic) same tests/compat_vector.rs::focus_mut_type
FocusMut::new(v: &'a mut Vector<A>) -> Self as im as im same tests/compat_vector.rs::focus_mut_new
FocusMut::len(&self) -> usize as im as im same tests/compat_vector.rs::focus_mut_len
FocusMut::is_empty(&self) -> bool as im as im same tests/compat_vector.rs::focus_mut_is_empty
FocusMut::get(&mut self, i: usize) -> Option<&A> as im as im same tests/compat_vector.rs::focus_mut_get
FocusMut::get_mut(&mut self, i: usize) -> Option<&mut A> as im as im same tests/compat_vector.rs::focus_mut_get_mut
FocusMut::index(&mut self, i: usize) -> &A panics index out of bounds as im as im same tests/compat_vector.rs::focus_mut_index
FocusMut::index_mut(&mut self, i: usize) -> &mut A panics index out of bounds as im as im same tests/compat_vector.rs::focus_mut_index_mut
FocusMut::set(&mut self, i: usize, v: A) -> Option<A> old value; out of range → None, nothing changes as im as im same tests/compat_vector.rs::focus_mut_set
FocusMut::swap(&mut self, a: usize, b: usize) equal → no-op; out of range panics index out of bounds text index out of bounds or overlapping im's text (01:panic-text) same tests/compat_vector.rs::focus_mut_swap
FocusMut::pair(&mut self, a, b, f: FnMut(&mut A, &mut A) -> B) -> B equal panics vector::FocusMut::pair: indices cannot be equal!; out of range index out of bounds out of range index out of bounds or overlapping im's texts (01:panic-text) same tests/compat_vector.rs::focus_mut_pair
FocusMut::triplet(&mut self, a, b, c, f: FnMut(&mut A, &mut A, &mut A) -> B) -> B two equal panic vector::FocusMut::triplet: indices cannot be equal! as im as im same tests/compat_vector.rs::focus_mut_triplet
FocusMut::chunk_at(&mut self, i: usize) -> (Range<usize>, &mut [A]) as im as im; chunk boundaries perennial's own same tests/compat_vector.rs::focus_mut_chunk_at
FocusMut::narrow(self, r: impl RangeBounds<usize>) -> Self panics as Focus::narrow imbl text im's text (01:panic-text); empty ranges accepted as Focus::narrow differs: empty ranges accepted (01:narrow-empty) tests/compat_vector.rs::focus_mut_narrow
FocusMut::split_at(self, i: usize) -> (Self, Self) as Focus::split_at (panics at len) as Focus::split_at (accepts len) as imbl differs: split_at(len) allowed (01:skip-truncate-split) tests/compat_vector.rs::focus_mut_split_at
FocusMut::unmut(self) -> Focus<'a, A> as im as im same tests/compat_vector.rs::focus_mut_unmut
impl IntoIterator for FocusMut (Item &'a mut A) as im as im same tests/compat_vector.rs::focus_mut_impl_into_iterator

Iterator types

item im 15.1 imbl 7 perennial status test
vector::Iter<'a, A> (Item &'a A) Iterator, DoubleEnded, ExactSize, Fused; no Clone, no Debug adds Clone as im plus Clone (next row) same tests/compat_vector.rs::iter_type
impl Clone for vector::Iter absent present provided (01 "imbl additions kept") added (imbl API) tests/compat_vector.rs::iter_impl_clone
vector::IterMut<'a, A> (Item &'a mut A) Iterator, DoubleEnded, ExactSize, Fused as im as im same tests/compat_vector.rs::iter_mut_type
vector::ConsumingIter<A> (Item A) Iterator, DoubleEnded, ExactSize, Fused adds Clone (7.0.2) as im plus Clone same tests/compat_vector.rs::consuming_iter_type
impl Clone for vector::ConsumingIter absent present provided (01 "imbl additions kept") added (imbl API) tests/compat_vector.rs::consuming_iter_impl_clone
vector::Chunks<'a, A> (Item &'a [A]) Iterator, DoubleEnded, Fused as im as im same tests/compat_vector.rs::chunks_type
vector::ChunksMut<'a, A> (Item &'a mut [A]) Iterator, DoubleEnded, Fused as im as im same tests/compat_vector.rs::chunks_mut_type
vector::rayon::ParIter<'a, A> (feature rayon) im only (not im-rc) present perennial only; Rc is not Send (01:features) same tests/compat_vector_features.rs::par_iter_type
vector::rayon::ParIterMut<'a, A> (feature rayon) im only present perennial only (01:features) same tests/compat_vector_features.rs::par_iter_mut_type
impl IntoParallelRefIterator for Vector (par_iter) indexed, order-preserving as im as im same tests/compat_vector.rs::impl_into_parallel_ref_iterator
impl IntoParallelRefMutIterator for Vector (par_iter_mut) indexed, order-preserving as im as im same tests/compat_vector.rs::impl_into_parallel_ref_mut_iterator

Trait implementations

item im 15.1 imbl 7 perennial status test
impl Clone O(1), bounded O(n) when inline as im as im same tests/compat_vector.rs::impl_clone
impl Default empty as im as im same tests/compat_vector.rs::impl_default
impl Debug [10, 20, 30], pretty like Vec; bound A: Clone + Debug bound A: Debug format as im; bound loosened to imbl's A: Debug (01:loose-bounds) same tests/differential/vector.rs
impl PartialEq length + element-wise ==; no identity short-cut (NaN vector != its clone) as im as im same tests/differential/vector.rs
impl Eq as im as im same tests/compat_vector.rs::impl_eq
impl PartialOrd lexicographic; NaN → None as im as im same tests/differential/vector.rs
impl Ord lexicographic as im as im same tests/differential/vector.rs
impl Hash elements in order, no length prefix (differs from Vec) as im as im same tests/compat_vector.rs::impl_hash
impl Index<usize> panics Vector::index: index out of bounds: {i} < {len} as im as im same tests/compat_vector.rs::impl_index
impl IndexMut<usize> panics Vector::index_mut: index out of bounds as im as im same tests/compat_vector.rs::impl_index_mut
impl Add for Vector<A> concatenation as im as im same tests/compat_vector.rs::impl_add
impl Add for &Vector<A> concatenation as im as im same tests/compat_vector.rs::impl_add_ref
impl Sum concatenation in order as im as im same tests/compat_vector.rs::impl_sum
impl Extend<A> push_back each as im as im same tests/compat_vector.rs::impl_extend
impl FromIterator<A> O(n) as im as im same tests/compat_vector.rs::impl_from_iterator
impl IntoIterator for Vector<A> ConsumingIter as im as im same tests/compat_vector.rs::impl_into_iterator
impl IntoIterator for &Vector<A> Iter as im as im same tests/compat_vector.rs::impl_into_iterator_ref
impl IntoIterator for &mut Vector<A> absent IterMut (≥ 4.0) provided (01 "imbl additions kept") added (imbl API) tests/compat_vector.rs::impl_into_iterator_mut
impl From<Vec<A>> as im as im same tests/compat_vector.rs::impl_from_vec
impl From<&Vec<A>> as im as im same tests/compat_vector.rs::impl_from_vec_ref
impl From<&[A]> as im as im same tests/compat_vector.rs::impl_from_slice
impl From<&Vector<&A>> for Vector<OA> (via ToOwned) clones out of a vector of references as im as im same tests/compat_vector.rs::impl_from_vector_of_refs
impl From<[A; N]> absent present provided (01 "imbl additions kept") added (imbl API) tests/compat_vector.rs::impl_from_array
impl Serialize (feature serde) as a sequence as im as im same tests/compat_vector_features.rs::impl_serialize
impl Deserialize (feature serde) from a sequence; object input → invalid type: map, expected a sequence as im as im same tests/compat_vector_features.rs::impl_deserialize
impl arbitrary::Arbitrary<'a> (feature arbitrary) yes yes yes same tests/compat_vector_features.rs::impl_arbitrary
impl quickcheck::Arbitrary (feature quickcheck) im only (not im-rc) yes both crates (01:features) same tests/compat_vector_features.rs::impl_quickcheck_arbitrary
impl bincode::Encode / Decode (feature bincode) absent yes not provided not provided: imbl-only, not in im's API; not in 0.1 (01:imbl-only) —
auto traits Send / Sync im-rc neither; im when A: Send + Sync as im perennial-rc neither; perennial when A: Send + Sync same tests/compat_vector.rs::auto_traits