@@ -1545,11 +1545,24 @@ HashTable::entry_t OpenAddressingHashTable<IsGlobal, ValueInPlace>::emplace(std:
1545
1545
update_high_watermark ();
1546
1546
};
1547
1547
1548
- return emplace_without_rehashing (std::move (key));
1548
+ auto slot = emplace_without_rehashing (std::move (key));
1549
+
1550
+ if constexpr (ValueInPlace) {
1551
+ /* ----- Return entry handle containing all values. -----*/
1552
+ return value_entry (slot);
1553
+ } else {
1554
+ /* ----- Allocate memory for out-of-place values and set pointer to it. -----*/
1555
+ Ptr<void > ptr =
1556
+ Module::Allocator ().allocate (layout_.values_size_in_bytes_ , layout_.values_max_alignment_in_bytes_ );
1557
+ *(slot + layout_.ptr_offset_in_bytes_ ).template to <uint32_t *>() = ptr.clone ().to <uint32_t >();
1558
+
1559
+ /* ----- Return entry handle containing all values. -----*/
1560
+ return value_entry (ptr);
1561
+ }
1549
1562
}
1550
1563
1551
1564
template <bool IsGlobal, bool ValueInPlace>
1552
- HashTable:: entry_t OpenAddressingHashTable<IsGlobal, ValueInPlace>::emplace_without_rehashing(std::vector<SQL_t> key)
1565
+ Ptr< void > OpenAddressingHashTable<IsGlobal, ValueInPlace>::emplace_without_rehashing(std::vector<SQL_t> key)
1553
1566
{
1554
1567
M_insist (bool (num_entries_), " must call `setup()` before" );
1555
1568
M_insist (bool (high_watermark_absolute_), " must call `setup()` before" );
@@ -1600,25 +1613,7 @@ HashTable::entry_t OpenAddressingHashTable<IsGlobal, ValueInPlace>::emplace_with
1600
1613
/* ----- Insert key. -----*/
1601
1614
insert_key (slot, std::move (key)); // move key at last use
1602
1615
1603
- if constexpr (ValueInPlace) {
1604
- /* ----- Return entry handle containing all values. -----*/
1605
- return value_entry (slot);
1606
- } else {
1607
- /* ----- Allocate memory for out-of-place values and set pointer to it. -----*/
1608
- Ptr<void > ptr =
1609
- Module::Allocator ().allocate (layout_.values_size_in_bytes_ , layout_.values_max_alignment_in_bytes_ );
1610
- *(slot + layout_.ptr_offset_in_bytes_ ).template to <uint32_t *>() = ptr.clone ().to <uint32_t >();
1611
-
1612
- if (pred) {
1613
- /* ----- Store address and size of dummy predication entry to free them later. -----*/
1614
- var_t <Ptr<void >> ptr_; // create global variable iff `IsGlobal` to be able to access it later for deallocation
1615
- ptr_ = ptr.clone ();
1616
- dummy_allocations_.emplace_back (ptr_, layout_.values_size_in_bytes_ );
1617
- }
1618
-
1619
- /* ----- Return entry handle containing all values. -----*/
1620
- return value_entry (ptr);
1621
- }
1616
+ return slot;
1622
1617
}
1623
1618
1624
1619
template <bool IsGlobal, bool ValueInPlace>
@@ -2173,18 +2168,27 @@ void OpenAddressingHashTable<IsGlobal, ValueInPlace>::rehash()
2173
2168
}
2174
2169
2175
2170
/* ----- Insert key into new hash table. No rehashing needed since the new hash table is large enough. */
2176
- auto e_new = emplace_without_rehashing (std::move (key));
2177
-
2178
- /* ----- Insert values from old entry into new one. -----*/
2179
- for (auto v : value_indices_) {
2180
- auto id = schema_.get ()[v].id ;
2181
- std::visit (overloaded {
2182
- [&]<sql_type T>(reference_t <T> &&r) -> void { r = e_old.template extract <T>(id); },
2183
- [](std::monostate) -> void { M_unreachable (" invalid reference" ); },
2184
- }, e_new.extract (id));
2171
+ auto slot = emplace_without_rehashing (std::move (key));
2172
+
2173
+ if constexpr (ValueInPlace) {
2174
+ /* ----- Get entry handle containing all values of new entry. -----*/
2175
+ auto e_new = value_entry (slot);
2176
+
2177
+ /* ----- Insert values from old entry into new one. -----*/
2178
+ for (auto v : value_indices_) {
2179
+ auto id = schema_.get ()[v].id ;
2180
+ std::visit (overloaded {
2181
+ [&]<sql_type T>(reference_t <T> &&r) -> void { r = e_old.template extract <T>(id); },
2182
+ [](std::monostate) -> void { M_unreachable (" invalid reference" ); },
2183
+ }, e_new.extract (id));
2184
+ }
2185
+ M_insist (e_old.empty ());
2186
+ M_insist (e_new.empty ());
2187
+ } else {
2188
+ /* ----- Set pointer to out-of-place values of new entry to the one of old entry. -----*/
2189
+ *(slot + layout_.ptr_offset_in_bytes_ ).template to <uint32_t *>() =
2190
+ *(it + layout_.ptr_offset_in_bytes_ ).template to <uint32_t *>();
2185
2191
}
2186
- M_insist (e_old.empty ());
2187
- M_insist (e_new.empty ());
2188
2192
};
2189
2193
2190
2194
/* ----- Advance to next entry in old hash table. -----*/
0 commit comments