Rosetta
|
This class handles the bookeeping to map between a set of integer ids in the "source" enumeration to a subset of those ids – the destination enumartion. Elements in the source enumeration that do not map to elements in the destination enumeration are represented by the value 0. Both enumerations should count from 1. Once the class has been initialized, this class offers O(1) mapping between elements in the enumerations. More...
#include <integer_mapping.hh>
Public Types | |
typedef utility::VirtualBase | parent |
Public Member Functions | |
subset_mapping () | |
subset_mapping (platform::Size source_enumeration_size) | |
subset_mapping (subset_mapping const &src) | |
subset_mapping & | operator= (subset_mapping const &rhs) |
~subset_mapping () override | |
void | set_source_size (platform::Size) |
Required before the first call to set_next_correspondence may be called. The size of the source enumeration must be known before the mapping may begin. More... | |
void | reserve_destination_size (platform::Size) |
If you know the size of the destination enumeration, then you can save some under-the-hood vector resizing operations by informing the subset_mapping its size up front. This call must proceed the first call to set_next_correspondence. More... | |
void | set_next_correspondence (platform::Size source_id) |
Inform the mapping of the next source-enumeration id that should be mapped to a destination-enumeration id. This will increase the size of the destination enumeration by one. It is not essential that the source-enumeration ids appear in sorted order, however, by construction, the destination ids will be in sorted order. More... | |
platform::Size | source_size () const |
The number of elements in the source enumeration. More... | |
platform::Size | destination_size () const |
The number of elements in the destination enumeration – this represents the number of calls that have been made to set_next_correspondence() More... | |
platform::Size | s2d (platform::Size source_id) const |
Map from the id of an element in source enumeration to an id in the the destination enumeration, which may in fact be UNMAPPED. More... | |
platform::Size | d2s (platform::Size destination_id) const |
Map from the id of an element in the destination enumeration to an id in the source enumeration. This is guaranteed to return a non-zero value. More... | |
bool | source_id_is_mapped (platform::Size source_id) const |
![]() | |
VirtualBase ()=default | |
Default constructor. More... | |
virtual | ~VirtualBase ()=default |
The virtual destructor is one of the main reasons for the VirtualBase class. More... | |
VirtualBase (VirtualBase const &)=default | |
VirtualBase (VirtualBase &&)=default | |
VirtualBase & | operator= (VirtualBase const &)=default |
VirtualBase & | operator= (VirtualBase &&)=default |
Static Public Attributes | |
static platform::Size const | UNMAPPED = 0 |
Private Attributes | |
utility::vector1< platform::Size > | src_2_dst_ |
utility::vector1< platform::Size > | dst_2_src_ |
This class handles the bookeeping to map between a set of integer ids in the "source" enumeration to a subset of those ids – the destination enumartion. Elements in the source enumeration that do not map to elements in the destination enumeration are represented by the value 0. Both enumerations should count from 1. Once the class has been initialized, this class offers O(1) mapping between elements in the enumerations.
|
default |
utility::subset_mapping::subset_mapping | ( | platform::Size | source_enumeration_size | ) |
utility::subset_mapping::subset_mapping | ( | subset_mapping const & | src | ) |
|
overridedefault |
platform::Size utility::subset_mapping::d2s | ( | platform::Size | destination_id | ) | const |
Map from the id of an element in the destination enumeration to an id in the source enumeration. This is guaranteed to return a non-zero value.
References dst_2_src_.
platform::Size utility::subset_mapping::destination_size | ( | ) | const |
The number of elements in the destination enumeration – this represents the number of calls that have been made to set_next_correspondence()
References dst_2_src_.
subset_mapping & utility::subset_mapping::operator= | ( | subset_mapping const & | rhs | ) |
References dst_2_src_, and src_2_dst_.
void utility::subset_mapping::reserve_destination_size | ( | platform::Size | dst_size | ) |
If you know the size of the destination enumeration, then you can save some under-the-hood vector resizing operations by informing the subset_mapping its size up front. This call must proceed the first call to set_next_correspondence.
References dst_2_src_.
platform::Size utility::subset_mapping::s2d | ( | platform::Size | source_id | ) | const |
Map from the id of an element in source enumeration to an id in the the destination enumeration, which may in fact be UNMAPPED.
References src_2_dst_.
void utility::subset_mapping::set_next_correspondence | ( | platform::Size | source_id | ) |
Inform the mapping of the next source-enumeration id that should be mapped to a destination-enumeration id. This will increase the size of the destination enumeration by one. It is not essential that the source-enumeration ids appear in sorted order, however, by construction, the destination ids will be in sorted order.
Prevent out-of-bounds assignment and the overwriting of previously mapped ids. Throws excn::EXCN_Msg_Exceptions
References CREATE_EXCEPTION, dst_2_src_, src_2_dst_, utility::to_string(), and UNMAPPED.
void utility::subset_mapping::set_source_size | ( | platform::Size | src_size | ) |
Required before the first call to set_next_correspondence may be called. The size of the source enumeration must be known before the mapping may begin.
References detail::fill(), src_2_dst_, and UNMAPPED.
bool utility::subset_mapping::source_id_is_mapped | ( | platform::Size | source_id | ) | const |
References src_2_dst_, and UNMAPPED.
platform::Size utility::subset_mapping::source_size | ( | ) | const |
The number of elements in the source enumeration.
References src_2_dst_.
|
private |
Referenced by d2s(), destination_size(), operator=(), reserve_destination_size(), and set_next_correspondence().
|
private |
Referenced by operator=(), s2d(), set_next_correspondence(), set_source_size(), source_id_is_mapped(), and source_size().
|
static |
Referenced by set_next_correspondence(), set_source_size(), and source_id_is_mapped().