Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
Loading...
Searching...
No Matches
correlation::core::ElementPool Class Reference

Thread-safe flyweight pool for chemical Element instances. More...

#include <Atom.hpp>

Static Public Member Functions

static const Element * defaultElement () noexcept
 Returns a shared sentinel empty element instance.
static const Element & get (std::uint16_t index) noexcept
 Lock-free O(1) lookup of an interned Element by its compact 16-bit pool index.
static std::uint16_t internIndex (const Element &elem)
 Interns an Element and returns its compact 16-bit pool index.
static std::uint16_t internIndex (std::string_view symbol, ElementID elem_id)
 Interns an element by symbol and ID and returns its compact 16-bit pool index.
static const Element * intern (const Element &elem)
 Interns an Element into the pool or returns an existing instance.
static const Element * intern (std::string_view symbol, ElementID elem_id)
 Interns an element by symbol and ID into the pool.

Static Public Attributes

static constexpr std::size_t kMaxElements = 65536

Static Private Member Functions

static std::array< std::atomic< const Element * >, kMaxElements > & table () noexcept

Detailed Description

Thread-safe flyweight pool for chemical Element instances.

Member Function Documentation

◆ defaultElement()

const Element * correlation::core::ElementPool::defaultElement ( )
inlinestaticnodiscardnoexcept

Returns a shared sentinel empty element instance.

Returns
Pointer to default element.
Here is the caller graph for this function:

◆ get()

const Element & correlation::core::ElementPool::get ( std::uint16_t index)
inlinestaticnodiscardnoexcept

Lock-free O(1) lookup of an interned Element by its compact 16-bit pool index.

Parameters
[in]indexCompact index returned by internIndex().
Returns
Const reference to the interned Element.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ intern() [1/2]

const Element * correlation::core::ElementPool::intern ( const Element & elem)
inlinestaticnodiscard

Interns an Element into the pool or returns an existing instance.

Parameters
[in]elemElement struct to intern.
Returns
Immutable pointer to shared Element.
Here is the call graph for this function:

◆ intern() [2/2]

const Element * correlation::core::ElementPool::intern ( std::string_view symbol,
ElementID elem_id )
inlinestaticnodiscard

Interns an element by symbol and ID into the pool.

Parameters
[in]symbolChemical symbol.
[in]elem_idElement identifier.
Returns
Immutable pointer to shared Element.
Here is the call graph for this function:

◆ internIndex() [1/2]

std::uint16_t correlation::core::ElementPool::internIndex ( const Element & elem)
inlinestaticnodiscard

Interns an Element and returns its compact 16-bit pool index.

Parameters
[in]elemElement struct to intern.
Returns
Compact pool index (0 for default empty element).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ internIndex() [2/2]

std::uint16_t correlation::core::ElementPool::internIndex ( std::string_view symbol,
ElementID elem_id )
inlinestaticnodiscard

Interns an element by symbol and ID and returns its compact 16-bit pool index.

Parameters
[in]symbolChemical symbol.
[in]elem_idElement identifier.
Returns
Compact pool index (0 for default empty element).
Here is the call graph for this function:

◆ table()

std::array< std::atomic< const Element * >, kMaxElements > & correlation::core::ElementPool::table ( )
inlinestaticprivatenoexcept
Here is the caller graph for this function:

Member Data Documentation

◆ kMaxElements

std::size_t correlation::core::ElementPool::kMaxElements = 65536
staticconstexpr

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