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
duckdb::TemplatedValidityMask< V > Struct Template Reference

Type used for validity masks. More...

Collaboration diagram for duckdb::TemplatedValidityMask< V >:

Public Types

using ValidityBuffer = TemplatedValidityData< V >
 

Public Member Functions

 TemplatedValidityMask (idx_t target_count)
 
 TemplatedValidityMask (V *ptr, idx_t capacity)
 
 TemplatedValidityMask (const TemplatedValidityMask &original, idx_t count)
 
bool AllValid () const
 
bool CheckAllValid (idx_t count) const
 
bool CheckAllInvalid (idx_t count) const
 
bool CheckAllValid (idx_t to, idx_t from) const
 
idx_t CountValid (const idx_t count) const
 
VGetData () const
 
void Reset (idx_t target_count_p=STANDARD_VECTOR_SIZE)
 
V GetValidityEntry (idx_t entry_idx) const
 
VGetValidityEntryUnsafe (idx_t entry_idx) const
 
bool RowIsValidUnsafe (idx_t row_idx) const
 
bool RowIsValid (idx_t row_idx) const
 Returns true if a row is valid (i.e. not null), false otherwise.
 
void SetValidUnsafe (idx_t row_idx)
 Same as SetValid, but skips a null check on validity_mask.
 
void SetValid (idx_t row_idx)
 Marks the entry at the specified row index as valid (i.e. not-null)
 
void SetInvalidUnsafe (idx_t entry_idx, idx_t idx_in_entry)
 Marks the bit at the specified entry as invalid (i.e. null)
 
void SetInvalidUnsafe (idx_t row_idx)
 Marks the bit at the specified row index as invalid (i.e. null)
 
void SetInvalid (idx_t row_idx)
 Marks the entry at the specified row index as invalid (i.e. null)
 
void Set (idx_t row_idx, bool valid)
 Mark the entry at the specified index as either valid or invalid (non-null or null)
 
void EnsureWritable ()
 Ensure the validity mask is writable, allocating space if it is not initialized.
 
void SetRangeInvalid (const idx_t count, const idx_t begin_entry, const idx_t end_entry)
 
void SetAllInvalid (idx_t count)
 Marks exactly "count" bits in the validity mask as invalid (null)
 
void SetAllValid (idx_t count)
 Marks exactly "count" bits in the validity mask as valid (not null)
 
bool IsMaskSet () const
 
void Initialize (validity_t *validity, idx_t new_capacity)
 
void Initialize (const TemplatedValidityMask &other)
 
void Initialize (idx_t count)
 
void Initialize ()
 
void Copy (const TemplatedValidityMask &other, idx_t count)
 

Static Public Member Functions

static idx_t ValidityMaskSize (idx_t count=STANDARD_VECTOR_SIZE)
 
static idx_t EntryCount (idx_t count)
 
static bool AllValid (V entry)
 
static bool NoneValid (V entry)
 
static bool RowIsValid (const V &entry, const idx_t &idx_in_entry)
 
static void GetEntryIndex (idx_t row_idx, idx_t &entry_idx, idx_t &idx_in_entry)
 
static V EntryWithValidBits (idx_t n)
 Get an entry that has first-n bits set as valid and rest set as invalid.
 
static idx_t SizeInBytes (idx_t n)
 

Static Public Attributes

static constexpr const idx_t BITS_PER_VALUE = ValidityBuffer::BITS_PER_VALUE
 
static constexpr const idx_t STANDARD_ENTRY_COUNT = (STANDARD_VECTOR_SIZE + (BITS_PER_VALUE - 1)) / BITS_PER_VALUE
 
static constexpr const idx_t STANDARD_MASK_SIZE = STANDARD_ENTRY_COUNT * sizeof(V)
 

Protected Attributes

Vvalidity_mask
 
buffer_ptr< ValidityBuffervalidity_data
 
idx_t capacity
 

Detailed Description

template<typename V>
struct duckdb::TemplatedValidityMask< V >

Type used for validity masks.

Constructor & Destructor Documentation

◆ TemplatedValidityMask() [1/4]

template<typename V >
duckdb::TemplatedValidityMask< V >::TemplatedValidityMask ( )
inline
8996 : validity_mask(nullptr), capacity(STANDARD_VECTOR_SIZE) {
8997 }

◆ TemplatedValidityMask() [2/4]

template<typename V >
duckdb::TemplatedValidityMask< V >::TemplatedValidityMask ( idx_t  target_count)
inlineexplicit
8998 : validity_mask(nullptr), capacity(target_count) {
8999 }

◆ TemplatedValidityMask() [3/4]

template<typename V >
duckdb::TemplatedValidityMask< V >::TemplatedValidityMask ( V ptr,
idx_t  capacity 
)
inlineexplicit
9000 : validity_mask(ptr), capacity(capacity) {
9001 }

◆ TemplatedValidityMask() [4/4]

template<typename V >
duckdb::TemplatedValidityMask< V >::TemplatedValidityMask ( const TemplatedValidityMask< V > &  original,
idx_t  count 
)
inline
9002 {
9003 Copy(original, count);
9004 }

Member Function Documentation

◆ ValidityMaskSize()

template<typename V >
static idx_t duckdb::TemplatedValidityMask< V >::ValidityMaskSize ( idx_t  count = STANDARD_VECTOR_SIZE)
inlinestatic
9006 {
9007 return ValidityBuffer::EntryCount(count) * sizeof(V);
9008 }

◆ AllValid() [1/2]

template<typename V >
bool duckdb::TemplatedValidityMask< V >::AllValid ( ) const
inline
9009 {
9010 return !validity_mask;
9011 }

◆ CheckAllValid() [1/2]

template<typename V >
bool duckdb::TemplatedValidityMask< V >::CheckAllValid ( idx_t  count) const
inline
9012 {
9013 return CountValid(count) == count;
9014 }

◆ CheckAllInvalid()

template<typename V >
bool duckdb::TemplatedValidityMask< V >::CheckAllInvalid ( idx_t  count) const
inline
9015 {
9016 return CountValid(count) == 0;
9017 }

◆ CheckAllValid() [2/2]

template<typename V >
bool duckdb::TemplatedValidityMask< V >::CheckAllValid ( idx_t  to,
idx_t  from 
) const
inline
9019 {
9020 if (AllValid()) {
9021 return true;
9022 }
9023 for (idx_t i = from; i < to; i++) {
9024 if (!RowIsValid(i)) {
9025 return false;
9026 }
9027 }
9028 return true;
9029 }

◆ CountValid()

template<typename V >
idx_t duckdb::TemplatedValidityMask< V >::CountValid ( const idx_t  count) const
inline
9031 {
9032 if (AllValid() || count == 0) {
9033 return count;
9034 }
9035
9036 idx_t valid = 0;
9037 const auto entry_count = EntryCount(count);
9038 for (idx_t entry_idx = 0; entry_idx < entry_count;) {
9039 auto entry = GetValidityEntry(entry_idx++);
9040 // Handle ragged end (if not exactly multiple of BITS_PER_VALUE)
9041 if (entry_idx == entry_count && count % BITS_PER_VALUE != 0) {
9042 const auto shift = BITS_PER_VALUE - (count % BITS_PER_VALUE);
9043 const auto mask = ValidityBuffer::MAX_ENTRY >> shift;
9044 entry &= mask;
9045 } else if (AllValid(entry)) {
9046 // Handle all set
9047 valid += BITS_PER_VALUE;
9048 continue;
9049 }
9050
9051 // Count partial entry (Kernighan's algorithm)
9052 while (entry) {
9053 entry &= (entry - 1);
9054 ++valid;
9055 }
9056 }
9057
9058 return valid;
9059 }
GMat mask(const GMat &src, const GMat &mask)

◆ GetData()

template<typename V >
V * duckdb::TemplatedValidityMask< V >::GetData ( ) const
inline
9061 {
9062 return validity_mask;
9063 }

◆ Reset()

template<typename V >
void duckdb::TemplatedValidityMask< V >::Reset ( idx_t  target_count_p = STANDARD_VECTOR_SIZE)
inline
9064 {
9065 validity_mask = nullptr;
9066 validity_data.reset();
9067 capacity = target_count_p;
9068 }

◆ EntryCount()

template<typename V >
static idx_t duckdb::TemplatedValidityMask< V >::EntryCount ( idx_t  count)
inlinestatic
9070 {
9071 return ValidityBuffer::EntryCount(count);
9072 }

◆ GetValidityEntry()

template<typename V >
V duckdb::TemplatedValidityMask< V >::GetValidityEntry ( idx_t  entry_idx) const
inline
9073 {
9074 if (!validity_mask) {
9075 return ValidityBuffer::MAX_ENTRY;
9076 }
9077 return GetValidityEntryUnsafe(entry_idx);
9078 }

◆ GetValidityEntryUnsafe()

template<typename V >
V & duckdb::TemplatedValidityMask< V >::GetValidityEntryUnsafe ( idx_t  entry_idx) const
inline
9079 {
9080 return validity_mask[entry_idx];
9081 }

◆ AllValid() [2/2]

template<typename V >
static bool duckdb::TemplatedValidityMask< V >::AllValid ( V  entry)
inlinestatic
9082 {
9083 // Check if all the tuples that are covered by this entry (usually 64) are valid
9084 return entry == ValidityBuffer::MAX_ENTRY;
9085 }

◆ NoneValid()

template<typename V >
static bool duckdb::TemplatedValidityMask< V >::NoneValid ( V  entry)
inlinestatic
9086 {
9087 return entry == 0;
9088 }

◆ RowIsValid() [1/2]

template<typename V >
static bool duckdb::TemplatedValidityMask< V >::RowIsValid ( const V entry,
const idx_t idx_in_entry 
)
inlinestatic
9089 {
9090 return entry & (V(1) << V(idx_in_entry));
9091 }

◆ GetEntryIndex()

template<typename V >
static void duckdb::TemplatedValidityMask< V >::GetEntryIndex ( idx_t  row_idx,
idx_t entry_idx,
idx_t idx_in_entry 
)
inlinestatic
9092 {
9093 entry_idx = row_idx / BITS_PER_VALUE;
9094 idx_in_entry = row_idx % BITS_PER_VALUE;
9095 }

◆ EntryWithValidBits()

template<typename V >
static V duckdb::TemplatedValidityMask< V >::EntryWithValidBits ( idx_t  n)
inlinestatic

Get an entry that has first-n bits set as valid and rest set as invalid.

9097 {
9098 if (n == 0) {
9099 return V(0);
9100 }
9101 return ValidityBuffer::MAX_ENTRY >> (BITS_PER_VALUE - n);
9102 }

◆ SizeInBytes()

template<typename V >
static idx_t duckdb::TemplatedValidityMask< V >::SizeInBytes ( idx_t  n)
inlinestatic
9103 {
9104 return (n + BITS_PER_VALUE - 1) / BITS_PER_VALUE;
9105 }

◆ RowIsValidUnsafe()

template<typename V >
bool duckdb::TemplatedValidityMask< V >::RowIsValidUnsafe ( idx_t  row_idx) const
inline

RowIsValidUnsafe should only be used if AllValid() is false: it achieves the same as RowIsValid but skips a not-null check

9109 {
9110 D_ASSERT(validity_mask);
9111 idx_t entry_idx, idx_in_entry;
9112 GetEntryIndex(row_idx, entry_idx, idx_in_entry);
9113 auto entry = GetValidityEntryUnsafe(entry_idx);
9114 return RowIsValid(entry, idx_in_entry);
9115 }
Here is the caller graph for this function:

◆ RowIsValid() [2/2]

template<typename V >
bool duckdb::TemplatedValidityMask< V >::RowIsValid ( idx_t  row_idx) const
inline

Returns true if a row is valid (i.e. not null), false otherwise.

9118 {
9119#ifdef DEBUG
9120 if (row_idx >= capacity) {
9121 throw InternalException("ValidityMask::RowIsValid - row_idx %d is out-of-range for mask with capacity %llu",
9122 row_idx, capacity);
9123 }
9124#endif
9125 if (!validity_mask) {
9126 return true;
9127 }
9128 return RowIsValidUnsafe(row_idx);
9129 }
bool RowIsValidUnsafe(idx_t row_idx) const
Definition duckdb.hpp:9109
Here is the call graph for this function:

◆ SetValidUnsafe()

template<typename V >
void duckdb::TemplatedValidityMask< V >::SetValidUnsafe ( idx_t  row_idx)
inline

Same as SetValid, but skips a null check on validity_mask.

9132 {
9133 D_ASSERT(validity_mask);
9134 idx_t entry_idx, idx_in_entry;
9135 GetEntryIndex(row_idx, entry_idx, idx_in_entry);
9136 validity_mask[entry_idx] |= (V(1) << V(idx_in_entry));
9137 }
Here is the caller graph for this function:

◆ SetValid()

template<typename V >
void duckdb::TemplatedValidityMask< V >::SetValid ( idx_t  row_idx)
inline

Marks the entry at the specified row index as valid (i.e. not-null)

9140 {
9141#ifdef DEBUG
9142 if (row_idx >= capacity) {
9143 throw InternalException("ValidityMask::SetValid - row_idx %d is out-of-range for mask with capacity %llu",
9144 row_idx, capacity);
9145 }
9146#endif
9147 if (!validity_mask) {
9148 // if AllValid() we don't need to do anything
9149 // the row is already valid
9150 return;
9151 }
9152 SetValidUnsafe(row_idx);
9153 }
void SetValidUnsafe(idx_t row_idx)
Same as SetValid, but skips a null check on validity_mask.
Definition duckdb.hpp:9132
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetInvalidUnsafe() [1/2]

template<typename V >
void duckdb::TemplatedValidityMask< V >::SetInvalidUnsafe ( idx_t  entry_idx,
idx_t  idx_in_entry 
)
inline

Marks the bit at the specified entry as invalid (i.e. null)

9156 {
9157 D_ASSERT(validity_mask);
9158 validity_mask[entry_idx] &= ~(V(1) << V(idx_in_entry));
9159 }
Here is the caller graph for this function:

◆ SetInvalidUnsafe() [2/2]

template<typename V >
void duckdb::TemplatedValidityMask< V >::SetInvalidUnsafe ( idx_t  row_idx)
inline

Marks the bit at the specified row index as invalid (i.e. null)

9162 {
9163 idx_t entry_idx, idx_in_entry;
9164 GetEntryIndex(row_idx, entry_idx, idx_in_entry);
9165 SetInvalidUnsafe(entry_idx, idx_in_entry);
9166 }
void SetInvalidUnsafe(idx_t entry_idx, idx_t idx_in_entry)
Marks the bit at the specified entry as invalid (i.e. null)
Definition duckdb.hpp:9156
Here is the call graph for this function:

◆ SetInvalid()

template<typename V >
void duckdb::TemplatedValidityMask< V >::SetInvalid ( idx_t  row_idx)
inline

Marks the entry at the specified row index as invalid (i.e. null)

9169 {
9170#ifdef DEBUG
9171 if (row_idx >= capacity) {
9172 throw InternalException("ValidityMask::SetInvalid - row_idx %d is out-of-range for mask with capacity %llu",
9173 row_idx, capacity);
9174 }
9175#endif
9176 if (!validity_mask) {
9177 Initialize(capacity);
9178 }
9179 SetInvalidUnsafe(row_idx);
9180 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Set()

template<typename V >
void duckdb::TemplatedValidityMask< V >::Set ( idx_t  row_idx,
bool  valid 
)
inline

Mark the entry at the specified index as either valid or invalid (non-null or null)

9183 {
9184 if (valid) {
9185 SetValid(row_idx);
9186 } else {
9187 SetInvalid(row_idx);
9188 }
9189 }
void SetValid(idx_t row_idx)
Marks the entry at the specified row index as valid (i.e. not-null)
Definition duckdb.hpp:9140
void SetInvalid(idx_t row_idx)
Marks the entry at the specified row index as invalid (i.e. null)
Definition duckdb.hpp:9169
Here is the call graph for this function:

◆ EnsureWritable()

template<typename V >
void duckdb::TemplatedValidityMask< V >::EnsureWritable ( )
inline

Ensure the validity mask is writable, allocating space if it is not initialized.

9192 {
9193 if (!validity_mask) {
9194 Initialize();
9195 }
9196 }
Here is the caller graph for this function:

◆ SetRangeInvalid()

template<typename V >
void duckdb::TemplatedValidityMask< V >::SetRangeInvalid ( const idx_t  count,
const idx_t  begin_entry,
const idx_t  end_entry 
)
inline

Marks a range of entries in the validity mask as invalid (null) This is useful for initialising large masks in parallel.

9200 {
9202 if (count == 0) {
9203 return;
9204 }
9205 const auto last_entry_index = ValidityBuffer::EntryCount(count) - 1;
9206 for (idx_t i = begin_entry; i < MinValue(last_entry_index, end_entry); i++) {
9207 validity_mask[i] = 0;
9208 }
9209 if (end_entry <= last_entry_index) {
9210 return;
9211 }
9212 const auto last_entry_bits = count % BITS_PER_VALUE;
9213 validity_mask[last_entry_index] =
9214 (last_entry_bits == 0) ? 0 : static_cast<V>(ValidityBuffer::MAX_ENTRY << (last_entry_bits));
9215 }
void EnsureWritable()
Ensure the validity mask is writable, allocating space if it is not initialized.
Definition duckdb.hpp:9192
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetAllInvalid()

template<typename V >
void duckdb::TemplatedValidityMask< V >::SetAllInvalid ( idx_t  count)
inline

Marks exactly "count" bits in the validity mask as invalid (null)

9218 {
9219 SetRangeInvalid(count, 0, EntryCount(count));
9220 }
void SetRangeInvalid(const idx_t count, const idx_t begin_entry, const idx_t end_entry)
Definition duckdb.hpp:9200
Here is the call graph for this function:

◆ SetAllValid()

template<typename V >
void duckdb::TemplatedValidityMask< V >::SetAllValid ( idx_t  count)
inline

Marks exactly "count" bits in the validity mask as valid (not null)

9223 {
9225 if (count == 0) {
9226 return;
9227 }
9228 auto last_entry_index = ValidityBuffer::EntryCount(count) - 1;
9229 for (idx_t i = 0; i < last_entry_index; i++) {
9230 validity_mask[i] = ValidityBuffer::MAX_ENTRY;
9231 }
9232 auto last_entry_bits = count % BITS_PER_VALUE;
9233 validity_mask[last_entry_index] |= (last_entry_bits == 0)
9234 ? ValidityBuffer::MAX_ENTRY
9235 : ~static_cast<V>(ValidityBuffer::MAX_ENTRY << (last_entry_bits));
9236 }
Here is the call graph for this function:

◆ IsMaskSet()

template<typename V >
bool duckdb::TemplatedValidityMask< V >::IsMaskSet ( ) const
inline
9238 {
9239 if (validity_mask) {
9240 return true;
9241 }
9242 return false;
9243 }

◆ Initialize() [1/4]

template<typename V >
void duckdb::TemplatedValidityMask< V >::Initialize ( validity_t *  validity,
idx_t  new_capacity 
)
inline
9246 {
9247 validity_data.reset();
9248 validity_mask = validity;
9249 capacity = new_capacity;
9250 }

◆ Initialize() [2/4]

template<typename V >
void duckdb::TemplatedValidityMask< V >::Initialize ( const TemplatedValidityMask< V > &  other)
inline
9251 {
9252 validity_mask = other.validity_mask;
9253 validity_data = other.validity_data;
9254 capacity = other.capacity;
9255 }

◆ Initialize() [3/4]

template<typename V >
void duckdb::TemplatedValidityMask< V >::Initialize ( idx_t  count)
inline
9256 {
9257 capacity = count;
9258 validity_data = make_buffer<ValidityBuffer>(count);
9259 validity_mask = validity_data->owned_data.get();
9260 }

◆ Initialize() [4/4]

template<typename V >
void duckdb::TemplatedValidityMask< V >::Initialize ( )
inline
9261 {
9262 Initialize(capacity);
9263 }

◆ Copy()

template<typename V >
void duckdb::TemplatedValidityMask< V >::Copy ( const TemplatedValidityMask< V > &  other,
idx_t  count 
)
inline
9264 {
9265 capacity = count;
9266 if (other.AllValid()) {
9267 validity_data = nullptr;
9268 validity_mask = nullptr;
9269 } else {
9270 validity_data = make_buffer<ValidityBuffer>(other.validity_mask, count);
9271 validity_mask = validity_data->owned_data.get();
9272 }
9273 }

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