1 #ifndef INDEX_INDEXKEY_H
2 #define INDEX_INDEXKEY_H
42 template<
class SomeDatum>
44 Create(
const std::vector<SomeDatum> &data) {
45 if (data.size() > (
size_t) std::numeric_limits<FieldId>::max()) {
46 LOG(
kFatal,
"too many fields in a key: %lu", data.size());
50 void *new_key = aligned_alloc(8, sz);
55 template<
class SomeDatum>
59 void *new_key = aligned_alloc(8, sz);
74 template<
class SomeDatum>
76 Construct(
void *key,
const std::vector<SomeDatum> &data) {
77 if (data.size() > (
size_t) std::numeric_limits<FieldId>::max()) {
78 LOG(
kFatal,
"too many fields in a key: %lu", data.size());
85 template<
class SomeDatum>
100 void *new_key = aligned_alloc(8, sz);
131 ASSERT(nkeys <= sch->GetNumFields());
132 for (
FieldId i = 0; i < nkeys; ++i) {
135 if (data_buffer.size() == data_buffer.capacity() &&
136 !data_buffer.empty()) {
137 LOG(
kFatal,
"causing the data buffer to increase capacity "
138 "and this will make previously deep copied "
139 "IndexKey contain dangling pointers (need to "
140 "reserve space on the vector first!).");
142 data_buffer.emplace_back(old_datum.
DeepCopy());
143 GetKey(i) = data_buffer.back();
153 return *
reinterpret_cast<const FieldId*
>(
this);
177 template<
class SomeDatum>
200 return !!(((uint8_t*) &
m_data)[2 + (keyid >> 3)] & (1 << (keyid & 7)));
210 ((uint8_t*) &
m_data)[2 + (keyid >> 3)] |= (1 << (keyid & 7));
212 ((uint8_t*) &
m_data)[2 + (keyid >> 3)] &=
213 ~(uint8_t)(1 << (keyid & 7));
221 uint8_t *bm = ((uint8_t *) &
m_data) + 2;
223 for (
size_t i = 0; i < n; ++i) {
265 std::vector<NullableDatumRef>
267 std::vector<NullableDatumRef> vec;
281 template<
class SomeDatum>
286 uint8_t *bm = ((uint8_t *) key ) + 2;
289 memset(bm, 0, ((nkeys + 7) >> 3));
290 for (
FieldId i = 0; i < nkeys; ++i) {
291 if (data[i].isnull()) {
292 bm[i >> 3] |= 1 << (i & 7);
A DatumRef object is a read-only reference to an C++ object of a supported runtime type.
Definition: datum.h:823
A Datum stores and possibly manage the memory resource of a read-only value of a plain fixed-length C...
Definition: datum.h:250
static Datum FromNull()
Definition: datum.h:343
Datum DeepCopy() const
Returns a deep copy of this datum so that HasExternalRef() == false and the owned value is a copy of ...
Definition: datum.h:621
A Schema object stores the information for accessing an ordered set of typed fields either from a dis...
Definition: Schema.h:39
bool FieldPassByRef(FieldId field_id) const
Returns whether this field is passed by reference or by value in memory.
Definition: Schema.h:262
constexpr Datum & GetDatum() const
Returns a reference to the underlying datum if this references one with a variable-length value.
Definition: datum.h:777
#define LOG(level,...)
LOG(LogSeverity level, const char *fmt, ...)
Definition: logging.h:116
constexpr LogSeverity kFatal
Definition: logging.h:22
int16_t FieldId
Definition: tdb_base.h:212
std::unique_ptr< IndexKey, AlignedAllocImpl::FreeMem > UniqueIndexKey
The returned smart pointer of IndexKey::Create().
Definition: IndexKey.h:10
An IndexKey stores references to a few data (Datum objects) that comprise a key tuple to in an index.
Definition: IndexKey.h:35
static void Construct(void *key, const std::vector< SomeDatum > &data)
Constructs a new IndexKey that references the data on a preallocated key.
Definition: IndexKey.h:76
static void Construct(void *key, SomeDatum *data, FieldId nkeys)
Definition: IndexKey.h:87
static size_t ComputeStructSize(FieldId nkeys)
Computes the minimum size of an byte array to store this IndexKey that holds nkeys.
Definition: IndexKey.h:246
DatumRef & GetKey(FieldId keyid) const
Returns the key keyid.
Definition: IndexKey.h:164
void DeepCopy(const Schema *sch, std::vector< Datum > &data_buffer)
Makes a deep copy of all the variable-length Datum the key is refernecing in a newly allocated memory...
Definition: IndexKey.h:129
uint64_t m_data[1]
Definition: IndexKey.h:300
void CopyTo(IndexKey *key2) const
Makes a copy of the index key to an existing index key.
Definition: IndexKey.h:114
size_t GetStructSize() const
Returns the minimum size of the byte array to store this IndexKey.
Definition: IndexKey.h:237
IndexKey & operator=(IndexKey &&)=delete
bool HasAnyNull() const
Returns if any of the keys is null.
Definition: IndexKey.h:220
std::vector< NullableDatumRef > ToNullableDatumVector() const
Returns the IndexKey as an std::vector<NullableDatumRef>.
Definition: IndexKey.h:266
void SetKey(FieldId keyid, const SomeDatum &key)
Sets the keyid-th field in this index key.
Definition: IndexKey.h:179
static UniqueIndexKey Create(const std::vector< SomeDatum > &data)
Allocates and constructs a new IndexKey that references the data.
Definition: IndexKey.h:44
void SetNullBit(FieldId keyid, bool isnull) const
Sets or clears the null bit for the key \keyid.
Definition: IndexKey.h:208
FieldId GetNumKeys() const
Returns the number of keys in this IndexKey.
Definition: IndexKey.h:152
IndexKey(IndexKey &&)=delete
NullableDatumRef GetNullableKey(FieldId keyid) const
Returns the key \keyid as a NullableDatumRef.
Definition: IndexKey.h:255
UniqueIndexKey Copy() const
Makes a copy of the index key in a newly allocated buffer.
Definition: IndexKey.h:98
bool IsNull(FieldId keyid) const
Returns the key keyid is null.
Definition: IndexKey.h:196
IndexKey(const IndexKey &)=delete
static UniqueIndexKey Create(SomeDatum *data, FieldId nkeys)
Definition: IndexKey.h:57
static void ConstructImpl(void *key, SomeDatum *data, FieldId nkeys, size_t sz)
Definition: IndexKey.h:283
IndexKey & operator=(const IndexKey &)=delete
#define MAXALIGN(LEN)
Definition: tdb_base.h:327
#define ASSERT(...)
Definition: tdb_base.h:190