Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
BS::blocks< T > Class Template Reference

A helper class to divide a range into blocks. Used by detach_blocks(), submit_blocks(), detach_loop(), and submit_loop(). More...

#include <BS_thread_pool.hpp>

Public Member Functions

 blocks (const T first_index_, const T index_after_last_, const std::size_t num_blocks_) noexcept
 Construct a blocks object with the given specifications.
 
end (const std::size_t block) const noexcept
 Get the index after the last index of a block.
 
std::size_t get_num_blocks () const noexcept
 Get the number of blocks. Note that this may be different than the desired number of blocks that was passed to the constructor.
 
start (const std::size_t block) const noexcept
 Get the first index of a block.
 

Private Attributes

std::size_t block_size = 0
 The size of each block (except possibly the last block).
 
std::size_t num_blocks = 0
 The number of blocks.
 
std::size_t remainder = 0
 The remainder obtained after dividing the total size by the number of blocks.
 
first_index = 0
 The first index in the range.
 
index_after_last = 0
 The index after the last index in the range.
 

Detailed Description

template<typename T>
class BS::blocks< T >

A helper class to divide a range into blocks. Used by detach_blocks(), submit_blocks(), detach_loop(), and submit_loop().

Template Parameters
TThe type of the indices. Should be a signed or unsigned integer.

Constructor & Destructor Documentation

◆ blocks()

template<typename T >
BS::blocks< T >::blocks ( const T  first_index_,
const T  index_after_last_,
const std::size_t  num_blocks_ 
)
inlinenoexcept

Construct a blocks object with the given specifications.

Parameters
first_index_The first index in the range.
index_after_last_The index after the last index in the range.
num_blocks_The desired number of blocks to divide the range into.
584 : num_blocks(num_blocks_), first_index(first_index_), index_after_last(index_after_last_)
585 {
587 {
588 const std::size_t total_size = static_cast<std::size_t>(index_after_last - first_index);
589 num_blocks = std::min(num_blocks, total_size);
590 block_size = total_size / num_blocks;
591 remainder = total_size % num_blocks;
592 if (block_size == 0)
593 {
594 block_size = 1;
595 num_blocks = (total_size > 1) ? total_size : 1;
596 }
597 }
598 else
599 {
600 num_blocks = 0;
601 }
602 }
T index_after_last
The index after the last index in the range.
Definition BS_thread_pool.hpp:660
std::size_t block_size
The size of each block (except possibly the last block).
Definition BS_thread_pool.hpp:640
std::size_t num_blocks
The number of blocks.
Definition BS_thread_pool.hpp:645
T first_index
The first index in the range.
Definition BS_thread_pool.hpp:655
std::size_t remainder
The remainder obtained after dividing the total size by the number of blocks.
Definition BS_thread_pool.hpp:650

Member Function Documentation

◆ end()

template<typename T >
T BS::blocks< T >::end ( const std::size_t  block) const
inlinenoexcept

Get the index after the last index of a block.

Parameters
blockThe block number.
Returns
The index after the last index.
611 {
612 return (block == num_blocks - 1) ? index_after_last : start(block + 1);
613 }
T start(const std::size_t block) const noexcept
Get the first index of a block.
Definition BS_thread_pool.hpp:631

◆ get_num_blocks()

template<typename T >
std::size_t BS::blocks< T >::get_num_blocks ( ) const
inlinenoexcept

Get the number of blocks. Note that this may be different than the desired number of blocks that was passed to the constructor.

Returns
The number of blocks.
621 {
622 return num_blocks;
623 }
Here is the caller graph for this function:

◆ start()

template<typename T >
T BS::blocks< T >::start ( const std::size_t  block) const
inlinenoexcept

Get the first index of a block.

Parameters
blockThe block number.
Returns
The first index.
632 {
633 return first_index + static_cast<T>(block * block_size) + static_cast<T>(block < remainder ? block : remainder);
634 }

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