Skip to main content

HashCell

Struct HashCell 

Source
pub struct HashCell<K, const D: usize>
where K: Eq + Hash,
{ /* private fields */ }
Expand description

Bucket sort points into cubes with HashMap-backed storage

See VecCell for a complete description of the algorithm. Use VecCell for dense, bounded collections of points. Use HashMap for sparse and/or unbounded collections of points.

§Examples

The default HashCell set both the nominal and maximum search radii to 1.0.

use hoomd_spatial::HashCell;

let hash_cell = HashCell::<usize, 3>::default();

Use the builder API to set any or all parameters:

use hoomd_spatial::HashCell;

let hash_cell = HashCell::<usize, 3>::builder()
    .nominal_search_radius(2.5.try_into()?)
    .maximum_search_radius(7.5)
    .build();

Implementations§

Source§

impl<K, const D: usize> HashCell<K, D>
where K: Copy + Eq + Hash,

Source

pub fn shrink_to_fit(&mut self)

Remove excess capacity from dynamically allocated arrays.

Source

pub fn builder() -> HashCellBuilder<K, D>

Construct a HashCell builder.

Use the builder to set any or all parameters and construct a HashCell.

§Example
use hoomd_spatial::HashCell;

let hash_cell = HashCell::<usize, 3>::builder()
    .nominal_search_radius(2.5.try_into()?)
    .maximum_search_radius(7.5)
    .build();

Trait Implementations§

Source§

impl<K, const D: usize> Clone for HashCell<K, D>
where K: Eq + Hash + Clone,

Source§

fn clone(&self) -> HashCell<K, D>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, const D: usize> Debug for HashCell<K, D>
where K: Eq + Hash + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, const D: usize> Default for HashCell<K, D>
where K: Copy + Eq + Hash,

Source§

fn default() -> Self

Construct a default HashCell.

The default sets both the nominal and maximum search radii to 1.0.

§Example
use hoomd_spatial::HashCell;

let hash_cell = HashCell::<usize, 3>::default();
Source§

impl<'de, K, const D: usize> Deserialize<'de> for HashCell<K, D>
where K: Eq + Hash + Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<K, const D: usize> Display for HashCell<K, D>
where K: Eq + Hash,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Summarize the contents of the cell list.

This is a slow operation. It is meant to be printed to logs only occasionally, such as at the end of a benchmark or simulation.

§Example
use hoomd_spatial::HashCell;
use log::info;

let vec_cell = HashCell::<usize, 3>::default();

info!("{vec_cell}");
Source§

impl<K, const D: usize> PointUpdate<Cartesian<D>, K> for HashCell<K, D>
where K: Copy + Eq + Hash,

Source§

fn insert(&mut self, key: K, position: Cartesian<D>)

Insert or update a point identified by a key.

§Example
use hoomd_spatial::{HashCell, PointUpdate};

let mut hash_cell = HashCell::default();

hash_cell.insert(0, [1.25, 2.5].into());
Source§

fn remove(&mut self, key: &K)

Remove the point with the given key.

§Example
use hoomd_spatial::{HashCell, PointUpdate};

let mut hash_cell = HashCell::default();
hash_cell.insert(0, [1.25, 2.5].into());

hash_cell.remove(&0)
Source§

fn len(&self) -> usize

Get the number of points in the spatial data structure.

§Example
use hoomd_spatial::{HashCell, PointUpdate};

let mut hash_cell = HashCell::default();
hash_cell.insert(0, [1.25, 2.5].into());

assert_eq!(hash_cell.len(), 1)
Source§

fn is_empty(&self) -> bool

Test if the spatial data structure is empty.

§Example
use hoomd_spatial::{HashCell, PointUpdate};

let mut hash_cell = HashCell::default();

assert!(hash_cell.is_empty());
Source§

fn contains_key(&self, key: &K) -> bool

Test if the spatial data structure contains a key.

use hoomd_spatial::{HashCell, PointUpdate};

let mut hash_cell = HashCell::default();
hash_cell.insert(0, [1.25, 2.5].into());

assert!(hash_cell.contains_key(&0));
Source§

fn clear(&mut self)

Remove all points.

§Example
use hoomd_spatial::{HashCell, PointUpdate};

let mut hash_cell = HashCell::default();
hash_cell.insert(0, [1.25, 2.5].into());

hash_cell.clear();
Source§

impl<const D: usize, K> PointsNearBall<Cartesian<D>, K> for HashCell<K, D>
where K: Copy + Eq + Hash,

Source§

fn points_near_ball( &self, position: &Cartesian<D>, radius: f64, ) -> impl Iterator<Item = K>

Find all the points that might be in the given ball.

points_near_ball will iterate over all points in the given ball and possibly others as well. HashCell may iterate over the points in any order.

§Example
use hoomd_spatial::{HashCell, PointUpdate, PointsNearBall};

let mut hash_cell = HashCell::default();
hash_cell.insert(0, [1.25, 0.0].into());
hash_cell.insert(1, [3.25, 0.75].into());
hash_cell.insert(2, [-10.0, 12.0].into());

for key in hash_cell.points_near_ball(&[2.0, 0.0].into(), 1.0) {
    println!("{key}");
}

Prints (in any order):

0
1
§Panics

Panics when radius is larger than the maximum search radius provided at construction, rounded up to the nearest integer multiple of the nominal search radius.

Source§

fn is_all_pairs() -> bool

Is this spatial data structures AllPairs?
Source§

impl<K, const D: usize> Serialize for HashCell<K, D>
where K: Eq + Hash + Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<K, const D: usize> WithSearchRadius for HashCell<K, D>
where K: Copy + Eq + Hash,

Source§

fn with_search_radius(radius: PositiveReal) -> Self

Construct a HashCell with the given search radius.

Set both the nominal and maximum search radii to radius.

§Example
use hoomd_spatial::{HashCell, WithSearchRadius};

let hash_cell = HashCell::<usize, 3>::with_search_radius(2.5.try_into()?);

Auto Trait Implementations§

§

impl<K, const D: usize> Freeze for HashCell<K, D>

§

impl<K, const D: usize> RefUnwindSafe for HashCell<K, D>
where K: RefUnwindSafe,

§

impl<K, const D: usize> Send for HashCell<K, D>
where K: Send,

§

impl<K, const D: usize> Sync for HashCell<K, D>
where K: Sync,

§

impl<K, const D: usize> Unpin for HashCell<K, D>
where K: Unpin,

§

impl<K, const D: usize> UnsafeUnpin for HashCell<K, D>

§

impl<K, const D: usize> UnwindSafe for HashCell<K, D>
where K: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,