risingwave_hummock_sdk/filter_utils.rs
1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use risingwave_common::config::meta::default::compaction_config;
16
17/// Determines whether the key count is large enough to warrant using a block-based filter.
18///
19/// # Arguments
20/// * `kv_count` - The total number of keys
21/// * `max_kv_count` - Optional configured threshold. If None, uses `DEFAULT_MAX_KV_COUNT_FOR_XOR16`
22///
23/// # Returns
24/// `true` if `kv_count` exceeds the threshold, indicating block-based filter should be used
25pub fn is_kv_count_too_large_for_xor16(kv_count: u64, max_kv_count: Option<u64>) -> bool {
26 let threshold = max_kv_count.unwrap_or(compaction_config::DEFAULT_MAX_KV_COUNT_FOR_XOR16);
27 kv_count > threshold
28}