Aspect Ratio Iterator

Header: fiction/algorithms/iter/aspect_ratio_iterator.hpp

template<typename AspectRatio>
class aspect_ratio_iterator

An iterator type that iterates over increasingly larger 2D aspect ratios via factorization, starting from a number of faces \( n \). After iterating over all possible factorizations of n, the next step increases \( n \) and continues with the factorization. Thereby, a sequence of aspect ratios starting from \( n = 4 \) faces looks like this: \( 1 \times 4, 4 \times 1, 2 \times 2, 1 \times 5, 5 \times 1, 1 \times 6, 6 \times 1, 2 \times 3, 3 \times 2, \dots \)

Template Parameters:

AspectRatio – Aspect ratio type.

Public Functions

inline explicit aspect_ratio_iterator([[maybe_unused]] uint64_t n = 0ul) noexcept

Standard constructor. Takes a starting value and computes an initial factorization. The value n represents the amount of faces in the desired aspect ratios. For example, \( n = 1 \) will yield aspect ratios with exactly \( 1 \) face, i.e. \( 1 \times 1 \) which is equal to ucoord_t{0, 0}. If \( n = 2 \), the aspect ratios \( 1 \times 2 \) and \( 2 \times 1 \) will result, which are equal to ucoord_t{0, 1} and ucoord_t{1, 0}. Both examples with AspectRatio == offset::ucoord_t.

Parameters:

n – Starting value of the aspect ratio iteration.

inline aspect_ratio_iterator &operator++() noexcept

Lets the iterator point to the next dimension of the current factorization. If there are no next factors, num is incremented and the next factors are computed.

Prefix version.

Returns:

Reference to this.

inline aspect_ratio_iterator operator++(int) noexcept

Creates a new iterator that points to the next dimension of the current factorization. If there are no next factors, num is incremented and the next factors are computed.

Postfix version. Less performance than the prefix version due to copy construction.

Returns:

Resulting iterator.

Gray Code Iterator

Header: fiction/algorithms/iter/gray_code_iterator.hpp

class gray_code_iterator

An iterator type that iterates over Gray code representations for decimal numbers.

The gray_code_iterator class provides an iterator for generating Gray code representations for a range of decimal numbers. It starts from a specified number and produces Gray codes in ascending order based on bitwise XOR operations.

Public Functions

inline explicit constexpr gray_code_iterator(const uint64_t start) noexcept

Constructs a Gray Code Iterator with a specified starting number.

Constructs a gray_code_iterator that generates Gray codes for decimal numbers starting from the given start number.

Parameters:

start – The starting decimal number for the iterator.

inline constexpr const uint64_t &operator*() const noexcept

Dereference operator. Returns a reference to the Gray code of the current iteration.

Returns:

Reference to the current Gray code.

inline constexpr gray_code_iterator &operator++() noexcept

Prefix increment operator. Sets the number and the corresponding Gray code.

Returns:

Reference to this.

inline constexpr bool operator==(const gray_code_iterator &other) const noexcept

Equality comparison operator. Compares the current iterator with another iterator.

Parameters:

other – The iterator to compare with.

Returns:

true if the current iterator is equal to the other iterator, false otherwise.

inline constexpr bool operator!=(const gray_code_iterator &other) const noexcept

Inequality comparison operator. Compares the current iterator with another iterator.

Parameters:

other – The iterator to compare with.

Returns:

true if the current iterator is not equal to the other iterator, false otherwise.

inline constexpr bool operator<(const gray_code_iterator &other) const noexcept

Less-than comparison operator. Compares the current iterator with another iterator.

Parameters:

other – The iterator to compare with.

Returns:

true if the current iterator is less than the other iterator, false otherwise.

inline constexpr bool operator<=(const gray_code_iterator &other) const noexcept

Less-than or equal-to comparison operator. Compares the current iterator with another iterator.

Parameters:

other – The iterator to compare with.

Returns:

true if the current iterator is less than or equal to the other iterator, false otherwise.

inline constexpr int64_t operator-(const gray_code_iterator &other) const noexcept

Subtraction operator to calculate the difference between two gray_code_iterators.

This operator calculates the difference between the current iterator and another gray_code_iterator provided as input. The result is returned as an int64_t representing the number of positions between the iterators.

Parameters:

other – The gray_code_iterator to subtract from the current iterator.

Returns:

The difference between the current iterator and the input iterator as int64_t.

inline constexpr gray_code_iterator operator++(int) noexcept

Postfix increment operator. Sets the next Gray Code.

Returns:

Copy of this before incrementing.

inline constexpr gray_code_iterator operator+(const int m) const noexcept

Addition operator. Computes the Gray code of the current iterator plus the given integer.

Parameters:

m – The amount of Gray codes to skip.

Returns:

Iterator of the current iterator plus the given integer.

inline constexpr gray_code_iterator &operator+=(const int m) noexcept

Addition assignment operator. Iterator is increased by given number.

Parameters:

m – The amount of Gray codes to skip.

Returns:

Reference to this.

inline constexpr gray_code_iterator operator-(const int m) const noexcept

Subtraction operator. Computes the Gray code of the current iterator minus the given integer.

Parameters:

m – The amount of Gray codes to skip.

Returns:

Iterator of the current iterator minus the given integer.

inline constexpr gray_code_iterator &operator--() noexcept

Prefix decrement operator. Sets the previous Gray code.

Returns:

Reference to this.

inline constexpr gray_code_iterator operator--(int) noexcept

Postfix decrement operator. Sets the previous Gray Code.

Returns:

Copy of this before decrementing.

inline constexpr gray_code_iterator &operator-=(const int m) noexcept

Subtraction assignment operator. Sets a previous Gray code.

Parameters:

m – The amount of Gray codes to skip.

Returns:

Reference to this.

inline constexpr gray_code_iterator &operator=(const uint64_t m) noexcept

Assignment operator. Sets the current number to the given integer.

Parameters:

m – The number to set.

inline constexpr uint64_t operator[](std::size_t index) const noexcept

Subscript operator. Returns the Gray code at a specific position in the iteration range.

Parameters:

index – The position in the iteration range.

Returns:

The Gray code at the specified position.

inline constexpr bool operator==(const uint64_t m) const noexcept

Equality operator. Compares the current number with the given integer.

Parameters:

m – Integer to compare with.

Returns:

true if the current number is equal to m, false otherwise.

inline constexpr bool operator!=(const uint64_t m) const noexcept

Inequality operator. Compares the current number with the given integer.

Parameters:

m – Integer to compare with.

Returns:

true if the current number is not equal to m, false otherwise.

inline constexpr bool operator<(const uint64_t m) const noexcept

Less-than operator. Compares the current number with the given integer.

Parameters:

m – Integer to compare with.

Returns:

true if the current number is less than m, false otherwise.

inline constexpr bool operator<=(const uint64_t m) const noexcept

Less-or-equal-than operator. Compares the current number with the given integer.

Parameters:

m – Integer to compare with.

Returns:

true if the current number is less than or equal to m, false otherwise.

inline constexpr bool operator>(const uint64_t m) const noexcept

Greater-than operator. Compares the current number with the given integer.

Parameters:

m – Integer to compare with.

Returns:

true if the current number is greater than m, false otherwise.

inline constexpr bool operator>=(const uint64_t m) const noexcept

Greater-or-equal-than operator. Compares the current number with the given integer.

Parameters:

m – Integer to compare with.

Returns:

true if the current number is greater than or equal to m, false otherwise.

BDL Input Iterator

Header: fiction/algorithms/iter/bdl_input_iterator.hpp

template<typename Lyt>
class bdl_input_iterator

Iterator that iterates over all possible input states of a BDL layout. There are \( 2^n \) possible input states for an \(n\)-input BDL layout, each with a unique input index. The input index is interpreted as a binary number, where the \(i\)-th bit represents the input state of the \(i\)-th input BDL pair. If the bit is 1, the lower BDL dot is set and the upper BDL dot removed. If the bit is 0, the upper BDL dot is removed and the lower BDL dot set. The iterator creates and stores a deep-copy of the given layout. The state enumeration wraps around, i.e. after the last possible input state, the first input state is set again.

The iterator satisfies the requirements of LegacyRandomAccessIterator and can be used in iterator-based for loops.

Template Parameters:

Lyt – SiDB cell-level layout type.

Public Functions

inline explicit bdl_input_iterator(const Lyt &lyt, const detect_bdl_pairs_params &params = {}) noexcept

Standard constructor. It alters the layout to set the first input state, which assigns binary 0 to all input BDL pairs.

Parameters:
  • lyt – The SiDB BDL layout to iterate over.

  • params – Parameters for the BDL pair detection.

inline const Lyt &operator*() const noexcept

Dereference operator. Returns a reference to the layout with the current input state.

Returns:

Reference to the current layout.

inline bdl_input_iterator &operator++() noexcept

Prefix increment operator. Sets the next input state.

Returns:

Reference to this.

inline bdl_input_iterator operator++(int) noexcept

Postfix increment operator. Sets the next input state.

Returns:

Copy of this before incrementing.

inline bdl_input_iterator operator+(const int m) const noexcept

Addition operator. Computes the input state of the current iterator plus the given integer.

Parameters:

m – The amount of input states to skip.

Returns:

The input state of the current iterator plus the given integer.

inline bdl_input_iterator &operator+=(const int m) noexcept

Addition assignment operator. Sets a next input state.

Parameters:

m – The amount of input states to skip.

Returns:

Reference to this.

inline bdl_input_iterator operator-(const int m) const noexcept

Subtraction operator. Computes the input state of the current iterator minus the given integer.

Parameters:

m – The amount of input states to skip.

Returns:

The input state of the current iterator minus the given integer.

inline bdl_input_iterator &operator--() noexcept

Prefix decrement operator. Sets the previous input state.

Returns:

Reference to this.

inline bdl_input_iterator operator--(int) noexcept

Postfix decrement operator. Sets the previous input state.

Returns:

Copy of this before decrementing.

inline bdl_input_iterator &operator-=(const int m) noexcept

Subtraction assignment operator. Sets a previous input state.

Parameters:

m – The amount of input states to skip.

Returns:

Reference to this.

inline bdl_input_iterator &operator=(const uint64_t m) noexcept

Assignment operator. Sets the input state to the given integer.

Parameters:

m – The input state to set.

inline bdl_input_iterator operator[](const int m) const noexcept

Subscript operator. Computes the input state of the current iterator plus the given integer.

Parameters:

m – The amount of input states to skip.

Returns:

The input state of the current iterator plus the given integer.

inline int64_t operator-(const bdl_input_iterator &other) const noexcept

Subtraction operator. Computes the difference between the current input index and the given iterator ones.

Parameters:

other – Iterator to compute the difference with.

Returns:

The difference between the current input index and the given iterator ones.

inline bool operator==(const uint64_t m) const noexcept

Equality operator. Compares the current input index with the given integer.

Parameters:

m – Integer to compare with.

Returns:

true if the current input index is equal to m, false otherwise.

inline bool operator!=(const uint64_t m) const noexcept

Inequality operator. Compares the current input index with the given integer.

Parameters:

m – Integer to compare with.

Returns:

true if the current input index is not equal to m, false otherwise.

inline bool operator<(const uint64_t m) const noexcept

Less-than operator. Compares the current input index with the given integer.

Parameters:

m – Integer to compare with.

Returns:

true if the current input index is less than m, false otherwise.

inline bool operator<=(const uint64_t m) const noexcept

Less-or-equal-than operator. Compares the current input index with the given integer.

Parameters:

m – Integer to compare with.

Returns:

true if the current input index is less than or equal to m, false otherwise.

inline bool operator>(const uint64_t m) const noexcept

Greater-than operator. Compares the current input index with the given integer.

Parameters:

m – Integer to compare with.

Returns:

true if the current input index is greater than m, false otherwise.

inline bool operator>=(const uint64_t m) const noexcept

Greater-or-equal-than operator. Compares the current input index with the given integer.

Parameters:

m – Integer to compare with.

Returns:

true if the current input index is greater than or equal to m, false otherwise.

inline uint64_t get_number_of_inputs() const noexcept

Returns the total number of input BDL pairs of the given SiDB gate layout.

Returns:

The number of input BDL pairs.