| 1 | //===----------------------------------------------------------------------===// |
| 2 | // DuckDB |
| 3 | // |
| 4 | // duckdb/execution/index/art/swizzleable_pointer.hpp |
| 5 | // |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | #pragma once |
| 9 | |
| 10 | #include "duckdb/common/constants.hpp" |
| 11 | |
| 12 | namespace duckdb { |
| 13 | |
| 14 | // classes |
| 15 | class MetaBlockReader; |
| 16 | |
| 17 | // structs |
| 18 | struct BlockPointer; |
| 19 | |
| 20 | //! SwizzleablePointer provides functions on a (possibly) swizzled pointer. If the swizzle flag is set, then the |
| 21 | //! pointer points to a storage address (and has no type), otherwise the pointer has a type and stores |
| 22 | //! other information (e.g., a buffer location) |
| 23 | class SwizzleablePointer { |
| 24 | public: |
| 25 | //! Constructs an empty SwizzleablePointer |
| 26 | SwizzleablePointer() : swizzle_flag(0), type(0), offset(0), buffer_id(0) {}; |
| 27 | //! Constructs a swizzled pointer from a buffer ID and an offset |
| 28 | explicit SwizzleablePointer(MetaBlockReader &reader); |
| 29 | //! Constructs a non-swizzled pointer from a buffer ID and an offset |
| 30 | SwizzleablePointer(uint32_t offset, uint32_t buffer_id) |
| 31 | : swizzle_flag(0), type(0), offset(offset), buffer_id(buffer_id) {}; |
| 32 | |
| 33 | //! The swizzle flag, set if swizzled, not set otherwise |
| 34 | uint8_t swizzle_flag : 1; |
| 35 | //! The type of the pointer, zero if not set |
| 36 | uint8_t type : 7; |
| 37 | //! The offset of a memory location |
| 38 | uint32_t offset : 24; |
| 39 | //! The buffer ID of a memory location |
| 40 | uint32_t buffer_id : 32; |
| 41 | |
| 42 | public: |
| 43 | //! Checks if the pointer is swizzled |
| 44 | inline bool IsSwizzled() const { |
| 45 | return swizzle_flag; |
| 46 | } |
| 47 | //! Returns true, if neither the swizzle flag nor the type is set, and false otherwise |
| 48 | inline bool IsSet() const { |
| 49 | return swizzle_flag || type; |
| 50 | } |
| 51 | //! Reset the pointer |
| 52 | inline void Reset() { |
| 53 | swizzle_flag = 0; |
| 54 | type = 0; |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | } // namespace duckdb |
| 59 | |