From 9dec0b9b9588b74697cb3643ca603db849e96bcb Mon Sep 17 00:00:00 2001 From: Rossi Sun Date: Fri, 27 Dec 2024 02:26:02 +0800 Subject: [PATCH] More refinement --- cpp/src/arrow/compute/key_map_internal.cc | 8 ++++---- cpp/src/arrow/compute/key_map_internal.h | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cpp/src/arrow/compute/key_map_internal.cc b/cpp/src/arrow/compute/key_map_internal.cc index 7b34cc3472df4..fbde367e30250 100644 --- a/cpp/src/arrow/compute/key_map_internal.cc +++ b/cpp/src/arrow/compute/key_map_internal.cc @@ -158,9 +158,9 @@ void SwissTable::init_slot_ids(const int num_keys, const uint16_t* selection, for (int i = 0; i < num_keys; ++i) { uint16_t id = selection[i]; uint32_t hash = hashes[id]; + uint32_t iblock = hash >> (bits_hash_ - log_blocks_); uint32_t match = ::arrow::bit_util::GetBit(match_bitvector, id) ? 1 : 0; - uint32_t block_id = hash >> (bits_hash_ - log_blocks_); - uint32_t slot_id = block_id * 8u + local_slots[id] + match; + uint32_t slot_id = iblock * 8u + local_slots[id] + match; out_slot_ids[id] = slot_id; } } @@ -186,8 +186,8 @@ void SwissTable::init_slot_ids_for_new_keys(uint32_t num_ids, const uint16_t* id uint32_t iblock = hash >> (bits_hash_ - log_blocks_); uint64_t block; for (;;) { - int64_t pos = num_block_bytes * iblock; - block = *reinterpret_cast(blocks_->mutable_data() + pos); + block = *reinterpret_cast(blocks_->mutable_data() + + num_block_bytes * iblock); block &= kHighBitOfEachByte; if (block) { break; diff --git a/cpp/src/arrow/compute/key_map_internal.h b/cpp/src/arrow/compute/key_map_internal.h index f4ad01381643d..c507a8ba8cb2b 100644 --- a/cpp/src/arrow/compute/key_map_internal.h +++ b/cpp/src/arrow/compute/key_map_internal.h @@ -266,15 +266,14 @@ uint64_t SwissTable::extract_group_id(const uint8_t* block_ptr, int slot, void SwissTable::insert_into_empty_slot(uint32_t slot_id, uint32_t hash, uint32_t group_id) { - const uint64_t num_groupid_bits = num_groupid_bits_from_log_blocks(log_blocks_); + const int64_t num_groupid_bits = num_groupid_bits_from_log_blocks(log_blocks_); // We assume here that the number of bits is rounded up to 8, 16, 32 or 64. // In that case we can insert group id value using aligned 64-bit word access. assert(num_groupid_bits == 8 || num_groupid_bits == 16 || num_groupid_bits == 32 || num_groupid_bits == 64); - const uint64_t num_block_bytes = - num_block_bytes_from_num_groupid_bits(num_groupid_bits); + const int64_t num_block_bytes = num_block_bytes_from_num_groupid_bits(num_groupid_bits); constexpr uint64_t stamp_mask = 0x7f; int start_slot = (slot_id & 7);