| 770 | } |
| 771 | |
| 772 | Status SwissTable::init(int64_t hardware_flags, MemoryPool* pool, int log_blocks, |
| 773 | bool no_hash_array) { |
| 774 | hardware_flags_ = hardware_flags; |
| 775 | pool_ = pool; |
| 776 | log_minibatch_ = util::MiniBatch::kLogMiniBatchLength; |
| 777 | |
| 778 | log_blocks_ = log_blocks; |
| 779 | bits_shift_for_block_and_stamp_ = ComputeBitsShiftForBlockAndStamp(log_blocks_); |
| 780 | bits_shift_for_block_ = ComputeBitsShiftForBlock(log_blocks_); |
| 781 | int num_groupid_bits = num_groupid_bits_from_log_blocks(log_blocks_); |
| 782 | num_inserted_ = 0; |
| 783 | |
| 784 | const int block_bytes = num_block_bytes_from_num_groupid_bits(num_groupid_bits); |
| 785 | const int64_t slot_bytes = num_bytes_total_blocks(block_bytes, log_blocks_); |
| 786 | ARROW_ASSIGN_OR_RAISE(blocks_, AllocateBuffer(slot_bytes, pool_)); |
| 787 | |
| 788 | // Make sure group ids are initially set to zero for all slots. |
| 789 | memset(blocks_->mutable_data(), 0, slot_bytes); |
| 790 | |
| 791 | // Initialize all status bytes to represent an empty slot. |
| 792 | for (int i = 0; i < 1 << log_blocks_; ++i) { |
| 793 | auto block = mutable_block_data(i, block_bytes); |
| 794 | util::SafeStore(block, kHighBitOfEachByte); |
| 795 | } |
| 796 | |
| 797 | if (no_hash_array) { |
| 798 | hashes_ = nullptr; |
| 799 | } else { |
| 800 | int64_t num_slots = num_slots_from_log_blocks(log_blocks); |
| 801 | const int hash_size = bits_hash_ >> 3; |
| 802 | const int64_t hash_bytes = hash_size * num_slots + padding_; |
| 803 | ARROW_ASSIGN_OR_RAISE(hashes_, AllocateBuffer(hash_bytes, pool_)); |
| 804 | } |
| 805 | |
| 806 | return Status::OK(); |
| 807 | } |
| 808 | |
| 809 | void SwissTable::cleanup() { |
| 810 | if (blocks_) { |
no test coverage detected