Skip to main content

AtomSelection

Enum AtomSelection 

Source
pub enum AtomSelection {
    Empty,
    All(u32),
    Range(Range<u32>),
    Ranges(SmallVec<[Range<u32>; 4]>),
    Sparse(Vec<u32>),
    Dense(BitVec),
}
Expand description

A set of atoms, addressed by position in the structure’s flat atom order.

§Examples

use molframe_core::AtomSelection;

let chain = AtomSelection::range(0..100);
let metals = AtomSelection::from_sorted(vec![5, 50, 500]);
assert_eq!(chain.intersect(&metals).len(), 2);

Variants§

§

Empty

No atoms.

§

All(u32)

Every atom of a structure with this many.

§

Range(Range<u32>)

One contiguous run.

§

Ranges(SmallVec<[Range<u32>; 4]>)

Several contiguous runs, ascending and disjoint.

§

Sparse(Vec<u32>)

Scattered positions, ascending and unique.

§

Dense(BitVec)

A bit per position, for a set dense enough to make that cheaper.

Implementations§

Source§

impl AtomSelection

Source

pub fn intersect(&self, other: &Self) -> Self

The atoms in both selections.

Source

pub fn union(&self, other: &Self) -> Self

The atoms in either selection.

Source

pub fn difference(&self, other: &Self) -> Self

The atoms in this selection but not the other.

Source

pub fn complement(&self, count: u32) -> Self

Every atom of a structure of count atoms that this selection excludes.

Source

pub fn heap_bytes(&self) -> usize

The bytes this selection occupies beyond its own header.

Source§

impl AtomSelection

Source

pub fn range(atoms: Range<u32>) -> Self

A selection covering one contiguous run.

Source

pub fn from_sorted(positions: Vec<u32>) -> Self

Chooses the cheapest shape for ascending unique positions.

§Panics

Panics if positions is not ascending and unique, or if its storage exceeds the platform’s addressable range. Collect arbitrary positions into AtomSelection to sort and deduplicate them first.

Source

pub fn len(&self) -> u64

The number of atoms selected.

§Panics

Panics if manually constructed storage violates normalized u32 ranges.

Source

pub fn is_empty(&self) -> bool

Returns true when nothing is selected.

Source

pub fn contains(&self, atom: u32) -> bool

Returns true when atom is selected.

Source

pub fn position_bound(&self) -> u32

One past the largest position this selection could name.

Derived from the shape rather than the positions, so a whole-structure selection answers from its own count and a run from its end. A caller that has to prove every position is inside a structure compares this once instead of asking about each atom — which matters because the cheapest selections, All and Empty, are exactly the ones a per-atom walk would read as a full traversal of the structure.

The bound is exact: no position in the selection reaches it, and every shape reports the smallest bound that says so.

Source

pub fn iter(&self) -> SelectionIter<'_> ⓘ

The selected positions, ascending.

A concrete iterator rather than a boxed one: the boxed form cost a heap allocation per call and a virtual call per position, which prevented the consuming loop from inlining anything. Selection walks are the innermost loop of every spatial and analysis pass.

Trait Implementations§

Source§

impl Clone for AtomSelection

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for AtomSelection

Source§

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

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

impl Default for AtomSelection

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for AtomSelection

Source§

impl FromIterator<u32> for AtomSelection

Source§

fn from_iter<T: IntoIterator<Item = u32>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a> IntoIterator for &'a AtomSelection

Source§

type Item = u32

The type of the elements being iterated over.
Source§

type IntoIter = SelectionIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for AtomSelection

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for AtomSelection

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.