Skip to content

Commit

Permalink
rename(collections/blazemap): map
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsonin committed May 22, 2024
1 parent 0c87ed8 commit 1984865
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/collections.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/// Defines [`BlazeMap`](crate::prelude::BlazeMap).
pub mod blazemap;
pub mod map;
8 changes: 4 additions & 4 deletions src/collections/blazemap.rs → src/collections/map.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub use crate::collections::blazemap::{
pub use crate::collections::map::{
entries::{Entry, OccupiedEntry, VacantEntry},
iters::{Drain, IntoIter, IntoKeys, IntoValues, Iter, IterMut, Keys, Values, ValuesMut},
};
use crate::{
collections::blazemap::entries::VacantEntryInner,
collections::map::entries::VacantEntryInner,
traits::{
BlazeMapId, BlazeMapIdStatic, CapacityInfoProvider, KeyByOffsetProvider, TypeInfoContainer,
},
Expand All @@ -29,8 +29,8 @@ mod iters;
/// A [`Vec`]-based analogue of a [`HashMap`](std::collections::HashMap).
#[derive(Clone, PartialEq, Eq)]
pub struct BlazeMap<K, V> {
pub(in crate::collections::blazemap) inner: Vec<Option<V>>,
pub(in crate::collections::blazemap) len: usize,
pub(in crate::collections::map) inner: Vec<Option<V>>,
pub(in crate::collections::map) len: usize,
phantom: PhantomData<K>,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use crate::prelude::BlazeMapId;
///
/// This enum is constructed
/// from the [`entry`] method on
/// [`BlazeMap`](crate::collections::blazemap::BlazeMap).
/// [`BlazeMap`](crate::collections::map::BlazeMap).
///
/// [`entry`]: crate::collections::blazemap::BlazeMap::entry
/// [`entry`]: crate::collections::map::BlazeMap::entry
pub enum Entry<'a, K, V>
where
K: BlazeMapId,
Expand All @@ -20,36 +20,36 @@ where

#[derive(Debug)]
/// A view into an occupied entry in a
/// [`BlazeMap`](crate::collections::blazemap::BlazeMap). It is part of the
/// [`BlazeMap`](crate::collections::map::BlazeMap). It is part of the
/// [`Entry`] enum.
pub struct OccupiedEntry<'a, K, V>
where
K: BlazeMapId,
{
pub(in crate::collections::blazemap) key: K,
pub(in crate::collections::map) key: K,

pub(in crate::collections::blazemap) len: &'a mut usize,
pub(in crate::collections::map) len: &'a mut usize,

pub(in crate::collections::blazemap) value: &'a mut Option<V>,
pub(in crate::collections::map) value: &'a mut Option<V>,
}

#[derive(Debug)]
/// A view into a vacant entry in a
/// [`BlazeMap`](crate::collections::blazemap::BlazeMap). It is part of the
/// [`BlazeMap`](crate::collections::map::BlazeMap). It is part of the
/// [`Entry`] enum.
pub struct VacantEntry<'a, K, V>
where
K: BlazeMapId,
{
pub(in crate::collections::blazemap) key: K,
pub(in crate::collections::map) key: K,

pub(in crate::collections::blazemap) len: &'a mut usize,
pub(in crate::collections::map) len: &'a mut usize,

pub(in crate::collections::blazemap) inner: VacantEntryInner<'a, V>,
pub(in crate::collections::map) inner: VacantEntryInner<'a, V>,
}

#[derive(Debug)]
pub(in crate::collections::blazemap) enum VacantEntryInner<'a, V> {
pub(in crate::collections::map) enum VacantEntryInner<'a, V> {
ShouldBeInserted(&'a mut Option<V>),
ShouldBeEnlarged(&'a mut Vec<Option<V>>),
}
Expand Down
34 changes: 17 additions & 17 deletions src/collections/blazemap/iters.rs → src/collections/map/iters.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
collections::blazemap::BlazeMap,
collections::map::BlazeMap,
prelude::{BlazeMapId, BlazeMapIdStatic},
traits::{KeyByOffsetProvider, TypeInfoContainer},
};
Expand All @@ -17,13 +17,13 @@ use std::{
///
/// [`iter`]: BlazeMap::iter
pub struct Iter<'a, K, V> {
pub(in crate::collections::blazemap) inner: *const Option<V>,
pub(in crate::collections::map) inner: *const Option<V>,

pub(in crate::collections::blazemap) current_position: usize,
pub(in crate::collections::map) current_position: usize,

pub(in crate::collections::blazemap) len: usize,
pub(in crate::collections::map) len: usize,

pub(in crate::collections::blazemap) phantom: PhantomData<(K, &'a V)>,
pub(in crate::collections::map) phantom: PhantomData<(K, &'a V)>,
}

/// A mutable iterator over the entries of a [`BlazeMap`].
Expand All @@ -33,13 +33,13 @@ pub struct Iter<'a, K, V> {
///
/// [`iter_mut`]: BlazeMap::iter_mut
pub struct IterMut<'a, K, V> {
pub(in crate::collections::blazemap) inner: *mut Option<V>,
pub(in crate::collections::map) inner: *mut Option<V>,

pub(in crate::collections::blazemap) current_position: usize,
pub(in crate::collections::map) current_position: usize,

pub(in crate::collections::blazemap) len: usize,
pub(in crate::collections::map) len: usize,

pub(in crate::collections::blazemap) phantom: PhantomData<(K, &'a mut V)>,
pub(in crate::collections::map) phantom: PhantomData<(K, &'a mut V)>,
}

/// An iterator over the keys of a [`BlazeMap`].
Expand All @@ -49,7 +49,7 @@ pub struct IterMut<'a, K, V> {
///
/// [`keys`]: BlazeMap::keys
pub struct Keys<'a, K, V> {
pub(in crate::collections::blazemap) inner: Iter<'a, K, V>,
pub(in crate::collections::map) inner: Iter<'a, K, V>,
}

/// An iterator over the values of a [`BlazeMap`].
Expand All @@ -59,7 +59,7 @@ pub struct Keys<'a, K, V> {
///
/// [`values`]: BlazeMap::values
pub struct Values<'a, K, V> {
pub(in crate::collections::blazemap) inner: Iter<'a, K, V>,
pub(in crate::collections::map) inner: Iter<'a, K, V>,
}

/// A mutable iterator over the values of a [`BlazeMap`].
Expand All @@ -69,7 +69,7 @@ pub struct Values<'a, K, V> {
///
/// [`values_mut`]: BlazeMap::values_mut
pub struct ValuesMut<'a, K, V> {
pub(in crate::collections::blazemap) inner: IterMut<'a, K, V>,
pub(in crate::collections::map) inner: IterMut<'a, K, V>,
}

/// An owning iterator over the entries of a [`BlazeMap`].
Expand All @@ -79,7 +79,7 @@ pub struct ValuesMut<'a, K, V> {
///
/// [`into_iter`]: IntoIterator::into_iter
pub struct IntoIter<K, V> {
pub(in crate::collections::blazemap) inner: BlazeMap<K, V>,
pub(in crate::collections::map) inner: BlazeMap<K, V>,
}

/// An owning iterator over the keys of a [`BlazeMap`].
Expand All @@ -89,7 +89,7 @@ pub struct IntoIter<K, V> {
///
/// [`into_keys`]: BlazeMap::into_keys
pub struct IntoKeys<K, V> {
pub(in crate::collections::blazemap) inner: IntoIter<K, V>,
pub(in crate::collections::map) inner: IntoIter<K, V>,
}

/// An owning iterator over the values of a [`BlazeMap`].
Expand All @@ -99,7 +99,7 @@ pub struct IntoKeys<K, V> {
///
/// [`into_values`]: BlazeMap::into_values
pub struct IntoValues<K, V> {
pub(in crate::collections::blazemap) inner: IntoIter<K, V>,
pub(in crate::collections::map) inner: IntoIter<K, V>,
}

/// A draining iterator over the entries of a [`BlazeMap`].
Expand All @@ -109,9 +109,9 @@ pub struct IntoValues<K, V> {
///
/// [`drain`]: BlazeMap::drain
pub struct Drain<'a, K, V> {
pub(in crate::collections::blazemap) map: &'a mut BlazeMap<K, V>,
pub(in crate::collections::map) map: &'a mut BlazeMap<K, V>,

pub(in crate::collections::blazemap) current_position: usize,
pub(in crate::collections::map) current_position: usize,
}

impl<'a, K, V> Iterator for Iter<'a, K, V>
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod utils;
/// Crate prelude.
pub mod prelude {
pub use crate::{
collections::blazemap::BlazeMap,
collections::map::BlazeMap,
traits::{AllInstancesIter, BlazeMapId, BlazeMapIdStatic, BlazeMapIdWrapper},
};
}
Expand Down
16 changes: 7 additions & 9 deletions tests/random_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl Action<String, String> {
write!(io, "{}", entry.or_default()).unwrap();
}
Entry::EntryMatch(event) => match entry {
blazemap::collections::blazemap::Entry::Occupied(mut entry) => {
blazemap::collections::map::Entry::Occupied(mut entry) => {
match event.on_occupied {
OccupiedEntry::Key => write!(io, "{:?}", entry.key()).unwrap(),
OccupiedEntry::RemoveEntry => {
Expand All @@ -252,15 +252,13 @@ impl Action<String, String> {
OccupiedEntry::Drop => drop(entry),
}
}
blazemap::collections::blazemap::Entry::Vacant(entry) => {
match event.on_vacant {
VacantEntry::Key => write!(io, "{:?}", entry.key()).unwrap(),
VacantEntry::Insert { value } => {
write!(io, "{:?}", entry.insert(value)).unwrap();
}
VacantEntry::Drop => drop(entry),
blazemap::collections::map::Entry::Vacant(entry) => match event.on_vacant {
VacantEntry::Key => write!(io, "{:?}", entry.key()).unwrap(),
VacantEntry::Insert { value } => {
write!(io, "{:?}", entry.insert(value)).unwrap();
}
}
VacantEntry::Drop => drop(entry),
},
},
Entry::Drop => drop(entry),
}
Expand Down

0 comments on commit 1984865

Please sign in to comment.