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::ValidityMask Struct Reference
Inheritance diagram for duckdb::ValidityMask:
Collaboration diagram for duckdb::ValidityMask:

Public Member Functions

 ValidityMask (idx_t capacity)
 ValidityMask (validity_t *ptr, idx_t capacity)
 ValidityMask (const ValidityMask &original, idx_t count)
DUCKDB_API void Resize (idx_t new_size)
DUCKDB_API idx_t Capacity () const
DUCKDB_API void SliceInPlace (const ValidityMask &other, idx_t target_offset, idx_t source_offset, idx_t count)
DUCKDB_API void Slice (const ValidityMask &other, idx_t source_offset, idx_t count)
DUCKDB_API void CopySel (const ValidityMask &other, const SelectionVector &sel, idx_t source_offset, idx_t target_offset, idx_t count)
DUCKDB_API void Combine (const ValidityMask &other, idx_t count)
DUCKDB_API string ToString (idx_t count) const
DUCKDB_API string ToString () const
void Write (WriteStream &writer, idx_t count)
void Read (ReadStream &reader, idx_t count)
Public Member Functions inherited from duckdb::TemplatedValidityMask< validity_t >
bool AllValid () const
bool CheckAllValid (idx_t count) const
bool CheckAllInvalid (idx_t count) const
idx_t CountValid (const idx_t count) const
validity_t * GetData () const
void Reset (idx_t target_count_p=STANDARD_VECTOR_SIZE)
validity_t GetValidityEntry (idx_t entry_idx) const
validity_t & GetValidityEntryUnsafe (idx_t entry_idx) const
bool RowIsValidUnsafe (idx_t row_idx) const
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 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 Copy (const TemplatedValidityMask &other, idx_t count)

Static Public Member Functions

static DUCKDB_API bool IsAligned (idx_t count)
Static Public Member Functions inherited from duckdb::TemplatedValidityMask< validity_t >
static idx_t ValidityMaskSize (idx_t count=STANDARD_VECTOR_SIZE)
static idx_t EntryCount (idx_t count)
static bool NoneValid (validity_t entry)
static bool RowIsValid (const validity_t &entry, const idx_t &idx_in_entry)
static void GetEntryIndex (idx_t row_idx, idx_t &entry_idx, idx_t &idx_in_entry)
static validity_t 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)

Additional Inherited Members

Public Types inherited from duckdb::TemplatedValidityMask< validity_t >
using ValidityBuffer
Static Public Attributes inherited from duckdb::TemplatedValidityMask< validity_t >
static constexpr const idx_t BITS_PER_VALUE
static constexpr const idx_t STANDARD_ENTRY_COUNT
static constexpr const idx_t STANDARD_MASK_SIZE
Protected Attributes inherited from duckdb::TemplatedValidityMask< validity_t >
validity_t * validity_mask
buffer_ptr< ValidityBuffer > validity_data
idx_t capacity

Constructor & Destructor Documentation

◆ ValidityMask() [1/4]

duckdb::ValidityMask::ValidityMask ( )
inline
9283 : TemplatedValidityMask(nullptr, STANDARD_VECTOR_SIZE) {
9284 }

◆ ValidityMask() [2/4]

duckdb::ValidityMask::ValidityMask ( idx_t capacity)
inlineexplicit
9285 : TemplatedValidityMask(capacity) {
9286 }

◆ ValidityMask() [3/4]

duckdb::ValidityMask::ValidityMask ( validity_t * ptr,
idx_t capacity )
inlineexplicit
9287 : TemplatedValidityMask(ptr, capacity) {
9288 }

◆ ValidityMask() [4/4]

duckdb::ValidityMask::ValidityMask ( const ValidityMask & original,
idx_t count )
inline
9289 : TemplatedValidityMask(original, count) {
9290 }

Member Function Documentation

◆ Resize()

void duckdb::ValidityMask::Resize ( idx_t new_size)
131185 {
131186 idx_t old_size = capacity;
131187 if (new_size <= old_size) {
131188 return;
131189 }
131190 capacity = new_size;
131191 if (validity_mask) {
131192 auto new_size_count = EntryCount(new_size);
131193 auto old_size_count = EntryCount(old_size);
131194 auto new_validity_data = make_buffer<ValidityBuffer>(new_size);
131195 auto new_owned_data = new_validity_data->owned_data.get();
131196 for (idx_t entry_idx = 0; entry_idx < old_size_count; entry_idx++) {
131197 new_owned_data[entry_idx] = validity_mask[entry_idx];
131198 }
131199 for (idx_t entry_idx = old_size_count; entry_idx < new_size_count; entry_idx++) {
131200 new_owned_data[entry_idx] = ValidityData::MAX_ENTRY;
131201 }
131202 validity_data = std::move(new_validity_data);
131203 validity_mask = validity_data->owned_data.get();
131204 }
131205}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ Capacity()

idx_t duckdb::ValidityMask::Capacity ( ) const
131207 {
131208 return capacity;
131209}

◆ SliceInPlace()

void duckdb::ValidityMask::SliceInPlace ( const ValidityMask & other,
idx_t target_offset,
idx_t source_offset,
idx_t count )
131248 {
131249 if (AllValid() && other.AllValid()) {
131250 // Both validity masks are uninitialized, nothing to do
131251 return;
131252 }
131253 EnsureWritable();
131254 const idx_t ragged = count % BITS_PER_VALUE;
131255 const idx_t entire_units = count / BITS_PER_VALUE;
131256 if (IsAligned(source_offset) && IsAligned(target_offset)) {
131257 auto target_validity = GetData();
131258 auto source_validity = other.GetData();
131259 auto source_offset_entries = EntryCount(source_offset);
131260 auto target_offset_entries = EntryCount(target_offset);
131261 if (!source_validity) {
131262 // if source has no validity mask - set all bytes to 1
131263 memset(target_validity + target_offset_entries, 0xFF, sizeof(validity_t) * entire_units);
131264 } else {
131265 memcpy(target_validity + target_offset_entries, source_validity + source_offset_entries,
131266 sizeof(validity_t) * entire_units);
131267 }
131268 if (ragged) {
131269 auto src_entry =
131270 source_validity ? source_validity[source_offset_entries + entire_units] : ValidityBuffer::MAX_ENTRY;
131271 src_entry &= (ValidityBuffer::MAX_ENTRY >> (BITS_PER_VALUE - ragged));
131272
131273 target_validity += target_offset_entries + entire_units;
131274 auto tgt_entry = *target_validity;
131275 tgt_entry &= (ValidityBuffer::MAX_ENTRY << ragged);
131276
131277 *target_validity = tgt_entry | src_entry;
131278 }
131279 return;
131280 } else if (IsAligned(target_offset)) {
131281 // Simple common case where we are shifting into an aligned mask (e.g., 0 in Slice above)
131282 const idx_t tail = source_offset % BITS_PER_VALUE;
131283 const idx_t head = BITS_PER_VALUE - tail;
131284 auto source_validity = other.GetData() + (source_offset / BITS_PER_VALUE);
131285 auto target_validity = this->GetData() + (target_offset / BITS_PER_VALUE);
131286 auto src_entry = *source_validity++;
131287 for (idx_t i = 0; i < entire_units; ++i) {
131288 // Start with head of previous src
131289 validity_t tgt_entry = src_entry >> tail;
131290 src_entry = *source_validity++;
131291 // Add in tail of current src
131292 tgt_entry |= (src_entry << head);
131293 *target_validity++ = tgt_entry;
131294 }
131295 // Finish last ragged entry
131296 if (ragged) {
131297 // Start with head of previous src
131298 validity_t tgt_entry = (src_entry >> tail);
131299 // Add in the tail of the next src, if head was too small
131300 if (head < ragged) {
131301 src_entry = *source_validity++;
131302 tgt_entry |= (src_entry << head);
131303 }
131304 // Mask off the bits that go past the ragged end
131305 tgt_entry &= (ValidityBuffer::MAX_ENTRY >> (BITS_PER_VALUE - ragged));
131306 // Restore the ragged end of the target
131307 tgt_entry |= *target_validity & (ValidityBuffer::MAX_ENTRY << ragged);
131308 *target_validity++ = tgt_entry;
131309 }
131310 return;
131311 }
131312
131313 // FIXME: use bitwise operations here
131314#if 1
131315 for (idx_t i = 0; i < count; i++) {
131316 Set(target_offset + i, other.RowIsValid(source_offset + i));
131317 }
131318#else
131319 // first shift the "whole" units
131320 idx_t entire_units = offset / BITS_PER_VALUE;
131321 idx_t sub_units = offset - entire_units * BITS_PER_VALUE;
131322 if (entire_units > 0) {
131323 idx_t validity_idx;
131324 for (validity_idx = 0; validity_idx + entire_units < STANDARD_ENTRY_COUNT; validity_idx++) {
131325 new_mask.validity_mask[validity_idx] = other.validity_mask[validity_idx + entire_units];
131326 }
131327 }
131328 // now we shift the remaining sub units
131329 // this gets a bit more complicated because we have to shift over the borders of the entries
131330 // e.g. suppose we have 2 entries of length 4 and we left-shift by two
131331 // 0101|1010
131332 // a regular left-shift of both gets us:
131333 // 0100|1000
131334 // we then OR the overflow (right-shifted by BITS_PER_VALUE - offset) together to get the correct result
131335 // 0100|1000 ->
131336 // 0110|1000
131337 if (sub_units > 0) {
131338 idx_t validity_idx;
131339 for (validity_idx = 0; validity_idx + 1 < STANDARD_ENTRY_COUNT; validity_idx++) {
131340 new_mask.validity_mask[validity_idx] =
131341 (other.validity_mask[validity_idx] >> sub_units) |
131342 (other.validity_mask[validity_idx + 1] << (BITS_PER_VALUE - sub_units));
131343 }
131344 new_mask.validity_mask[validity_idx] >>= sub_units;
131345 }
131346#ifdef DEBUG
131347 for (idx_t i = offset; i < STANDARD_VECTOR_SIZE; i++) {
131348 D_ASSERT(new_mask.RowIsValid(i - offset) == other.RowIsValid(i));
131349 }
131350 Initialize(new_mask);
131351#endif
131352#endif
131353}
void Set(idx_t row_idx, bool valid)
Definition duckdb.hpp:9183
void EnsureWritable()
Definition duckdb.hpp:9192

◆ Slice()

void duckdb::ValidityMask::Slice ( const ValidityMask & other,
idx_t source_offset,
idx_t count )
131211 {
131212 if (other.AllValid()) {
131213 validity_mask = nullptr;
131214 validity_data.reset();
131215 return;
131216 }
131217 if (source_offset == 0) {
131218 Initialize(other);
131219 return;
131220 }
131221 ValidityMask new_mask(count);
131222 new_mask.SliceInPlace(other, 0, source_offset, count);
131223 Initialize(new_mask);
131224}

◆ CopySel()

void duckdb::ValidityMask::CopySel ( const ValidityMask & other,
const SelectionVector & sel,
idx_t source_offset,
idx_t target_offset,
idx_t count )
131231 {
131232 if (!other.IsMaskSet() && !IsMaskSet()) {
131233 // no need to copy anything if neither has any null values
131234 return;
131235 }
131236
131237 if (!sel.IsSet() && IsAligned(source_offset) && IsAligned(target_offset)) {
131238 // common case where we are shifting into an aligned mask using a flat vector
131239 SliceInPlace(other, target_offset, source_offset, copy_count);
131240 return;
131241 }
131242 for (idx_t i = 0; i < copy_count; i++) {
131243 auto source_idx = sel.get_index(source_offset + i);
131244 Set(target_offset + i, other.RowIsValid(source_idx));
131245 }
131246}

◆ Combine()

void duckdb::ValidityMask::Combine ( const ValidityMask & other,
idx_t count )
131141 {
131142 if (other.AllValid()) {
131143 // X & 1 = X
131144 return;
131145 }
131146 if (AllValid()) {
131147 // 1 & Y = Y
131148 Initialize(other);
131149 return;
131150 }
131151 if (validity_mask == other.validity_mask) {
131152 // X & X == X
131153 return;
131154 }
131155 // have to merge
131156 // create a new validity mask that contains the combined mask
131157 auto owned_data = std::move(validity_data);
131158 auto data = GetData();
131159 auto other_data = other.GetData();
131160
131161 Initialize(count);
131162 auto result_data = GetData();
131163
131164 auto entry_count = ValidityData::EntryCount(count);
131165 for (idx_t entry_idx = 0; entry_idx < entry_count; entry_idx++) {
131166 result_data[entry_idx] = data[entry_idx] & other_data[entry_idx];
131167 }
131168}

◆ ToString() [1/2]

string duckdb::ValidityMask::ToString ( idx_t count) const
131171 {
131172 string result = "Validity Mask (" + to_string(count) + ") [";
131173 for (idx_t i = 0; i < count; i++) {
131174 result += RowIsValid(i) ? "." : "X";
131175 }
131176 result += "]";
131177 return result;
131178}
std::string to_string(const T &value)
Definition duckdb.cpp:19425

◆ ToString() [2/2]

string duckdb::ValidityMask::ToString ( ) const
131180 {
131181 return ValidityMask::ToString(capacity);
131182}

◆ IsAligned()

bool duckdb::ValidityMask::IsAligned ( idx_t count)
static
131226 {
131227 return count % BITS_PER_VALUE == 0;
131228}

◆ Write()

void duckdb::ValidityMask::Write ( WriteStream & writer,
idx_t count )
131357 {
131358 auto valid_values = CountValid(count);
131359 auto invalid_values = count - valid_values;
131360 auto bitmask_bytes = ValidityMask::ValidityMaskSize(count);
131361 auto need_u32 = count >= NumericLimits<uint16_t>::Maximum();
131362 auto bytes_per_value = need_u32 ? sizeof(uint32_t) : sizeof(uint16_t);
131363 auto valid_value_size = bytes_per_value * valid_values + sizeof(uint32_t);
131364 auto invalid_value_size = bytes_per_value * invalid_values + sizeof(uint32_t);
131365 if (valid_value_size < bitmask_bytes || invalid_value_size < bitmask_bytes) {
131366 auto serialize_valid = valid_value_size < invalid_value_size;
131367 // serialize (in)valid value indexes as [COUNT][V0][V1][...][VN]
131368 auto flag = serialize_valid ? ValiditySerialization::VALID_VALUES : ValiditySerialization::INVALID_VALUES;
131369 writer.Write(flag);
131370 writer.Write<uint32_t>(NumericCast<uint32_t>(MinValue(valid_values, invalid_values)));
131371 for (idx_t i = 0; i < count; i++) {
131372 if (RowIsValid(i) == serialize_valid) {
131373 if (need_u32) {
131374 writer.Write<uint32_t>(UnsafeNumericCast<uint32_t>(i));
131375 } else {
131376 writer.Write<uint16_t>(UnsafeNumericCast<uint16_t>(i));
131377 }
131378 }
131379 }
131380 } else {
131381 // serialize the entire bitmask
131382 writer.Write(ValiditySerialization::BITMASK);
131383 writer.WriteData(const_data_ptr_cast(GetData()), bitmask_bytes);
131384 }
131385}
::uint32_t uint32_t
::uint16_t uint16_t

◆ Read()

void duckdb::ValidityMask::Read ( ReadStream & reader,
idx_t count )
131387 {
131388 Initialize(count);
131389 // deserialize the storage type
131390 auto flag = reader.Read<ValiditySerialization>();
131391 if (flag == ValiditySerialization::BITMASK) {
131392 // deserialize the bitmask
131393 reader.ReadData(data_ptr_cast(GetData()), ValidityMask::ValidityMaskSize(count));
131394 return;
131395 }
131396 auto is_u32 = count >= NumericLimits<uint16_t>::Maximum();
131397 auto is_valid = flag == ValiditySerialization::VALID_VALUES;
131398 auto serialize_count = reader.Read<uint32_t>();
131399 if (is_valid) {
131400 SetAllInvalid(count);
131401 }
131402 for (idx_t i = 0; i < serialize_count; i++) {
131403 idx_t index = is_u32 ? reader.Read<uint32_t>() : reader.Read<uint16_t>();
131404 Set(index, is_valid);
131405 }
131406}
index
void SetAllInvalid(idx_t count)
Definition duckdb.hpp:9218

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