Skip to content

Commit

Permalink
initial updates for owned storage, reallocating vec
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Whitehead <[email protected]>
  • Loading branch information
andrewwhitehead committed Mar 8, 2022
1 parent 3611696 commit 562f4d9
Show file tree
Hide file tree
Showing 7 changed files with 359 additions and 153 deletions.
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
2 changes: 2 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
5 changes: 5 additions & 0 deletions src/collections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,11 @@ 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.
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
2 changes: 2 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
2 changes: 2 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
Loading

0 comments on commit 562f4d9

Please sign in to comment.