1.3.64
 
Loading...
Searching...
No Matches
helios::UUIDPositionMapper Class Reference

Bidirectional mapper between UUIDs and array positions. More...

#include <IndexTypes.h>

Public Member Functions

void build (const std::vector< uint > &primitive_uuids)
 Build mapping from ordered UUID list.
 
ArrayPosition toPosition (PrimitiveUUID uuid) const
 Convert UUID to array position.
 
PrimitiveUUID toUUID (ArrayPosition pos) const
 Convert array position to UUID.
 
bool isValidUUID (PrimitiveUUID uuid) const
 Check if UUID exists in the mapping.
 
size_t getPrimitiveCount () const
 Get total number of primitives in the mapping.
 
bool empty () const
 Check if mapper is empty (no primitives)
 

Detailed Description

Bidirectional mapper between UUIDs and array positions.

Provides O(1) conversion in both directions:

  • UUID → Position: Sparse array lookup uuid_to_position_[UUID]
  • Position → UUID: Dense array lookup position_to_uuid_[position]

The mapper is built once during geometry initialization and used throughout the radiation model for all index conversions.

Thread-safe for read operations after build() completes.

// Build mapper from ordered UUID list
std::vector<uint> primitive_uuids = {10, 42, 100, 5}; // Order defines positions
mapper.build(primitive_uuids);
// Convert UUID → Position
PrimitiveUUID uuid{42};
ArrayPosition pos = mapper.toPosition(uuid); // Returns ArrayPosition{1}
// Convert Position → UUID
PrimitiveUUID uuid = mapper.toUUID(ArrayPosition{3}); // Returns PrimitiveUUID{5}

Definition at line 133 of file IndexTypes.h.

Member Function Documentation

◆ build()

void helios::UUIDPositionMapper::build ( const std::vector< uint > &  primitive_uuids)
inline

Build mapping from ordered UUID list.

Parameters
primitive_uuidsVector of UUIDs in array position order (i.e., primitive_uuids[i] is the UUID at position i)

This method:

  1. Stores the dense position→UUID mapping
  2. Builds a sparse UUID→position lookup table sized to max_UUID + 1
  3. Populates the sparse table with SIZE_MAX for non-existent UUIDs

Complexity: O(n) where n = number of primitives

Definition at line 156 of file IndexTypes.h.

◆ empty()

bool helios::UUIDPositionMapper::empty ( ) const
inline

Check if mapper is empty (no primitives)

Definition at line 252 of file IndexTypes.h.

◆ getPrimitiveCount()

size_t helios::UUIDPositionMapper::getPrimitiveCount ( ) const
inline

Get total number of primitives in the mapping.

Returns
Number of primitives (equivalent to position_to_uuid_.size())

Definition at line 245 of file IndexTypes.h.

◆ isValidUUID()

bool helios::UUIDPositionMapper::isValidUUID ( PrimitiveUUID  uuid) const
inline

Check if UUID exists in the mapping.

Parameters
uuidPrimitive UUID to check
Returns
true if UUID maps to a valid position
if (!mapper.isValidUUID(PrimitiveUUID{42})) {
std::cerr << "UUID 42 not found in geometry\n";
}

Definition at line 236 of file IndexTypes.h.

◆ toPosition()

ArrayPosition helios::UUIDPositionMapper::toPosition ( PrimitiveUUID  uuid) const
inline

Convert UUID to array position.

Parameters
uuidPrimitive UUID
Returns
Array position, or INVALID_POSITION if UUID not found

Complexity: O(1)

PrimitiveUUID uuid{42};
ArrayPosition pos = mapper.toPosition(uuid);
if (pos == INVALID_POSITION) {
helios_runtime_error("UUID not found");
}

Definition at line 190 of file IndexTypes.h.

◆ toUUID()

PrimitiveUUID helios::UUIDPositionMapper::toUUID ( ArrayPosition  pos) const
inline

Convert array position to UUID.

Parameters
posArray position
Returns
Primitive UUID
Exceptions
std::out_of_rangeif position is out of bounds

Complexity: O(1)

PrimitiveUUID uuid = mapper.toUUID(pos);

Definition at line 217 of file IndexTypes.h.


The documentation for this class was generated from the following file: