honeycomb_core::attributes

Struct AttrStorageManager

Source
pub struct AttrStorageManager { /* private fields */ }
Expand description

Main attribute storage structure.

This structure is used to store all generic attributes that the user may add to the combinatorial map he’s building.

§Implementation

The structure uses hashmaps in order to store each attribute’s dedicated storage. Which storage is used is determined by the associated type AttributeBind::StorageType.

The key type used by the map is each attribute’s TypeId. This implies that all attributes must have a different (unique) type. For example, two decimal-valued attribute will need to be wrapped in different dedicated structures.

Using the TypeId as the key value for collections yields a cleaner API, where the only argument passed to access methods is the ID of the cell of which they want the attribute. The actual attribute type is specified by passing a generic to the method. This bypasses any issues linked to literal-typed keys, such as typos, naming conventions, portability, etc.

Generics passed in access methods also have a secondary usage. To store heterogeneous collections, the internal hashmaps uses Box<dyn UnknownAttributeStorage> as their value type. Some operations require us to downcast the stored object (implementing UnknownAttributeStorage) to the correct collection type. This is achieved by using the downcast-rs crate and the associated storage type AttributeBind::StorageType. What follows is a simplified version of that code:

pub struct Manager {
    inner: HashMap<TypeId, Box<dyn UnknownAttributeStorage>>,
}

impl Manager {
    pub fn add_storage<A: AttributeBind + 'static>(
        &mut self,
        size: usize,
    ) {
        let typeid = TypeId::of::<A>();
        let new_storage = <A as AttributeBind>::StorageType::new(size);
        self.inner.insert(typeid, Box::new(new_storage));
    }

    pub fn get_storage<A: AttributeBind>(&self) -> &<A as AttributeBind>::StorageType {
        let probably_storage = &self.inner[&TypeId::of::<A>()];
        // downcast is possible because:
        // - StorageType: AttributeStorage<A>
        // - AttributeStorage<A>: UnknownAttributeStorage
        probably_storage
            .downcast_ref::<<A as AttributeBind>::StorageType>()
            .expect("E: could not downcast generic storage to specified attribute type")
    }
}

Implementations§

Source§

impl AttrStorageManager

Manager-wide methods

Source

pub fn extend_storages(&mut self, length: usize)

Extend the size of all storages in the manager.

§Arguments
  • length: usize – Length by which storages should be extended.
Source

pub fn merge_attributes( &self, orbit_policy: &OrbitPolicy, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, )

Execute a merging operation on all attributes associated with a given orbit for specified cells.

§Arguments
  • orbit_policy: OrbitPolicy – Orbit associated with affected attributes.
  • id_out: DartIdentifier – Identifier to write the result to.
  • id_in_lhs: DartIdentifier – Identifier of one attribute value to merge.
  • id_in_rhs: DartIdentifier – Identifier of the other attribute value to merge.
Source

pub fn merge_vertex_attributes( &self, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, )

Execute a merging operation on all attributes associated with vertices for specified cells.

§Arguments
  • id_out: DartIdentifier – Identifier to write the result to.
  • id_in_lhs: DartIdentifier – Identifier of one attribute value to merge.
  • id_in_rhs: DartIdentifier – Identifier of the other attribute value to merge.
Source

pub fn merge_edge_attributes( &self, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, )

Execute a merging operation on all attributes associated with edges for specified cells.

§Arguments
  • id_out: DartIdentifier – Identifier to write the result to.
  • id_in_lhs: DartIdentifier – Identifier of one attribute value to merge.
  • id_in_rhs: DartIdentifier – Identifier of the other attribute value to merge.
Source

pub fn merge_face_attributes( &self, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, )

Execute a merging operation on all attributes associated with faces for specified cells.

§Arguments
  • id_out: DartIdentifier – Identifier to write the result to.
  • id_in_lhs: DartIdentifier – Identifier of one attribute value to merge.
  • id_in_rhs: DartIdentifier – Identifier of the other attribute value to merge.
Source

pub fn merge_other_attributes( &self, _orbit_policy: &OrbitPolicy, _id_out: DartIdType, _id_in_lhs: DartIdType, _id_in_rhs: DartIdType, )

Execute a merging operation on all attributes associated with a given orbit for specified cells.

§Arguments
  • orbit_policy: OrbitPolicy – Orbit associated with affected attributes.
  • id_out: DartIdentifier – Identifier to write the result to.
  • id_in_lhs: DartIdentifier – Identifier of one attribute value to merge.
  • id_in_rhs: DartIdentifier – Identifier of the other attribute value to merge.
Source

pub fn split_attributes( &self, orbit_policy: &OrbitPolicy, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, )

Execute a splitting operation on all attributes associated with a given orbit for specified cells.

§Arguments
  • orbit_policy: OrbitPolicy – Orbit associated with affected attributes.
  • id_out_lhs: DartIdentifier – Identifier to write the result to.
  • id_out_rhs: DartIdentifier – Identifier to write the result to.
  • id_in: DartIdentifier – Identifier of the attribute value to split.
Source

pub fn split_vertex_attributes( &self, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, )

Execute a splitting operation on all attributes associated with vertices for specified cells.

§Arguments
  • orbit_policy: OrbitPolicy – Orbit associated with affected attributes.
  • id_out_lhs: DartIdentifier – Identifier to write the result to.
  • id_out_rhs: DartIdentifier – Identifier to write the result to.
  • id_in: DartIdentifier – Identifier of the attribute value to split.
Source

pub fn split_edge_attributes( &self, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, )

Execute a splitting operation on all attributes associated with edges for specified cells.

§Arguments
  • orbit_policy: OrbitPolicy – Orbit associated with affected attributes.
  • id_out_lhs: DartIdentifier – Identifier to write the result to.
  • id_out_rhs: DartIdentifier – Identifier to write the result to.
  • id_in: DartIdentifier – Identifier of the attribute value to split.
Source

pub fn split_face_attributes( &self, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, )

Execute a splitting operation on all attributes associated with faces for specified cells.

§Arguments
  • orbit_policy: OrbitPolicy – Orbit associated with affected attributes.
  • id_out_lhs: DartIdentifier – Identifier to write the result to.
  • id_out_rhs: DartIdentifier – Identifier to write the result to.
  • id_in: DartIdentifier – Identifier of the attribute value to split.
Source

pub fn split_other_attributes( &self, _orbit_policy: &OrbitPolicy, _id_out_lhs: DartIdType, _id_out_rhs: DartIdType, _id_in: DartIdType, )

Execute a splitting operation on all attributes associated with a given orbit for specified cells.

§Arguments
  • orbit_policy: OrbitPolicy – Orbit associated with affected attributes.
  • id_out_lhs: DartIdentifier – Identifier to write the result to.
  • id_out_rhs: DartIdentifier – Identifier to write the result to.
  • id_in: DartIdentifier – Identifier of the attribute value to split.
Source§

impl AttrStorageManager

Attribute-specific methods

Source

pub fn add_storage<A: AttributeBind + 'static>(&mut self, size: usize)

Add a new storage to the manager.

For a breakdown of the principles used for implementation, refer to the Explanation section of the AttrStorageManager documentation entry.

§Arguments
  • size: usize – Initial size of the new storage.
§Generic
  • A: AttributeBind + 'static – Type of the attribute that will be stored.
§Panics

This function will panic if there is already a storage of attribute A in the manager.

Source

pub fn extend_storage<A: AttributeBind>(&mut self, length: usize)

Extend the size of the storage of a given attribute.

§Arguments
  • length: usize – Length by which the storage should be extended.
§Generic
  • A: AttributeBind – Attribute of which the storage should be extended.
Source

pub fn get_storage<A: AttributeBind>( &self, ) -> Option<&<A as AttributeBind>::StorageType>

Get a reference to the storage of a given attribute.

§Generic
  • A: AttributeBind – Attribute stored by the fetched storage.
§Panics

This method may panic if:

  • there’s no storage associated with the specified attribute
  • downcasting Box<dyn UnknownAttributeStorage> to <A as AttributeBind>::StorageType fails
Source

pub fn remove_storage<A: AttributeBind>(&mut self)

Remove an entire attribute storage from the manager.

This method is useful when implementing routines that uses attributes to run; Those can then be removed before the final result is returned.

§Generic
  • A: AttributeBind – Attribute stored by the fetched storage.
Source

pub fn set_attribute<A: AttributeBind>(&self, id: A::IdentifierType, val: A)

Set the value of an attribute.

§Arguments
  • id: A::IdentifierType – Cell ID to which the attribute is associated.
  • val: A – New value of the attribute for the given ID.
§Generic
  • A: AttributeBind – Type of the attribute being set.
§Panics

This method may panic if:

  • there’s no storage associated with the specified attribute
  • downcasting Box<dyn UnknownAttributeStorage> to <A as AttributeBind>::StorageType fails
  • the index lands out of bounds
Source

pub fn insert_attribute<A: AttributeBind>(&self, id: A::IdentifierType, val: A)

Set the value of an attribute.

§Arguments
  • id: A::IdentifierType – Cell ID to which the attribute is associated.
  • val: A – New value of the attribute for the given ID.
§Generic
  • A: AttributeBind – Type of the attribute being set.
§Panics

This method may panic if:

  • there already is a value associated to the given ID for the specified attribute
  • there’s no storage associated with the specified attribute
  • downcasting Box<dyn UnknownAttributeStorage> to <A as AttributeBind>::StorageType fails
  • the index lands out of bounds
Source

pub fn get_attribute<A: AttributeBind>( &self, id: A::IdentifierType, ) -> Option<A>

Get the value of an attribute.

§Arguments
  • id: A::IdentifierType – Cell ID to which the attribute is associated.
§Generic
  • A: AttributeBind – Type of the attribute fetched.
§Return

The method may return:

  • Some(val: A) if there is an attribute associated with the specified index,
  • None if there is not.
§Panics

This method may panic if:

  • there’s no storage associated with the specified attribute
  • downcasting Box<dyn UnknownAttributeStorage> to <A as AttributeBind>::StorageType fails
  • the index lands out of bounds
Source

pub fn replace_attribute<A: AttributeBind>( &self, id: A::IdentifierType, val: A, ) -> Option<A>

Set the value of an attribute.

§Arguments
  • id: A::IdentifierType – ID of the cell to which the attribute is associated.
  • val: A – New value of the attribute for the given ID.
§Generic
  • A: AttributeBind – Type of the attribute being set.
§Return

The method should return:

  • Some(val_old: A) if there was an attribute associated with the specified index,
  • None if there was not.
§Panics

This method may panic if:

  • there’s no storage associated with the specified attribute
  • downcasting Box<dyn UnknownAttributeStorage> to <A as AttributeBind>::StorageType fails
  • the index lands out of bounds
Source

pub fn remove_attribute<A: AttributeBind>( &self, id: A::IdentifierType, ) -> Option<A>

Remove the an item from an attribute storage.

§Arguments
  • id: A::IdentifierType – Cell ID to which the attribute is associated.
§Generic
  • A: AttributeBind – Type of the attribute fetched.
§Return

The method may return:

  • Some(val: A) if was is an attribute associated with the specified index,
  • None if there was not.
§Panics

This method may panic if:

  • there’s no storage associated with the specified attribute
  • downcasting Box<dyn UnknownAttributeStorage> to <A as AttributeBind>::StorageType fails
  • the index lands out of bounds
Source

pub fn merge_attribute<A: AttributeBind>( &self, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, )

Merge given attribute values.

§Arguments
  • id_out: DartIdentifier – Identifier to write the result to.
  • id_in_lhs: DartIdentifier – Identifier of one attribute value to merge.
  • id_in_rhs: DartIdentifier – Identifier of the other attribute value to merge.
Source

pub fn split_attribute<A: AttributeBind>( &self, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, )

Split given attribute value.

§Arguments
  • id_out_lhs: DartIdentifier – Identifier to write the result to.
  • id_out_rhs: DartIdentifier – Identifier to write the result to.
  • id_in: DartIdentifier – Identifier of the attribute value to split.

Trait Implementations§

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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, 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.