Skip to content
Draft
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
6 changes: 3 additions & 3 deletions benches/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ macro_rules! removals {
#[bench]
fn $fnn(b: &mut Bencher) {
let mut rng = SmallRng::seed_from_u64(0x5432_1012_3454_3210);
let mut pairs = coca::AllocVec::<(u32, u32), usize>::with_capacity($n);
let mut pairs = coca::collections::AllocVec::<(u32, u32), usize>::with_capacity($n);
for _ in 0..$n {
pairs.push((rng.next_u32(), rng.next_u32()));
}
Expand All @@ -77,7 +77,7 @@ macro_rules! removals {

mod unordered {
use super::*;
use coca::AllocVec;
use coca::collections::AllocVec;
use std::collections::HashMap as StdHashMap;

#[allow(unconditional_recursion)] // false positive!
Expand Down Expand Up @@ -167,7 +167,7 @@ mod unordered {

mod ordered {
use super::*;
use coca::AllocVec;
use coca::collections::AllocVec;
use std::collections::BTreeMap;

impl<K, V> Map<K, V> for BTreeMap<K, V>
Expand Down
4 changes: 4 additions & 0 deletions src/collections/list_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use self::Entry::{Occupied, Vacant};
/// The [`LayoutSpec`] for a [`ListMap`].
pub struct ListMapLayout<K, V>(PhantomData<(K, V)>);
impl<K, V> LayoutSpec for ListMapLayout<K, V> {
type Item = (K, V);

fn layout_with_capacity(items: usize) -> Result<Layout, LayoutError> {
let keys_array = Layout::array::<K>(items)?;
let values_array = Layout::array::<V>(items)?;
Expand Down Expand Up @@ -847,6 +849,8 @@ pub struct InlineStorage<K, V, const N: usize> {
}

unsafe impl<K, V, const N: usize> Storage<ListMapLayout<K, V>> for InlineStorage<K, V, N> {
const MIN_REPRESENTABLE: usize = N;

fn get_ptr(&self) -> *const u8 {
(self as *const Self).cast()
}
Expand Down
15 changes: 15 additions & 0 deletions src/collections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,21 @@ pub type ArenaVec<'a, T, I = usize> = Vec<T, ArenaStorage<'a, ArrayLayout<T>>, I
/// ```
pub type AllocVec<T, I = usize> = Vec<T, crate::storage::AllocStorage<ArrayLayout<T>>, I>;

#[cfg(feature = "alloc")]
#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))]
/// A heap-allocated vector which automatically reallocates.
///
/// # Examples
/// ```
/// let mut vec = coca::collections::ReallocVec::<char>::new();
/// vec.push('a');
/// vec.push('b');
/// vec.push('c');
/// assert_eq!(vec.len(), 3);
/// assert_eq!(vec.capacity(), 4);
/// ```
pub type ReallocVec<T, I = usize> = Vec<T, crate::storage::ReallocStorage<ArrayLayout<T>>, I>;

/// A vector using an inline array for storage.
///
/// # Examples
Expand Down
4 changes: 4 additions & 0 deletions src/collections/pool/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ union Slot<T, I: Capacity> {
/// The [`LayoutSpec`] for a [`DirectPool`].
pub struct DirectPoolLayout<T, H>(PhantomData<(T, H)>);
impl<T, H: Handle> LayoutSpec for DirectPoolLayout<T, H> {
type Item = (T, H::Index, u32);

fn layout_with_capacity(items: usize) -> Result<Layout, LayoutError> {
let item_array = Layout::array::<Slot<T, H::Index>>(items)?;
let gen_count_array = Layout::array::<u32>(items)?;
Expand Down Expand Up @@ -1133,6 +1135,8 @@ pub struct InlineStorage<T, H: Handle, const N: usize> {
unsafe impl<T, H: Handle, const N: usize> Storage<DirectPoolLayout<T, H>>
for InlineStorage<T, H, N>
{
const MIN_REPRESENTABLE: usize = N;

#[inline]
fn get_ptr(&self) -> *const u8 {
(self as *const Self).cast()
Expand Down
3 changes: 3 additions & 0 deletions src/collections/pool/packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use crate::storage::{Capacity, LayoutSpec, Storage};
/// The [`LayoutSpec`] for a [`PackedPool`].
pub struct PackedPoolLayout<T, H>(PhantomData<(T, H)>);
impl<T, H: Handle> LayoutSpec for PackedPoolLayout<T, H> {
type Item = (T, H, u32, H::Index);

fn layout_with_capacity(items: usize) -> Result<Layout, LayoutError> {
let values_array = Layout::array::<T>(items)?;
let handles_array = Layout::array::<H>(items)?;
Expand Down Expand Up @@ -1153,6 +1155,7 @@ pub struct InlineStorage<T, H: Handle, const N: usize> {
unsafe impl<T, H: Handle, const N: usize> Storage<PackedPoolLayout<T, H>>
for InlineStorage<T, H, N>
{
const MIN_REPRESENTABLE: usize = N;
fn get_ptr(&self) -> *const u8 {
(self as *const Self).cast()
}
Expand Down
Loading