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

General 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 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§

impl AttrStorageManager

Merge variants.

Source

pub fn force_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.

This variant is equivalent to merge_attributes, but internally uses a transaction that will be retried until validated.

Source

pub fn force_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.

This variant is equivalent to merge_vertex_attributes, but internally uses a transaction that will be retried until validated.

Source

pub fn force_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.

This variant is equivalent to merge_edge_attributes, but internally uses a transaction that will be retried until validated.

Source

pub fn force_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.

This variant is equivalent to merge_face_attributes, but internally uses a transaction that will be retried until validated.

Source

pub fn merge_attributes( &self, trans: &mut Transaction, orbit_policy: &OrbitPolicy, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, ) -> StmResult<()>

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

§Arguments
  • trans: &mut Transaction – Transaction used for synchronization.
  • 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.
§Return / Errors

This method is meant to be called in a context where the returned Result is used to validate the transaction passed as argument. The result should not be processed manually.

Source

pub fn merge_vertex_attributes( &self, trans: &mut Transaction, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, ) -> StmResult<()>

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

§Arguments
  • trans: &mut Transaction – Transaction used for synchronization.
  • 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.
§Return / Errors

This method is meant to be called in a context where the returned Result is used to validate the transaction passed as argument. The result should not be processed manually.

Source

pub fn merge_edge_attributes( &self, trans: &mut Transaction, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, ) -> StmResult<()>

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

§Arguments
  • trans: &mut Transaction – Transaction used for synchronization.
  • 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.
§Return / Errors

This method is meant to be called in a context where the returned Result is used to validate the transaction passed as argument. The result should not be processed manually.

Source

pub fn merge_face_attributes( &self, trans: &mut Transaction, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, ) -> StmResult<()>

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

§Arguments
  • trans: &mut Transaction – Transaction used for synchronization.
  • 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.
§Return / Errors

This method is meant to be called in a context where the returned Result is used to validate the transaction passed as argument. The result should not be processed manually.

Source

pub fn try_merge_attributes( &self, trans: &mut Transaction, orbit_policy: &OrbitPolicy, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, ) -> CMapResult<()>

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

§Errors

This method will fail, returning an error, if:

  • the transaction cannot be completed
  • a merge fails (e.g. because one merging value is missing)

The returned error can be used in conjunction with transaction control to avoid any modifications in case of failure at attribute level. The user can then choose, through its transaction control policy, to retry or abort as he wishes.

Source

pub fn try_merge_vertex_attributes( &self, trans: &mut Transaction, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, ) -> CMapResult<()>

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

§Errors

This method will fail, returning an error, if:

  • the transaction cannot be completed
  • a merge fails (e.g. because one merging value is missing)

The returned error can be used in conjunction with transaction control to avoid any modifications in case of failure at attribute level. The user can then choose, through its transaction control policy, to retry or abort as he wishes.

Source

pub fn try_merge_edge_attributes( &self, trans: &mut Transaction, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, ) -> CMapResult<()>

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

§Errors

This method will fail, returning an error, if:

  • the transaction cannot be completed
  • a merge fails (e.g. because one merging value is missing)

The returned error can be used in conjunction with transaction control to avoid any modifications in case of failure at attribute level. The user can then choose, through its transaction control policy, to retry or abort as he wishes.

Source

pub fn try_merge_face_attributes( &self, trans: &mut Transaction, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, ) -> CMapResult<()>

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

§Errors

This method will fail, returning an error, if:

  • the transaction cannot be completed
  • a merge fails (e.g. because one merging value is missing)

The returned error can be used in conjunction with transaction control to avoid any modifications in case of failure at attribute level. The user can then choose, through its transaction control policy, to retry or abort as he wishes.

Source

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

Merge given attribute values.

This variant is equivalent to merge_attribute, but internally uses a transaction that will be retried until validated.

Source

pub fn merge_attribute<A: AttributeBind + AttributeUpdate>( &self, trans: &mut Transaction, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, ) -> StmResult<()>

Merge given attribute values.

§Arguments
  • trans: &mut Transaction – Transaction used for synchronization.
  • 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.
§Return / Errors

This method is meant to be called in a context where the returned Result is used to validate the transaction passed as argument. The result should not be processed manually.

Source

pub fn try_merge_attribute<A: AttributeBind + AttributeUpdate>( &self, trans: &mut Transaction, id_out: DartIdType, id_in_lhs: DartIdType, id_in_rhs: DartIdType, ) -> CMapResult<()>

Merge given attribute values.

§Errors

This method will fail, returning an error, if:

  • the transaction cannot be completed
  • the merge fails (e.g. because one merging value is missing)

The returned error can be used in conjunction with transaction control to avoid any modifications in case of failure at attribute level. The user can then choose, through its transaction control policy, to retry or abort as he wishes.

Source§

impl AttrStorageManager

Split variants.

Source

pub fn force_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.

This variant is equivalent to split_attributes, but internally uses a transaction that will be retried until validated.

Source

pub fn force_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.

This variant is equivalent to split_vertex_attributes, but internally uses a transaction that will be retried until validated.

Source

pub fn force_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.

This variant is equivalent to split_edge_attributes, but internally uses a transaction that will be retried until validated.

Source

pub fn force_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.

This variant is equivalent to split_face_attributes, but internally uses a transaction that will be retried until validated.

Source

pub fn split_attributes( &self, trans: &mut Transaction, orbit_policy: &OrbitPolicy, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, ) -> StmResult<()>

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

§Arguments
  • trans: &mut Transaction – Transaction used for synchronization.
  • 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.
§Return / Errors

This method is meant to be called in a context where the returned Result is used to validate the transaction passed as argument. The result should not be processed manually.

Source

pub fn split_vertex_attributes( &self, trans: &mut Transaction, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, ) -> StmResult<()>

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

§Arguments
  • trans: &mut Transaction – Transaction used for synchronization.
  • 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.
§Return / Errors

This method is meant to be called in a context where the returned Result is used to validate the transaction passed as argument. The result should not be processed manually.

Source

pub fn split_edge_attributes( &self, trans: &mut Transaction, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, ) -> StmResult<()>

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

§Arguments
  • trans: &mut Transaction – Transaction used for synchronization.
  • 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.
§Return / Errors

This method is meant to be called in a context where the returned Result is used to validate the transaction passed as argument. The result should not be processed manually.

Source

pub fn split_face_attributes( &self, trans: &mut Transaction, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, ) -> StmResult<()>

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

§Arguments
  • trans: &mut Transaction – Transaction used for synchronization.
  • 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.
§Return / Errors

This method is meant to be called in a context where the returned Result is used to validate the transaction passed as argument. The result should not be processed manually.

Source

pub fn try_split_attributes( &self, trans: &mut Transaction, orbit_policy: &OrbitPolicy, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, ) -> CMapResult<()>

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

§Errors

This method will fail, returning an error, if:

  • the transaction cannot be completed
  • a split fails (e.g. because there is no value to split from)

The returned error can be used in conjunction with transaction control to avoid any modifications in case of failure at attribute level. The user can then choose, through its transaction control policy, to retry or abort as he wishes.

Source

pub fn try_split_vertex_attributes( &self, trans: &mut Transaction, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, ) -> CMapResult<()>

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

§Errors

This method will fail, returning an error, if:

  • the transaction cannot be completed
  • a split fails (e.g. because there is no value to split from)

The returned error can be used in conjunction with transaction control to avoid any modifications in case of failure at attribute level. The user can then choose, through its transaction control policy, to retry or abort as he wishes.

Source

pub fn try_split_edge_attributes( &self, trans: &mut Transaction, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, ) -> CMapResult<()>

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

§Errors

This method will fail, returning an error, if:

  • the transaction cannot be completed
  • a split fails (e.g. because there is no value to split from)

The returned error can be used in conjunction with transaction control to avoid any modifications in case of failure at attribute level. The user can then choose, through its transaction control policy, to retry or abort as he wishes.

Source

pub fn try_split_face_attributes( &self, trans: &mut Transaction, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, ) -> CMapResult<()>

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

§Errors

This method will fail, returning an error, if:

  • the transaction cannot be completed
  • a split fails (e.g. because there is no value to split from)

The returned error can be used in conjunction with transaction control to avoid any modifications in case of failure at attribute level. The user can then choose, through its transaction control policy, to retry or abort as he wishes.

Source

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

Split given attribute value.

This variant is equivalent to split_attribute, but internally uses a transaction that will be retried until validated.

Source

pub fn split_attribute<A: AttributeBind + AttributeUpdate>( &self, trans: &mut Transaction, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, ) -> StmResult<()>

Split given attribute value.

§Arguments
  • trans: &mut Transaction – Transaction used for synchronization.
  • 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.
§Return / Errors

This method is meant to be called in a context where the returned Result is used to validate the transaction passed as argument. The result should not be processed manually.

Source

pub fn try_split_attribute<A: AttributeBind + AttributeUpdate>( &self, trans: &mut Transaction, id_out_lhs: DartIdType, id_out_rhs: DartIdType, id_in: DartIdType, ) -> CMapResult<()>

Split given attribute value.

§Errors

This method will fail, returning an error, if:

  • the transaction cannot be completed
  • the split fails (e.g. because there is no value to split from)

The returned error can be used in conjunction with transaction control to avoid any modifications in case of failure at attribute level. The user can then choose, through its transaction control policy, to retry or abort as he wishes.

Source§

impl AttrStorageManager

Attribute read & write methods

Source

pub fn read_attribute<A: AttributeBind>( &self, trans: &mut Transaction, id: A::IdentifierType, ) -> StmResult<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 / Errors

This method is meant to be called in a context where the returned Result is used to validate the transaction passed as argument. The result should not be processed manually, only used via the ? operator.

§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 write_attribute<A: AttributeBind>( &self, trans: &mut Transaction, id: A::IdentifierType, val: A, ) -> StmResult<Option<A>>

Set the value of an attribute, and return the old one.

§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 / Errors

This method is meant to be called in a context where the returned Result is used to validate the transaction passed as argument. The result should not be processed manually, only used via the ? operator.

§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 force_read_attribute<A: AttributeBind>( &self, id: A::IdentifierType, ) -> Option<A>

Get the value of an attribute.

This variant is equivalent to read_attribute, but internally uses a transaction that will be retried until validated.

Source

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

Set the value of an attribute, and return the old one.

This variant is equivalent to write_attribute, but internally uses a transaction that will be retried until validated.

Source

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

Remove the an item from an attribute storage, and return it.

This variant is equivalent to remove_attribute, but internally uses a transaction that will be retried until validated.

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.