From 236101bbbeb74fa8be9267996a9d0c1a225e9f98 Mon Sep 17 00:00:00 2001 From: Zhaoyan Sun <53212907+Curtis001@users.noreply.github.com> Date: Fri, 17 Jun 2022 18:06:17 +0800 Subject: [PATCH] Update builder.h 1. In function "Finalize", if range and num_bins_ are both power of 2, shift_ shoule plus 1 to adapt to num_bins. 2. In function "TransformIntoRadixTable", tree_.front().second[max_prefix+1] is not assigned. --- include/ts/ts_cht/builder.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/ts/ts_cht/builder.h b/include/ts/ts_cht/builder.h index 2f54542..8f97fae 100644 --- a/include/ts/ts_cht/builder.h +++ b/include/ts/ts_cht/builder.h @@ -43,11 +43,12 @@ class Builder { log_num_bins_ = ComputeLog(static_cast(num_bins_)); // Compute the logarithm in base 2 of the range. - auto lg = ComputeLog(max_key_ - min_key_, true); + const KeyType range = max_key_ - min_key_; + auto lg = ComputeLog(range, true); // And also the initial shift for the first node of the tree. assert(lg >= log_num_bins_); - shift_ = lg - log_num_bins_; + shift_ = lg - log_num_bins_ + ((range & (range - 1)) == 0 && (num_bins_ & (num_bins_ - 1)) == 0); // And build. // TODO: build faster (use trick with lcp)! @@ -341,9 +342,9 @@ class Builder { num_radix_bits_ = log_num_bins_; num_shift_bits_ = GetNumShiftBits(max_key_ - min_key_, num_radix_bits_); const uint32_t max_prefix = (max_key_ - min_key_) >> num_shift_bits_; - table_.resize(max_prefix + 2, 0); - for (size_t index = 0, limit = std::min(num_bins_, table_.size()); index != limit; ++index) + for (size_t index = 0, limit = max_prefix + 1; index != limit; ++index) table_[index] = (tree_.front().second[index].first & Mask); + table_[max_prefix + 1] = tree_.front().second[max_prefix].second; table_.back() = curr_num_keys_; shift_ = num_shift_bits_; }