From b48be127fb3617ebe025e60e38129411d5fe6952 Mon Sep 17 00:00:00 2001 From: egolearner Date: Thu, 17 Sep 2026 16:03:52 +0800 Subject: [PATCH 01/10] chore: enable readability-identifier-naming check and fix violations Add a Google-style-based readability-identifier-naming configuration to .clang-tidy with project-specific tweaks: - member functions use snake_case; static/global functions may use snake_case or upper-camel CamelCase - struct/class data members use snake_case, trailing underscore optional - local variables and parameters use snake_case; constants stay loose - fix the broken HeaderFilterRegex so headers are covered Auto-fix all existing naming violations across src/tests/tools and insert missing override specifiers. Generated ANTLR/FTS code and vendored third-party files are exempted via per-directory configs and NOLINT ranges. --- .clang-tidy | 49 +- src/ailego/algorithm/integer_quantizer.cc | 32 +- src/ailego/encoding/json/mod_json.c | 4 + src/ailego/internal/cpu_features.h | 3 + src/ailego/math_batch/cosine_distance_batch.h | 8 +- src/ailego/math_batch/distance_batch.h | 10 +- .../math_batch/euclidean_distance_batch.h | 4 +- .../euclidean_distance_batch_dispatch.cc | 4 +- ...euclidean_distance_batch_impl_fp16_avx2.cc | 4 +- ...clidean_distance_batch_impl_fp16_avx512.cc | 4 +- ...ean_distance_batch_impl_fp16_avx512fp16.cc | 4 +- ...euclidean_distance_batch_impl_fp32_avx2.cc | 4 +- ...clidean_distance_batch_impl_fp32_avx512.cc | 4 +- .../math_batch/inner_product_distance_batch.h | 4 +- .../inner_product_distance_batch_dispatch.cc | 4 +- ...r_product_distance_batch_impl_fp16_avx2.cc | 4 +- ...product_distance_batch_impl_fp16_avx512.cc | 4 +- ...uct_distance_batch_impl_fp16_avx512fp16.cc | 4 +- ...r_product_distance_batch_impl_fp32_avx2.cc | 4 +- ...r_product_distance_batch_impl_int8_avx2.cc | 4 +- ...uct_distance_batch_impl_int8_avx512fp16.cc | 4 +- src/ailego/utility/bitset_helper.h | 4 +- src/ailego/utility/matrix_helper.h | 32 +- src/core/algorithm/cluster/linear_seeker.h | 2 +- .../algorithm/cluster/multi_chunk_cluster.cc | 16 +- .../algorithm/cluster/multi_chunk_cluster.h | 16 +- .../algorithm/cluster/opt_kmeans_cluster.cc | 24 +- .../cluster/stratified_cluster_trainer.h | 19 +- src/core/algorithm/cluster/vector_mean.h | 82 +- src/core/algorithm/diskann/diskann_builder.h | 4 +- .../diskann/diskann_builder_entity.h | 2 +- src/core/algorithm/diskann/diskann_context.h | 2 +- src/core/algorithm/diskann/diskann_holder.h | 2 +- src/core/algorithm/diskann/diskann_reducer.cc | 11 +- src/core/algorithm/diskann/diskann_reducer.h | 6 +- .../diskann/diskann_reducer_entity.h | 2 +- src/core/algorithm/diskann/diskann_searcher.h | 2 +- .../diskann/diskann_searcher_entity.h | 2 +- src/core/algorithm/diskann/diskann_streamer.h | 2 +- src/core/algorithm/diskann/diskann_util.h | 22 +- .../algorithm/flat/flat_streamer_entity.cc | 4 +- .../algorithm/flat/flat_streamer_entity.h | 2 +- src/core/algorithm/flat/flat_utility.h | 6 +- .../flat_sparse/flat_sparse_builder.h | 4 +- src/core/algorithm/hnsw/hnsw_algorithm.cc | 4 +- src/core/algorithm/hnsw/hnsw_chunk.cc | 2 +- src/core/algorithm/hnsw/hnsw_chunk.h | 2 +- .../algorithm/hnsw/hnsw_streamer_entity.cc | 2 +- .../algorithm/hnsw/hnsw_streamer_entity.h | 6 +- .../hnsw_sparse/hnsw_sparse_algorithm.cc | 4 +- .../hnsw_sparse/hnsw_sparse_builder.h | 4 +- .../algorithm/hnsw_sparse/hnsw_sparse_chunk.h | 2 +- .../hnsw_sparse/hnsw_sparse_streamer_entity.h | 4 +- src/core/algorithm/ivf/ivf_builder.cc | 4 +- src/core/algorithm/ivf/ivf_builder.h | 2 +- .../algorithm/ivf/ivf_distance_calculator.cc | 4 +- .../algorithm/ivf/ivf_distance_calculator.h | 6 +- src/core/algorithm/ivf/ivf_utility.h | 6 +- .../vamana/vamana_streamer_entity.cc | 2 +- .../algorithm/vamana/vamana_streamer_entity.h | 6 +- src/core/framework/index_mapping.cc | 6 +- src/core/interface/index.cc | 32 +- src/core/interface/index_factory.cc | 2 +- src/core/interface/index_param.cc | 92 +- src/core/interface/indexes/diskann_index.cc | 6 +- src/core/interface/indexes/flat_index.cc | 42 +- src/core/interface/indexes/hnsw_index.cc | 2 +- .../interface/indexes/hnsw_rabitq_index.cc | 2 +- src/core/interface/indexes/ivf_index.cc | 18 +- .../interface/indexes/ivf_rabitq_index.cc | 4 +- src/core/interface/indexes/vamana_index.cc | 2 +- .../metric/quantized_integer_metric_batch.h | 32 +- src/core/metric/uniform_uint7_metric.cc | 4 +- .../mixed_reducer/mixed_streamer_reducer.cc | 4 +- .../mixed_reducer/mixed_streamer_reducer.h | 2 +- src/core/quantizer/rotator/matrix_rotator.cc | 20 +- src/core/quantizer/uniform_uint4_converter.cc | 12 +- src/core/quantizer/uniform_uint4_reformer.cc | 10 +- src/core/quantizer/uniform_uint7_reformer.cc | 6 +- src/core/quantizer/uniform_uint8_reformer.cc | 26 +- src/core/utility/basic_refiner.cc | 4 +- src/core/utility/buffer_storage.cc | 20 +- src/core/utility/mmap_file_storage.cc | 2 +- src/core/utility/visit_filter.h | 142 +- src/db/collection.cc | 10 +- src/db/common/cgroup_util.cc | 52 +- src/db/common/cgroup_util.h | 32 +- src/db/common/config.cc | 8 +- src/db/common/glogger.h | 2 +- src/db/doc_iterator.cc | 2 +- .../index/column/fts_column/gen/.clang-tidy | 2 + .../column/inverted_column/inverted_codec.h | 10 +- .../inverted_column/inverted_column_indexer.h | 6 +- .../inverted_column_indexer_search.cc | 102 +- .../inverted_column_indexer_util.cc | 40 +- .../inverted_column_indexer_write.cc | 42 +- .../inverted_column/inverted_indexer.cc | 38 +- .../column/inverted_column/inverted_indexer.h | 4 +- .../inverted_column/inverted_rocksdb_merger.h | 4 +- .../inverted_column/inverted_search_result.h | 4 +- .../combined_vector_column_indexer.cc | 24 +- .../combined_vector_column_indexer.h | 4 +- .../vector_column/vector_column_indexer.cc | 22 +- .../vector_column/vector_column_indexer.h | 18 +- src/db/index/common/doc.cc | 6 +- .../index/common/manifest/manifest_codec.cc | 257 ++-- src/db/index/common/manifest/pb_wire.cc | 24 +- src/db/index/common/manifest/pb_wire.h | 54 +- src/db/index/segment/segment.cc | 150 +- src/db/index/segment/segment.h | 12 +- src/db/index/segment/segment_helper.cc | 14 +- src/db/index/segment/sql_expr_parser.cc | 68 +- src/db/index/storage/arrow_ipc_writer.h | 2 +- src/db/index/storage/base_forward_store.h | 2 +- .../index/storage/bufferpool_forward_store.cc | 18 +- .../index/storage/bufferpool_forward_store.h | 8 +- src/db/index/storage/chunked_file_writer.cc | 12 +- src/db/index/storage/chunked_file_writer.h | 6 +- src/db/index/storage/memory_forward_store.cc | 36 +- src/db/index/storage/memory_forward_store.h | 10 +- src/db/index/storage/mmap_forward_store.cc | 62 +- src/db/index/storage/mmap_forward_store.h | 31 +- src/db/index/storage/parquet_writer.h | 2 +- src/db/index/storage/store_helper.h | 4 +- src/db/index/storage/wal/local_wal_file.h | 2 +- src/db/sqlengine/analyzer/query_analyzer.cc | 6 +- src/db/sqlengine/analyzer/query_analyzer.h | 2 +- src/db/sqlengine/analyzer/query_node.h | 8 +- src/db/sqlengine/antlr/gen/.clang-tidy | 2 + src/db/sqlengine/common/generic_node.h | 22 +- .../parser/case_changing_charstream.h | 20 +- .../sqlengine/parser/error_verbose_listener.h | 14 +- src/db/sqlengine/parser/node.cc | 6 +- src/db/sqlengine/parser/node.h | 2 +- src/db/sqlengine/parser/query_parser.cc | 6 +- src/db/sqlengine/parser/select_info.h | 4 +- .../parser/zvec_cached_sql_parser.cc | 16 +- .../sqlengine/parser/zvec_cached_sql_parser.h | 6 +- src/db/sqlengine/parser/zvec_parser.cc | 10 +- src/db/sqlengine/parser/zvec_sql_parser.cc | 284 ++-- src/db/sqlengine/planner/invert_search.cc | 6 +- .../sqlengine/planner/ops/fetch_vector_op.cc | 4 +- src/db/sqlengine/planner/segment_node.cc | 8 +- .../sqlengine/planner/vector_recall_node.cc | 30 +- .../zvec/ailego/buffer/concurrentqueue.h | 6 +- .../zvec/ailego/buffer/external_cache.h | 2 +- .../zvec/ailego/buffer/vector_page_table.h | 2 +- src/include/zvec/ailego/container/cube.h | 32 +- src/include/zvec/ailego/math_batch/utils.h | 4 +- src/include/zvec/ailego/pattern/expected.hpp | 4 + src/include/zvec/ailego/pattern/factory.h | 2 +- .../zvec/core/framework/index_bundle.h | 24 +- .../zvec/core/framework/index_features.h | 52 +- .../zvec/core/framework/index_mapping.h | 2 +- .../zvec/core/framework/index_metric.h | 2 +- .../zvec/core/framework/index_refiner.h | 2 +- .../zvec/core/framework/index_storage.h | 2 +- src/include/zvec/core/interface/index.h | 52 +- src/include/zvec/core/interface/index_param.h | 69 +- .../core/interface/index_param_builders.h | 16 +- src/include/zvec/db/query_params.h | 2 +- src/include/zvec/turbo/turbo.h | 2 +- .../quantizer/fp16_quantizer/fp16_quantizer.h | 2 +- .../quantizer/fp32_quantizer/fp32_quantizer.h | 2 +- .../quantizer/int4_quantizer/int4_quantizer.h | 2 +- .../quantizer/int8_quantizer/int8_quantizer.h | 2 +- .../algorithm/integer_quantizer_test.cc | 24 +- tests/ailego/buffer/vector_page_table_test.cc | 200 +-- tests/ailego/container/cube_test.cc | 44 +- tests/ailego/io/utf8_path_test.cc | 12 +- .../math/cosine_distance_matrix_fp16_test.cc | 10 +- .../math/cosine_distance_matrix_fp32_test.cc | 10 +- .../math/cosine_distance_matrix_int8_test.cc | 10 +- .../euclidean_distance_matrix_fp16_test.cc | 10 +- .../euclidean_distance_matrix_fp32_test.cc | 12 +- .../euclidean_distance_matrix_int8_test.cc | 10 +- .../math/inner_product_matrix_fp16_test.cc | 10 +- .../math/inner_product_matrix_fp32_test.cc | 12 +- .../math/inner_product_matrix_int8_test.cc | 10 +- ...ips_euclidean_distance_matrix_fp16_test.cc | 12 +- ...ips_euclidean_distance_matrix_fp32_test.cc | 12 +- ...ips_euclidean_distance_matrix_int4_test.cc | 12 +- ...ips_euclidean_distance_matrix_int8_test.cc | 12 +- tests/ailego/math/norm_matrix_fp16_test.cc | 12 +- tests/ailego/math/norm_matrix_fp32_test.cc | 12 +- tests/ailego/math/norm_matrix_int4_test.cc | 12 +- tests/ailego/math/norm_matrix_int8_test.cc | 12 +- tests/ailego/parallel/thread_pool_test.cc | 8 +- tests/ailego/pattern/closure_test.cc | 247 ++-- tests/ailego/pattern/scope_guard_test.cc | 16 +- .../diskann/diskann_searcher_test.cc | 536 +++---- .../core/algorithm/flat/flat_streamer_test.cc | 324 ++--- .../flat_sparse/flat_sparse_searcher_test.cc | 99 +- .../flat_sparse_streamer_buffer_test.cc | 58 +- .../flat_sparse/flat_sparse_streamer_test.cc | 218 +-- .../core/algorithm/hnsw/hnsw_streamer_test.cc | 1242 ++++++++--------- .../hnsw_sparse/hnsw_sparse_streamer_test.cc | 463 +++--- tests/core/algorithm/ivf/ivf_searcher_test.cc | 18 +- .../vamana/vamana_fast_search_test.cc | 82 +- .../algorithm/vamana/vamana_streamer_test.cc | 335 ++--- tests/core/interface/index_group_by_test.cc | 46 +- tests/core/interface/index_interface_test.cc | 32 +- .../metric/quantized_integer_metric_test.cc | 36 +- .../core/utility/buffer_storage_write_test.cc | 88 +- tests/db/collection_test.cc | 10 +- tests/db/common/cgroup_util_test.cc | 20 +- .../crash_recovery/optimize_recovery_test.cc | 24 +- .../db/crash_recovery/write_recovery_test.cc | 58 +- .../fts_column/fts_rocksdb_reducer_test.cc | 100 +- .../column/vector_column_group_by_test.cc | 36 +- .../column/vector_column_indexer_test.cc | 302 ++-- .../common/manifest_codec_golden_test.cc | 10 +- tests/db/index/common/pb_wire_test.cc | 94 +- tests/db/index/segment/segment_helper_test.cc | 170 +-- tests/db/index/segment/segment_test.cc | 102 +- tests/db/index/segment/segment_test_fixture.h | 2 +- .../db/index/storage/arrow_ipc_writer_test.cc | 6 +- .../db/index/storage/bufferpool_store_test.cc | 52 +- tests/db/index/storage/mem_store_test.cc | 70 +- tests/db/index/storage/mmap_store_test.cc | 102 +- tests/db/index/storage/wal_file_test.cc | 12 +- tests/db/index/utils/utils.cc | 4 +- tests/db/sqlengine/fts_multi_segment_test.cc | 2 +- tests/db/sqlengine/fts_recall_test.cc | 6 +- tests/db/sqlengine/mock_segment.h | 12 +- tests/db/sqlengine/optimizer_test.cc | 8 +- tests/db/sqlengine/perf_bench_test.cc | 44 +- tests/db/sqlengine/recall_base.h | 2 +- tests/db/sqlengine/test_helper.h | 2 +- tools/core/bench.cc | 38 +- tools/core/bench_original.cc | 38 +- tools/core/bench_result.h | 4 +- tools/core/local_builder.cc | 6 +- tools/core/local_builder_original.cc | 6 +- tools/core/recall.cc | 42 +- tools/core/recall_original.cc | 42 +- tools/db/fts_bench_main.cc | 30 +- 237 files changed, 4404 insertions(+), 4303 deletions(-) create mode 100644 src/db/index/column/fts_column/gen/.clang-tidy create mode 100644 src/db/sqlengine/antlr/gen/.clang-tidy diff --git a/.clang-tidy b/.clang-tidy index ad50f503d..43e3130a9 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,7 +7,54 @@ Checks: > modernize-use-equals-default, modernize-use-equals-delete, modernize-redundant-void-arg, + readability-identifier-naming, WarningsAsErrors: "*" -HeaderFilterRegex: "^(src|tests|tools)/(?!db/sqlengine/antlr/gen/|db/index/column/fts_column/gen/|include/zvec/ailego/encoding/json/mod_json\\.h).*" +HeaderFilterRegex: "(^|/)(src|tests|tools)/" FormatStyle: none SystemHeaders: false +CheckOptions: + # Type-like identifiers use CamelCase (Google style). STL-compatible + # container aliases (iterator, value_type, *_t ...) are exempted. + readability-identifier-naming.NamespaceCase: lower_case + readability-identifier-naming.ClassCase: CamelCase + readability-identifier-naming.ClassIgnoredRegexp: '(const_)?(iterator|reverse_iterator)' + readability-identifier-naming.StructCase: CamelCase + readability-identifier-naming.StructIgnoredRegexp: '(const_)?(iterator|reverse_iterator)' + readability-identifier-naming.UnionCase: CamelCase + readability-identifier-naming.EnumCase: CamelCase + readability-identifier-naming.TypedefCase: CamelCase + readability-identifier-naming.TypedefIgnoredRegexp: '(_.*|[a-z][a-z0-9_]*|.*_t|.*_type|(const_)?(iterator|reverse_iterator|pointer|reference))' + readability-identifier-naming.TypeAliasCase: CamelCase + readability-identifier-naming.TypeAliasIgnoredRegexp: '(_.*|[a-z][a-z0-9_]*|.*_t|.*_type|(const_)?(iterator|reverse_iterator|pointer|reference))' + # Member functions use snake_case. Static/free/global functions may use + # snake_case or CamelCase. A leading underscore (private-method convention) + # or trailing underscore (keyword avoidance, e.g. delete_) is allowed. + readability-identifier-naming.MethodCase: lower_case + readability-identifier-naming.MethodIgnoredRegexp: '_*[a-z][a-z0-9_]*' + readability-identifier-naming.ClassMethodCase: lower_case + readability-identifier-naming.ClassMethodIgnoredRegexp: '(_*[a-z][a-z0-9_]*|[A-Z][A-Za-z0-9]*)' + readability-identifier-naming.FunctionCase: lower_case + readability-identifier-naming.FunctionIgnoredRegexp: '(_*[a-z][a-z0-9_]*|[A-Z][A-Za-z0-9]*)' + readability-identifier-naming.GlobalFunctionCase: lower_case + readability-identifier-naming.GlobalFunctionIgnoredRegexp: '(_*[a-z][a-z0-9_]*|[A-Z][A-Za-z0-9]*)' + # Data members use snake_case; a trailing underscore is allowed but not required. + readability-identifier-naming.MemberCase: lower_case + readability-identifier-naming.MemberIgnoredRegexp: '_*[a-z][a-z0-9]*(_[a-z0-9]+)*_*' + readability-identifier-naming.ConstantMemberCase: lower_case + readability-identifier-naming.ConstantMemberIgnoredRegexp: '_*[a-z][a-z0-9]*(_[a-z0-9]+)*_*' + # Static data members follow the same snake_case rule as non-static members. + readability-identifier-naming.ClassMemberCase: lower_case + readability-identifier-naming.ClassMemberIgnoredRegexp: '_*[a-z][a-z0-9]*(_[a-z0-9]+)*_*' + # Local variables and parameters use snake_case. + readability-identifier-naming.LocalVariableCase: lower_case + readability-identifier-naming.ParameterCase: lower_case + # Constants keep the existing mixed conventions (kCamelCase / UPPER_CASE / + # snake_case) and are intentionally not enforced. + readability-identifier-naming.ConstantCase: aNy_CasE + readability-identifier-naming.LocalConstantCase: aNy_CasE + readability-identifier-naming.StaticConstantCase: aNy_CasE + readability-identifier-naming.ClassConstantCase: aNy_CasE + readability-identifier-naming.GlobalConstantCase: aNy_CasE + readability-identifier-naming.ConstexprVariableCase: aNy_CasE + readability-identifier-naming.GlobalVariableCase: aNy_CasE + readability-identifier-naming.StaticVariableCase: aNy_CasE diff --git a/src/ailego/algorithm/integer_quantizer.cc b/src/ailego/algorithm/integer_quantizer.cc index a3b61b74c..8cfa72fa4 100644 --- a/src/ailego/algorithm/integer_quantizer.cc +++ b/src/ailego/algorithm/integer_quantizer.cc @@ -129,7 +129,7 @@ static inline void ExpandCandidateDistribution( */ static inline size_t ComputeThreshold(const std::vector &hist, const size_t target_bins) { - std::vector P_distribution(hist.size()); + std::vector p_distribution(hist.size()); size_t zero_point_index = hist.size() / 2; size_t start_bin = target_bins / 2; @@ -147,19 +147,19 @@ static inline size_t ComputeThreshold(const std::vector &hist, //! for each zero-axised quantization range: [-threshold, threshold], search //! the best solution for (size_t threshold = start_bin; threshold <= end_bin; ++threshold) { - P_distribution.resize(threshold * 2); + p_distribution.resize(threshold * 2); auto p_hist = &hist[zero_point_index - threshold]; - for (size_t i = 0; i != P_distribution.size(); ++i) { - P_distribution[i] = static_cast(p_hist[i]); + for (size_t i = 0; i != p_distribution.size(); ++i) { + p_distribution[i] = static_cast(p_hist[i]); } negative_outliers_count -= hist[zero_point_index - threshold]; positive_outliers_count -= hist[zero_point_index + threshold - 1]; - P_distribution[0] += negative_outliers_count; - P_distribution[P_distribution.size() - 1] += positive_outliers_count; + p_distribution[0] += negative_outliers_count; + p_distribution[p_distribution.size() - 1] += positive_outliers_count; //! Quantize the bins in range [-threshold, threshold] to target_bins - std::vector Q_distribution(target_bins, 0); + std::vector q_distribution(target_bins, 0); float merged_cnt = static_cast(threshold * 2) / target_bins; size_t left_boundary = zero_point_index - threshold; for (size_t i = 0; i < target_bins; ++i) { @@ -168,28 +168,28 @@ static inline size_t ComputeThreshold(const std::vector &hist, const size_t start_ceil = static_cast(std::ceil(start)); const size_t end_floor = static_cast(std::floor(end)); if (left_boundary + start_ceil > 0) { - Q_distribution[i] += + q_distribution[i] += ((float)start_ceil - start) * hist[left_boundary + start_ceil - 1]; } if (left_boundary + end_floor < hist.size()) { - Q_distribution[i] += + q_distribution[i] += (end - (float)end_floor) * hist[left_boundary + end_floor]; } for (size_t j = start_ceil; j < end_floor; j++) { - Q_distribution[i] += hist[left_boundary + j]; + q_distribution[i] += hist[left_boundary + j]; } } - std::vector Q_expand_distribution; - ExpandCandidateDistribution(hist, Q_distribution, threshold, - &Q_expand_distribution); + std::vector q_expand_distribution; + ExpandCandidateDistribution(hist, q_distribution, threshold, + &q_expand_distribution); //! Compute Kullback-Leibler Divergence, normalize the smooth the data //! first. Ref: http://hanj.cs.illinois.edu/cs412/bk3/KL-divergence.pdf - MakeSmooth(P_distribution); - MakeSmooth(Q_expand_distribution); + MakeSmooth(p_distribution); + MakeSmooth(q_expand_distribution); double divergence = - ComputeKlDivergence(P_distribution, Q_expand_distribution); + ComputeKlDivergence(p_distribution, q_expand_distribution); if (divergence < min_divergence) { min_divergence = divergence; diff --git a/src/ailego/encoding/json/mod_json.c b/src/ailego/encoding/json/mod_json.c index ea6a1103c..a8f220f8a 100644 --- a/src/ailego/encoding/json/mod_json.c +++ b/src/ailego/encoding/json/mod_json.c @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +// NOLINTBEGIN + #include #include #include @@ -3589,3 +3591,5 @@ mod_json_string_t *mod_json_dump(mod_json_value_t *val) { } return str; } + +// NOLINTEND diff --git a/src/ailego/internal/cpu_features.h b/src/ailego/internal/cpu_features.h index ac065aa1e..2ad814368 100644 --- a/src/ailego/internal/cpu_features.h +++ b/src/ailego/internal/cpu_features.h @@ -21,6 +21,8 @@ namespace internal { /*! Cpu Features */ +// NOLINTBEGIN(readability-identifier-naming): identifiers mirror CPUID feature +// mnemonics (SSE4_1, AVX512_VNNI, L1_ECX ...) and stay in hardware casing. class CpuFeatures { public: //! 16-bit FP conversions @@ -376,6 +378,7 @@ class CpuFeatures { }; static StaticFlags static_flags_; }; +// NOLINTEND(readability-identifier-naming) } // namespace internal } // namespace ailego diff --git a/src/ailego/math_batch/cosine_distance_batch.h b/src/ailego/math_batch/cosine_distance_batch.h index b8a8309a9..fb2290471 100644 --- a/src/ailego/math_batch/cosine_distance_batch.h +++ b/src/ailego/math_batch/cosine_distance_batch.h @@ -21,7 +21,7 @@ #include #include "inner_product_distance_batch.h" -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { template @@ -35,10 +35,10 @@ struct CosineDistanceBatch { const ValueType *query, size_t num_vecs, size_t dim, float *results) { constexpr size_t extra_dim = sizeof(float) / sizeof(ValueType); - size_t _dim = dim - extra_dim; + size_t data_dim = dim - extra_dim; InnerProductDistanceBatch::ComputeBatch( - vecs, query, num_vecs, _dim, results); + vecs, query, num_vecs, data_dim, results); for (size_t i = 0; i < num_vecs; ++i) { results[i] = 1 - results[i]; @@ -55,4 +55,4 @@ struct CosineDistanceBatch { }; -} // namespace zvec::ailego::DistanceBatch \ No newline at end of file +} // namespace zvec::ailego::distance_batch \ No newline at end of file diff --git a/src/ailego/math_batch/distance_batch.h b/src/ailego/math_batch/distance_batch.h index 6fcc987cb..c186cef9d 100644 --- a/src/ailego/math_batch/distance_batch.h +++ b/src/ailego/math_batch/distance_batch.h @@ -26,7 +26,7 @@ template < template class DistanceType, typename ValueType, size_t BatchSize, size_t PrefetchStep, typename = void> struct BaseDistance { - static inline void _ComputeBatch(const ValueType **m, const ValueType *q, + static inline void compute_batch(const ValueType **m, const ValueType *q, size_t num, size_t dim, float *out) { for (size_t i = 0; i < num; ++i) { DistanceType::Compute(m[i], q, dim, out + i); @@ -39,14 +39,14 @@ struct BaseDistance { const void ** /*extra_values*/) { if constexpr (std::is_same_v, CosineDistanceMatrix>) { - return DistanceBatch::CosineDistanceBatch< + return distance_batch::CosineDistanceBatch< ValueType, BatchSize, PrefetchStep>::ComputeBatch(m, q, num, dim, out); } if constexpr (std::is_same_v, EuclideanDistanceMatrix>) { - return DistanceBatch::EuclideanDistanceBatch< + return distance_batch::EuclideanDistanceBatch< ValueType, BatchSize, PrefetchStep>::ComputeBatch(m, q, num, dim, out); } @@ -54,12 +54,12 @@ struct BaseDistance { if constexpr (std::is_same_v< DistanceType, SquaredEuclideanDistanceMatrix>) { - return DistanceBatch::SquaredEuclideanDistanceBatch< + return distance_batch::SquaredEuclideanDistanceBatch< ValueType, BatchSize, PrefetchStep>::ComputeBatch(m, q, num, dim, out, nullptr); } - _ComputeBatch(m, q, num, dim, out); + compute_batch(m, q, num, dim, out); } }; diff --git a/src/ailego/math_batch/euclidean_distance_batch.h b/src/ailego/math_batch/euclidean_distance_batch.h index 60e020f9e..5fe309f94 100644 --- a/src/ailego/math_batch/euclidean_distance_batch.h +++ b/src/ailego/math_batch/euclidean_distance_batch.h @@ -22,7 +22,7 @@ #include #include -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { // SquaredEuclideanDistanceBatch template @@ -141,4 +141,4 @@ struct SquaredEuclideanDistanceBatchImpl { size_t dim, float *sums); }; -} // namespace zvec::ailego::DistanceBatch +} // namespace zvec::ailego::distance_batch diff --git a/src/ailego/math_batch/euclidean_distance_batch_dispatch.cc b/src/ailego/math_batch/euclidean_distance_batch_dispatch.cc index 5c8ffb254..68f473978 100644 --- a/src/ailego/math_batch/euclidean_distance_batch_dispatch.cc +++ b/src/ailego/math_batch/euclidean_distance_batch_dispatch.cc @@ -19,7 +19,7 @@ #include #include "euclidean_distance_batch.h" -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { #if defined(__AVX512FP16__) void compute_one_to_many_squared_euclidean_avx512fp16_fp16_1( @@ -188,4 +188,4 @@ void SquaredEuclideanDistanceBatchImpl:: // dim, sums); // } -} // namespace zvec::ailego::DistanceBatch +} // namespace zvec::ailego::distance_batch diff --git a/src/ailego/math_batch/euclidean_distance_batch_impl_fp16_avx2.cc b/src/ailego/math_batch/euclidean_distance_batch_impl_fp16_avx2.cc index e6d793da0..1e321e735 100644 --- a/src/ailego/math_batch/euclidean_distance_batch_impl_fp16_avx2.cc +++ b/src/ailego/math_batch/euclidean_distance_batch_impl_fp16_avx2.cc @@ -17,7 +17,7 @@ #include #include -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { #if defined(__AVX2__) @@ -111,4 +111,4 @@ void compute_one_to_many_squared_euclidean_avx2_fp16_12( } #endif -} // namespace zvec::ailego::DistanceBatch +} // namespace zvec::ailego::distance_batch diff --git a/src/ailego/math_batch/euclidean_distance_batch_impl_fp16_avx512.cc b/src/ailego/math_batch/euclidean_distance_batch_impl_fp16_avx512.cc index 1d4750eff..d1caaa3bf 100644 --- a/src/ailego/math_batch/euclidean_distance_batch_impl_fp16_avx512.cc +++ b/src/ailego/math_batch/euclidean_distance_batch_impl_fp16_avx512.cc @@ -17,7 +17,7 @@ #include #include -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { #if defined(__AVX512F__) @@ -134,4 +134,4 @@ void compute_one_to_many_squared_euclidean_avx512f_fp16_12( #endif -} // namespace zvec::ailego::DistanceBatch +} // namespace zvec::ailego::distance_batch diff --git a/src/ailego/math_batch/euclidean_distance_batch_impl_fp16_avx512fp16.cc b/src/ailego/math_batch/euclidean_distance_batch_impl_fp16_avx512fp16.cc index 70e024039..03eac5dcd 100644 --- a/src/ailego/math_batch/euclidean_distance_batch_impl_fp16_avx512fp16.cc +++ b/src/ailego/math_batch/euclidean_distance_batch_impl_fp16_avx512fp16.cc @@ -17,7 +17,7 @@ #include #include -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { #if defined(__AVX512FP16__) @@ -96,4 +96,4 @@ void compute_one_to_many_squared_euclidean_avx512fp16_fp16_12( #endif -} // namespace zvec::ailego::DistanceBatch +} // namespace zvec::ailego::distance_batch diff --git a/src/ailego/math_batch/euclidean_distance_batch_impl_fp32_avx2.cc b/src/ailego/math_batch/euclidean_distance_batch_impl_fp32_avx2.cc index ce27e92a0..8246556d4 100644 --- a/src/ailego/math_batch/euclidean_distance_batch_impl_fp32_avx2.cc +++ b/src/ailego/math_batch/euclidean_distance_batch_impl_fp32_avx2.cc @@ -25,7 +25,7 @@ sum += (x * x); \ } -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { #if defined(__AVX2__) @@ -101,4 +101,4 @@ void compute_one_to_many_squared_euclidean_avx2_fp32_12( #endif -} // namespace zvec::ailego::DistanceBatch +} // namespace zvec::ailego::distance_batch diff --git a/src/ailego/math_batch/euclidean_distance_batch_impl_fp32_avx512.cc b/src/ailego/math_batch/euclidean_distance_batch_impl_fp32_avx512.cc index d7e58478c..701bc565e 100644 --- a/src/ailego/math_batch/euclidean_distance_batch_impl_fp32_avx512.cc +++ b/src/ailego/math_batch/euclidean_distance_batch_impl_fp32_avx512.cc @@ -25,7 +25,7 @@ sum += (x * x); \ } -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { #if defined(__AVX512F__) @@ -92,4 +92,4 @@ void compute_one_to_many_squared_euclidean_avx512f_fp32_12( #endif -} // namespace zvec::ailego::DistanceBatch +} // namespace zvec::ailego::distance_batch diff --git a/src/ailego/math_batch/inner_product_distance_batch.h b/src/ailego/math_batch/inner_product_distance_batch.h index 6375482a2..568cc6c22 100644 --- a/src/ailego/math_batch/inner_product_distance_batch.h +++ b/src/ailego/math_batch/inner_product_distance_batch.h @@ -21,7 +21,7 @@ #include #include -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { template struct InnerProductDistanceBatch; @@ -140,4 +140,4 @@ struct InnerProductDistanceBatchImpl { size_t dim, float *sums); }; -} // namespace zvec::ailego::DistanceBatch +} // namespace zvec::ailego::distance_batch diff --git a/src/ailego/math_batch/inner_product_distance_batch_dispatch.cc b/src/ailego/math_batch/inner_product_distance_batch_dispatch.cc index 78376626a..adbd2952e 100644 --- a/src/ailego/math_batch/inner_product_distance_batch_dispatch.cc +++ b/src/ailego/math_batch/inner_product_distance_batch_dispatch.cc @@ -20,7 +20,7 @@ #include #include "inner_product_distance_batch.h" -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { #if defined(__AVX512VNNI__) void compute_one_to_many_inner_product_avx512_vnni_int8_query_preprocess( @@ -225,4 +225,4 @@ void InnerProductDistanceBatchImpl::compute_one_to_many( dim, sums); } -} // namespace zvec::ailego::DistanceBatch +} // namespace zvec::ailego::distance_batch diff --git a/src/ailego/math_batch/inner_product_distance_batch_impl_fp16_avx2.cc b/src/ailego/math_batch/inner_product_distance_batch_impl_fp16_avx2.cc index d6fe475f2..43d719180 100644 --- a/src/ailego/math_batch/inner_product_distance_batch_impl_fp16_avx2.cc +++ b/src/ailego/math_batch/inner_product_distance_batch_impl_fp16_avx2.cc @@ -18,7 +18,7 @@ #include #include -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { #if defined(__AVX2__) @@ -106,4 +106,4 @@ void compute_one_to_many_inner_product_avx2_fp16_12( #endif -} // namespace zvec::ailego::DistanceBatch \ No newline at end of file +} // namespace zvec::ailego::distance_batch \ No newline at end of file diff --git a/src/ailego/math_batch/inner_product_distance_batch_impl_fp16_avx512.cc b/src/ailego/math_batch/inner_product_distance_batch_impl_fp16_avx512.cc index 805da8dae..c9df60988 100644 --- a/src/ailego/math_batch/inner_product_distance_batch_impl_fp16_avx512.cc +++ b/src/ailego/math_batch/inner_product_distance_batch_impl_fp16_avx512.cc @@ -18,7 +18,7 @@ #include #include -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { #if defined(__AVX512F__) @@ -125,4 +125,4 @@ void compute_one_to_many_inner_product_avx512f_fp16_12( } #endif -} // namespace zvec::ailego::DistanceBatch +} // namespace zvec::ailego::distance_batch diff --git a/src/ailego/math_batch/inner_product_distance_batch_impl_fp16_avx512fp16.cc b/src/ailego/math_batch/inner_product_distance_batch_impl_fp16_avx512fp16.cc index b69e60b57..7b3fc037b 100644 --- a/src/ailego/math_batch/inner_product_distance_batch_impl_fp16_avx512fp16.cc +++ b/src/ailego/math_batch/inner_product_distance_batch_impl_fp16_avx512fp16.cc @@ -18,7 +18,7 @@ #include #include -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { #if defined(__AVX512FP16__) template @@ -89,4 +89,4 @@ void compute_one_to_many_inner_product_avx512fp16_fp16_12( } #endif -} // namespace zvec::ailego::DistanceBatch +} // namespace zvec::ailego::distance_batch diff --git a/src/ailego/math_batch/inner_product_distance_batch_impl_fp32_avx2.cc b/src/ailego/math_batch/inner_product_distance_batch_impl_fp32_avx2.cc index bead50745..74cffc365 100644 --- a/src/ailego/math_batch/inner_product_distance_batch_impl_fp32_avx2.cc +++ b/src/ailego/math_batch/inner_product_distance_batch_impl_fp32_avx2.cc @@ -18,7 +18,7 @@ #include #include -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { #if defined(__AVX2__) @@ -131,4 +131,4 @@ void compute_one_to_many_inner_product_avx2_fp32_12( #endif -} // namespace zvec::ailego::DistanceBatch \ No newline at end of file +} // namespace zvec::ailego::distance_batch \ No newline at end of file diff --git a/src/ailego/math_batch/inner_product_distance_batch_impl_int8_avx2.cc b/src/ailego/math_batch/inner_product_distance_batch_impl_int8_avx2.cc index 66d7e1543..3bab06694 100644 --- a/src/ailego/math_batch/inner_product_distance_batch_impl_int8_avx2.cc +++ b/src/ailego/math_batch/inner_product_distance_batch_impl_int8_avx2.cc @@ -17,7 +17,7 @@ #include #include -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { #if defined(__AVX2__) @@ -101,4 +101,4 @@ void compute_one_to_many_inner_product_avx2_int8_12( #endif -} // namespace zvec::ailego::DistanceBatch \ No newline at end of file +} // namespace zvec::ailego::distance_batch \ No newline at end of file diff --git a/src/ailego/math_batch/inner_product_distance_batch_impl_int8_avx512fp16.cc b/src/ailego/math_batch/inner_product_distance_batch_impl_int8_avx512fp16.cc index 96c68dc6b..249cb7a2c 100644 --- a/src/ailego/math_batch/inner_product_distance_batch_impl_int8_avx512fp16.cc +++ b/src/ailego/math_batch/inner_product_distance_batch_impl_int8_avx512fp16.cc @@ -17,7 +17,7 @@ #include #include -namespace zvec::ailego::DistanceBatch { +namespace zvec::ailego::distance_batch { #if defined(__AVX512VNNI__) @@ -170,4 +170,4 @@ void compute_one_to_many_inner_product_avx512_vnni_int8_12( #endif -} // namespace zvec::ailego::DistanceBatch \ No newline at end of file +} // namespace zvec::ailego::distance_batch \ No newline at end of file diff --git a/src/ailego/utility/bitset_helper.h b/src/ailego/utility/bitset_helper.h index 20af020e4..83541c2a8 100644 --- a/src/ailego/utility/bitset_helper.h +++ b/src/ailego/utility/bitset_helper.h @@ -112,8 +112,8 @@ class BitsetHelper { size_t cardinality() const; //! Calculate the size of buffer if it contains N bits - static size_t BufferSize(size_t N) { - return (((N + 0x1f) >> 5) << 2); + static size_t BufferSize(size_t n) { + return (((n + 0x1f) >> 5) << 2); } //! Calculate the count of bits can be contained diff --git a/src/ailego/utility/matrix_helper.h b/src/ailego/utility/matrix_helper.h index 1a05ad5fb..b7a136396 100644 --- a/src/ailego/utility/matrix_helper.h +++ b/src/ailego/utility/matrix_helper.h @@ -22,21 +22,21 @@ namespace ailego { struct MatrixHelper { //! Transpose a matrix template - static inline void Transpose(const void *src, size_t N, void *dst) { + static inline void Transpose(const void *src, size_t n, void *dst) { for (size_t i = 0; i < M; ++i) { - for (size_t j = 0; j < N; ++j) { + for (size_t j = 0; j < n; ++j) { *(reinterpret_cast(dst) + (j * M + i)) = - *(reinterpret_cast(src) + (i * N + j)); + *(reinterpret_cast(src) + (i * n + j)); } } } //! Reverse transpose a matrix template - static inline void ReverseTranspose(const void *src, size_t N, void *dst) { - for (size_t i = 0; i < N; ++i) { + static inline void ReverseTranspose(const void *src, size_t n, void *dst) { + for (size_t i = 0; i < n; ++i) { for (size_t j = 0; j < M; ++j) { - *(reinterpret_cast(dst) + (j * N + i)) = + *(reinterpret_cast(dst) + (j * n + i)) = *(reinterpret_cast(src) + (i * M + j)); } } @@ -44,23 +44,23 @@ struct MatrixHelper { //! Transpose a matrix template - static inline void Transpose(const void *src, size_t M, size_t N, void *dst) { - for (size_t i = 0; i < M; ++i) { - for (size_t j = 0; j < N; ++j) { - *(reinterpret_cast(dst) + (j * M + i)) = - *(reinterpret_cast(src) + (i * N + j)); + static inline void Transpose(const void *src, size_t m, size_t n, void *dst) { + for (size_t i = 0; i < m; ++i) { + for (size_t j = 0; j < n; ++j) { + *(reinterpret_cast(dst) + (j * m + i)) = + *(reinterpret_cast(src) + (i * n + j)); } } } //! Reverse transpose a matrix template - static inline void ReverseTranspose(const void *src, size_t M, size_t N, + static inline void ReverseTranspose(const void *src, size_t m, size_t n, void *dst) { - for (size_t i = 0; i < N; ++i) { - for (size_t j = 0; j < M; ++j) { - *(reinterpret_cast(dst) + (j * N + i)) = - *(reinterpret_cast(src) + (i * M + j)); + for (size_t i = 0; i < n; ++i) { + for (size_t j = 0; j < m; ++j) { + *(reinterpret_cast(dst) + (j * n + i)) = + *(reinterpret_cast(src) + (i * m + j)); } } } diff --git a/src/core/algorithm/cluster/linear_seeker.h b/src/core/algorithm/cluster/linear_seeker.h index 022d8c194..d95c85320 100644 --- a/src/core/algorithm/cluster/linear_seeker.h +++ b/src/core/algorithm/cluster/linear_seeker.h @@ -28,7 +28,7 @@ class LinearSeeker : public Seeker { LinearSeeker() : meta_(), metric_(), features_() {} //! Destructor - ~LinearSeeker() = default; + ~LinearSeeker() override = default; //! Initialize Seeker int init(const IndexMeta &meta) override { diff --git a/src/core/algorithm/cluster/multi_chunk_cluster.cc b/src/core/algorithm/cluster/multi_chunk_cluster.cc index 8b842819f..118dfc31e 100644 --- a/src/core/algorithm/cluster/multi_chunk_cluster.cc +++ b/src/core/algorithm/cluster/multi_chunk_cluster.cc @@ -70,20 +70,20 @@ int MultiChunkClusterAlgorithm::update_params(const ailego::Params ¶ms) { } int MultiChunkClusterAlgorithm::init_distance_func() { - IndexMetric::Pointer metric_{}; - metric_ = IndexFactory::CreateMetric(meta_.metric_name()); - if (!metric_) { + IndexMetric::Pointer metric{}; + metric = IndexFactory::CreateMetric(meta_.metric_name()); + if (!metric) { LOG_ERROR("Create metric %s failed.", meta_.metric_name().c_str()); return IndexError_Unsupported; } - int ret = metric_->init(meta_, meta_.metric_params()); + int ret = metric->init(meta_, meta_.metric_params()); if (ret != 0) { LOG_ERROR("IndexMetric init failed wit ret %d.", ret); return ret; } - distance_func_ = metric_->distance_matrix(1, 1); + distance_func_ = metric->distance_matrix(1, 1); if (!distance_func_) { LOG_ERROR("DistanceMatrix function is nullptr."); return IndexError_Unsupported; @@ -98,15 +98,15 @@ int MultiChunkClusterAlgorithm::do_chunk() { } size_t large_chunk_count = meta_.dimension() % chunk_count_; - size_t base_chunk_dim_ = meta_.dimension() / chunk_count_; + size_t base_chunk_dim = meta_.dimension() / chunk_count_; chunk_dims_.clear(); for (size_t i = 0; i < chunk_count_; ++i) { if (i < large_chunk_count) { - chunk_dims_.push_back(base_chunk_dim_ + 1); + chunk_dims_.push_back(base_chunk_dim + 1); } else { - chunk_dims_.push_back(base_chunk_dim_); + chunk_dims_.push_back(base_chunk_dim); } } diff --git a/src/core/algorithm/cluster/multi_chunk_cluster.h b/src/core/algorithm/cluster/multi_chunk_cluster.h index 19096d761..d61d02d68 100644 --- a/src/core/algorithm/cluster/multi_chunk_cluster.h +++ b/src/core/algorithm/cluster/multi_chunk_cluster.h @@ -146,18 +146,19 @@ class MultiChunkNumericalAlgorithm : public MultiChunkClusterAlgorithm { MultiChunkNumericalAlgorithm() = default; //! Destructor - ~MultiChunkNumericalAlgorithm() = default; + ~MultiChunkNumericalAlgorithm() override = default; protected: //! cluster thread void do_cluster(size_t idx, size_t chunk_step, IndexCluster::CentroidList *cents, - std::atomic *finished); + std::atomic *finished) override; //! label thread void do_label(size_t idx, size_t step, const IndexCluster::CentroidList ¢s, - std::vector *out, std::atomic *finished); + std::vector *out, + std::atomic *finished) override; }; //! cluster thread @@ -295,18 +296,19 @@ class MultiChunkNumericalInnerProductAlgorithm MultiChunkNumericalInnerProductAlgorithm() = default; //! Destructor - ~MultiChunkNumericalInnerProductAlgorithm() = default; + ~MultiChunkNumericalInnerProductAlgorithm() override = default; protected: //! cluster thread void do_cluster(size_t idx, size_t chunk_step, IndexCluster::CentroidList *cents, - std::atomic *finished); + std::atomic *finished) override; //! label thread void do_label(size_t idx, size_t chunk_step, const IndexCluster::CentroidList ¢s, - std::vector *out, std::atomic *finished); + std::vector *out, + std::atomic *finished) override; }; //! cluster thread @@ -428,7 +430,7 @@ void MultiChunkNumericalInnerProductAlgorithm::do_label( //! MultiChunkCluster class MultiChunkCluster { public: - std::shared_ptr Pointer; + std::shared_ptr pointer; //! Constructor MultiChunkCluster() = default; diff --git a/src/core/algorithm/cluster/opt_kmeans_cluster.cc b/src/core/algorithm/cluster/opt_kmeans_cluster.cc index 5da838628..39299f89f 100644 --- a/src/core/algorithm/cluster/opt_kmeans_cluster.cc +++ b/src/core/algorithm/cluster/opt_kmeans_cluster.cc @@ -222,18 +222,18 @@ void OptKmeansAlgorithm::update_params(const ailego::Params ¶ms) { } int OptKmeansAlgorithm::init_distance_func() { - IndexMetric::Pointer metric_{}; - metric_ = IndexFactory::CreateMetric(meta_.metric_name()); - if (!metric_) { + IndexMetric::Pointer metric{}; + metric = IndexFactory::CreateMetric(meta_.metric_name()); + if (!metric) { LOG_ERROR("Create Metric %s failed.", meta_.metric_name().c_str()); return IndexError_Unsupported; } - int ret = metric_->init(meta_, meta_.metric_params()); + int ret = metric->init(meta_, meta_.metric_params()); if (ret != 0) { LOG_ERROR("IndexMetric init failed wit ret %d.", ret); return ret; } - distance_func_ = metric_->distance_matrix(1, 1); + distance_func_ = metric->distance_matrix(1, 1); if (!distance_func_) { LOG_ERROR("DistanceMatrix function is nullptr."); return IndexError_Unsupported; @@ -449,8 +449,8 @@ int OptKmeansAlgorithm::mount(IndexFeatures::Pointer feats) { } int OptKmeansAlgorithm::check_dimension() const { - auto type_ = meta_.data_type(); - switch (type_) { + auto type = meta_.data_type(); + switch (type) { case IndexMeta::DataType::DT_INT4: if (meta_.dimension() % 8 != 0) { LOG_ERROR( @@ -1204,10 +1204,10 @@ int OptKmeansCluster::mount(IndexFeatures::Pointer feats) { int OptKmeansCluster::init(const IndexMeta &meta, const ailego::Params ¶ms) { - auto type_ = meta.data_type(); + auto type = meta.data_type(); if (meta.metric_name() == "InnerProduct") { - switch (type_) { + switch (type) { case IndexMeta::DataType::DT_FP16: { algorithm_.reset( new (std::nothrow) @@ -1240,12 +1240,12 @@ int OptKmeansCluster::init(const IndexMeta &meta, break; } default: { - LOG_ERROR("Unsupported feature types %d.", type_); + LOG_ERROR("Unsupported feature types %d.", type); return IndexError_Mismatch; } } } else { - switch (type_) { + switch (type) { case IndexMeta::DataType::DT_FP16: { algorithm_.reset(new (std::nothrow) NumericalKmeansAlgorithm); @@ -1272,7 +1272,7 @@ int OptKmeansCluster::init(const IndexMeta &meta, break; } default: { - LOG_ERROR("Unsupported feature types %d.", type_); + LOG_ERROR("Unsupported feature types %d.", type); return IndexError_Mismatch; } } diff --git a/src/core/algorithm/cluster/stratified_cluster_trainer.h b/src/core/algorithm/cluster/stratified_cluster_trainer.h index 2f48e4662..4e9dc4e8b 100644 --- a/src/core/algorithm/cluster/stratified_cluster_trainer.h +++ b/src/core/algorithm/cluster/stratified_cluster_trainer.h @@ -29,32 +29,33 @@ class StratifiedClusterTrainer : public IndexTrainer { StratifiedClusterTrainer() = default; //! Destructor - ~StratifiedClusterTrainer() = default; + ~StratifiedClusterTrainer() override = default; protected: //! Initialize Trainer - virtual int init(const IndexMeta &meta, const ailego::Params ¶ms); + int init(const IndexMeta &meta, const ailego::Params ¶ms) override; //! Cleanup Trainer - virtual int cleanup(); + int cleanup() override; //! Train the data - virtual int train(IndexThreads::Pointer threads, IndexHolder::Pointer holder); + int train(IndexThreads::Pointer threads, + IndexHolder::Pointer holder) override; //! Load index from file path or dir - virtual int load(IndexStorage::Pointer cntr); + int load(IndexStorage::Pointer cntr) override; //! Dump index into file path or dir - virtual int dump(const IndexDumper::Pointer &dumper); + int dump(const IndexDumper::Pointer &dumper) override; //! Retrieve Index Meta - virtual const IndexMeta &meta() const; + const IndexMeta &meta() const override; //! Retrieve statistics - virtual const IndexTrainer::Stats &stats() const; + const IndexTrainer::Stats &stats() const override; //! Retrieve the output indexes - virtual IndexBundle::Pointer indexes() const; + IndexBundle::Pointer indexes() const override; private: int init_params(const ailego::Params ¶ms); diff --git a/src/core/algorithm/cluster/vector_mean.h b/src/core/algorithm/cluster/vector_mean.h index 34024048c..44f81fe33 100644 --- a/src/core/algorithm/cluster/vector_mean.h +++ b/src/core/algorithm/cluster/vector_mean.h @@ -115,7 +115,7 @@ class GeneralVectorMeanArray : public VectorMeanArray { } //! Resize accumulators - virtual void resize(size_t cnt) { + void resize(size_t cnt) override { if (array_.size() < cnt) { for (size_t i = array_.size(); i < cnt; ++i) { array_.emplace_back(dimension_); @@ -126,27 +126,27 @@ class GeneralVectorMeanArray : public VectorMeanArray { } //! Clear accumulators - virtual void clear() { + void clear() override { array_.clear(); } //! Retrieve an accumulator - virtual VectorMean &at(size_t i) { + VectorMean &at(size_t i) override { return array_[i]; } //! Retrieve an accumulator - virtual const VectorMean &at(size_t i) const { + const VectorMean &at(size_t i) const override { return array_[i]; } //! Retrieve the count of accumulators - virtual size_t count() const { + size_t count() const override { return array_.size(); } //! Retrieve the dimension of accumulators - virtual size_t dimension() const { + size_t dimension() const override { return dimension_; } @@ -196,12 +196,12 @@ class NumericalVectorMean : public VectorMean { } //! Reset accumulator - virtual void reset() { + void reset() override { this->reset(accums_.size()); } //! Plus a vector - virtual bool plus(const void *vec, size_t len) { + bool plus(const void *vec, size_t len) override { size_t dim = accums_.size(); if (dim * sizeof(T) != len) { return false; @@ -214,7 +214,7 @@ class NumericalVectorMean : public VectorMean { } //! Retrieve the mean of vectors - virtual bool mean(void *out, size_t len) const { + bool mean(void *out, size_t len) const override { size_t dim = accums_.size(); if (dim * sizeof(T) != len) { return false; @@ -226,7 +226,7 @@ class NumericalVectorMean : public VectorMean { } //! Retrieve the mean of vectors - virtual void mean(std::string *out) const { + void mean(std::string *out) const override { ailego::NumericalVector &vec = *static_cast *>(out); @@ -238,7 +238,7 @@ class NumericalVectorMean : public VectorMean { } //! Merge another vector mean - virtual bool merge(const VectorMean &rhs) { + bool merge(const VectorMean &rhs) override { const NumericalVectorMean &src = dynamic_cast &>(rhs); @@ -254,12 +254,12 @@ class NumericalVectorMean : public VectorMean { } //! Retrieve the count of vectors - virtual size_t count() const { + size_t count() const override { return count_; } //! Retrieve dimension of accumulator - virtual size_t dimension() const { + size_t dimension() const override { return accums_.size(); } @@ -321,12 +321,12 @@ class NumericalVectorHarmonicMean : public VectorMean { } //! Reset accumulator - virtual void reset() { + void reset() override { this->reset(accums_.size()); } //! Plus a vector (harmonic) - virtual bool plus(const void *vec, size_t len) { + bool plus(const void *vec, size_t len) override { size_t dim = accums_.size(); if (dim * sizeof(T) != len) { return false; @@ -339,7 +339,7 @@ class NumericalVectorHarmonicMean : public VectorMean { } //! Retrieve the mean of vectors (harmonic) - virtual bool mean(void *out, size_t len) const { + bool mean(void *out, size_t len) const override { size_t dim = accums_.size(); if (dim * sizeof(T) != len) { return false; @@ -351,7 +351,7 @@ class NumericalVectorHarmonicMean : public VectorMean { } //! Retrieve the mean of vectors - virtual void mean(std::string *out) const { + void mean(std::string *out) const override { ailego::NumericalVector &vec = *static_cast *>(out); @@ -363,7 +363,7 @@ class NumericalVectorHarmonicMean : public VectorMean { } //! Merge another vector mean - virtual bool merge(const VectorMean &rhs) { + bool merge(const VectorMean &rhs) override { const NumericalVectorHarmonicMean &src = dynamic_cast &>(rhs); @@ -379,12 +379,12 @@ class NumericalVectorHarmonicMean : public VectorMean { } //! Retrieve the count of vectors - virtual size_t count() const { + size_t count() const override { return count_; } //! Retrieve dimension of accumulator - virtual size_t dimension() const { + size_t dimension() const override { return accums_.size(); } @@ -446,12 +446,12 @@ class NumericalVectorGeometricMean : public VectorMean { } //! Reset accumulator - virtual void reset() { + void reset() override { this->reset(accums_.size()); } //! Plus a vector (geometric) - virtual bool plus(const void *vec, size_t len) { + bool plus(const void *vec, size_t len) override { size_t dim = accums_.size(); if (dim * sizeof(T) != len) { return false; @@ -464,7 +464,7 @@ class NumericalVectorGeometricMean : public VectorMean { } //! Retrieve the mean of vectors (geometric) - virtual bool mean(void *out, size_t len) const { + bool mean(void *out, size_t len) const override { size_t dim = accums_.size(); if (dim * sizeof(T) != len) { return false; @@ -477,7 +477,7 @@ class NumericalVectorGeometricMean : public VectorMean { } //! Retrieve the mean of vectors - virtual void mean(std::string *out) const { + void mean(std::string *out) const override { ailego::NumericalVector &vec = *static_cast *>(out); @@ -489,7 +489,7 @@ class NumericalVectorGeometricMean : public VectorMean { } //! Merge another vector mean - virtual bool merge(const VectorMean &rhs) { + bool merge(const VectorMean &rhs) override { const NumericalVectorGeometricMean &src = dynamic_cast &>(rhs); @@ -505,12 +505,12 @@ class NumericalVectorGeometricMean : public VectorMean { } //! Retrieve the count of vectors - virtual size_t count() const { + size_t count() const override { return count_; } //! Retrieve dimension of accumulator - virtual size_t dimension() const { + size_t dimension() const override { return accums_.size(); } @@ -574,12 +574,12 @@ class BinaryVectorMean : public VectorMean { } //! Reset accumulator - virtual void reset() { + void reset() override { this->reset(accums_.size()); } //! Plus a vector - virtual bool plus(const void *vec, size_t len) { + bool plus(const void *vec, size_t len) override { size_t dim = accums_.size(); if (dim != (len << 3)) { return false; @@ -596,7 +596,7 @@ class BinaryVectorMean : public VectorMean { } //! Retrieve the mean of vectors - virtual bool mean(void *out, size_t len) const { + bool mean(void *out, size_t len) const override { size_t dim = accums_.size(); if (dim != (len << 3)) { return false; @@ -614,7 +614,7 @@ class BinaryVectorMean : public VectorMean { } //! Retrieve the mean of vectors - virtual void mean(std::string *out) const { + void mean(std::string *out) const override { size_t dim = accums_.size(); out->clear(); out->resize((dim + 7) / 8); @@ -630,7 +630,7 @@ class BinaryVectorMean : public VectorMean { } //! Merge another vector mean - virtual bool merge(const VectorMean &rhs) { + bool merge(const VectorMean &rhs) override { const BinaryVectorMean &src = dynamic_cast(rhs); size_t dim = accums_.size(); @@ -645,12 +645,12 @@ class BinaryVectorMean : public VectorMean { } //! Retrieve the count of vectors - virtual size_t count() const { + size_t count() const override { return count_; } //! Retrieve dimension of accumulator - virtual size_t dimension() const { + size_t dimension() const override { return accums_.size(); } @@ -701,12 +701,12 @@ class NibbleVectorMean : public VectorMean { } //! Reset accumulator - virtual void reset() { + void reset() override { this->reset(accums_.size()); } //! Plus a vector - virtual bool plus(const void *vec, size_t len) { + bool plus(const void *vec, size_t len) override { size_t dim = accums_.size(); if (dim != (len << 1)) { return false; @@ -723,7 +723,7 @@ class NibbleVectorMean : public VectorMean { } //! Retrieve the mean of vectors - virtual bool mean(void *out, size_t len) const { + bool mean(void *out, size_t len) const override { size_t dim = accums_.size(); if (dim != (len << 1)) { return false; @@ -742,7 +742,7 @@ class NibbleVectorMean : public VectorMean { } //! Retrieve the mean of vectors - virtual void mean(std::string *out) const { + void mean(std::string *out) const override { size_t dim = accums_.size(); out->clear(); out->resize(dim >> 1); @@ -757,7 +757,7 @@ class NibbleVectorMean : public VectorMean { } //! Merge another vector mean - virtual bool merge(const VectorMean &rhs) { + bool merge(const VectorMean &rhs) override { const NibbleVectorMean &src = dynamic_cast(rhs); size_t dim = accums_.size(); @@ -772,12 +772,12 @@ class NibbleVectorMean : public VectorMean { } //! Retrieve the count of vectors - virtual size_t count() const { + size_t count() const override { return count_; } //! Retrieve dimension of accumulator - virtual size_t dimension() const { + size_t dimension() const override { return accums_.size(); } diff --git a/src/core/algorithm/diskann/diskann_builder.h b/src/core/algorithm/diskann/diskann_builder.h index dd8477e75..ec026d8d6 100644 --- a/src/core/algorithm/diskann/diskann_builder.h +++ b/src/core/algorithm/diskann/diskann_builder.h @@ -86,7 +86,7 @@ class DiskAnnBuilder : public IndexBuilder { } private: - enum BUILD_STATE { + enum BuildState { BUILD_STATE_INIT = 0, BUILD_STATE_INITED = 1, BUILD_STATE_TRAINED = 2, @@ -115,7 +115,7 @@ class DiskAnnBuilder : public IndexBuilder { std::string codebook_prefix_{""}; std::string index_path_prefix_{"./diskann"}; - BUILD_STATE state_{BUILD_STATE_INIT}; + BuildState state_{BUILD_STATE_INIT}; Stats stats_; int errcode_{0}; diff --git a/src/core/algorithm/diskann/diskann_builder_entity.h b/src/core/algorithm/diskann/diskann_builder_entity.h index ce097b3a3..75522e454 100644 --- a/src/core/algorithm/diskann/diskann_builder_entity.h +++ b/src/core/algorithm/diskann/diskann_builder_entity.h @@ -26,7 +26,7 @@ class DiskAnnBuilderEntity : public DiskAnnEntity { using Pointer = std::shared_ptr; DiskAnnBuilderEntity() = default; - virtual ~DiskAnnBuilderEntity() = default; + ~DiskAnnBuilderEntity() override = default; public: void clear(); diff --git a/src/core/algorithm/diskann/diskann_context.h b/src/core/algorithm/diskann/diskann_context.h index 514d36590..2d2107da8 100644 --- a/src/core/algorithm/diskann/diskann_context.h +++ b/src/core/algorithm/diskann/diskann_context.h @@ -57,7 +57,7 @@ class DiskAnnContext : public IndexContext, const turbo::Quantizer::Pointer &data_quantizer = nullptr); //! Destructor - virtual ~DiskAnnContext(); + ~DiskAnnContext() override; //! Create a lightweight context for reading vectors by id. static Pointer create_fetch_context(const IndexMeta &meta, diff --git a/src/core/algorithm/diskann/diskann_holder.h b/src/core/algorithm/diskann/diskann_holder.h index 874b862c3..f9d0f2d30 100644 --- a/src/core/algorithm/diskann/diskann_holder.h +++ b/src/core/algorithm/diskann/diskann_holder.h @@ -73,7 +73,7 @@ class DiskAnnIndexHolder : public IndexHolder { } //! Destructor - virtual ~Iterator() { + ~Iterator() override { if (file_.is_open()) { file_.close(); } diff --git a/src/core/algorithm/diskann/diskann_reducer.cc b/src/core/algorithm/diskann/diskann_reducer.cc index 250ec3667..fa2c4bbf9 100644 --- a/src/core/algorithm/diskann/diskann_reducer.cc +++ b/src/core/algorithm/diskann/diskann_reducer.cc @@ -38,10 +38,10 @@ int DiskAnnReducer::init(const ailego::Params ¶ms) { } reducer_file_path_ = ailego::StringHelper::Concat( - working_path_, "/", kReducerFileName, index_name); + working_path_, "/", k_reducer_file_name, index_name); - holder_file_path_ = ailego::StringHelper::Concat(working_path_, "/", - kHolderFileName, index_name); + holder_file_path_ = ailego::StringHelper::Concat( + working_path_, "/", k_holder_file_name, index_name); state_ = STATE_INITED; return 0; @@ -100,9 +100,10 @@ int DiskAnnReducer::reduce(const IndexFilter &filter) { disk_holder_->close(); } - builder_ = IndexFactory::CreateBuilder(kDiskAnnBuilderName); + builder_ = IndexFactory::CreateBuilder(k_disk_ann_builder_name); if (!builder_) { - LOG_ERROR("Create builder failed. name[%s]", kDiskAnnBuilderName.c_str()); + LOG_ERROR("Create builder failed. name[%s]", + k_disk_ann_builder_name.c_str()); return IndexError_Runtime; } diff --git a/src/core/algorithm/diskann/diskann_reducer.h b/src/core/algorithm/diskann/diskann_reducer.h index 4d78c05ad..f1cde740d 100644 --- a/src/core/algorithm/diskann/diskann_reducer.h +++ b/src/core/algorithm/diskann/diskann_reducer.h @@ -76,9 +76,9 @@ class DiskAnnReducer : public IndexReducer { Stats stats_{}; State state_{STATE_UNINITED}; - const std::string kDiskAnnBuilderName{"DiskAnnBuilder"}; - const std::string kReducerFileName{"diskann.reducer.builder."}; - const std::string kHolderFileName{"diskann.reducer.holder."}; + const std::string k_disk_ann_builder_name{"DiskAnnBuilder"}; + const std::string k_reducer_file_name{"diskann.reducer.builder."}; + const std::string k_holder_file_name{"diskann.reducer.holder."}; }; } // namespace core diff --git a/src/core/algorithm/diskann/diskann_reducer_entity.h b/src/core/algorithm/diskann/diskann_reducer_entity.h index e653d08d0..d3fd1975d 100644 --- a/src/core/algorithm/diskann/diskann_reducer_entity.h +++ b/src/core/algorithm/diskann/diskann_reducer_entity.h @@ -31,7 +31,7 @@ class DiskAnnReducerEntity : public DiskAnnEntity { public: DiskAnnReducerEntity() = default; - virtual ~DiskAnnReducerEntity() = default; + ~DiskAnnReducerEntity() override = default; int load(const IndexStorage::Pointer &container, bool check_crc); int load_segments(bool check_crc); diff --git a/src/core/algorithm/diskann/diskann_searcher.h b/src/core/algorithm/diskann/diskann_searcher.h index 0416ea4f1..a0f73850b 100644 --- a/src/core/algorithm/diskann/diskann_searcher.h +++ b/src/core/algorithm/diskann/diskann_searcher.h @@ -28,7 +28,7 @@ class DiskAnnSearcher : public IndexSearcher { public: DiskAnnSearcher(); - ~DiskAnnSearcher(); + ~DiskAnnSearcher() override; DiskAnnSearcher(const DiskAnnSearcher &) = delete; DiskAnnSearcher &operator=(const DiskAnnSearcher &) = delete; diff --git a/src/core/algorithm/diskann/diskann_searcher_entity.h b/src/core/algorithm/diskann/diskann_searcher_entity.h index 38d35ee14..b2a7bb81b 100644 --- a/src/core/algorithm/diskann/diskann_searcher_entity.h +++ b/src/core/algorithm/diskann/diskann_searcher_entity.h @@ -30,7 +30,7 @@ class DiskAnnSearcherEntity : public DiskAnnEntity { public: DiskAnnSearcherEntity() = default; - virtual ~DiskAnnSearcherEntity() = default; + ~DiskAnnSearcherEntity() override = default; public: const DiskAnnEntity::Pointer clone() const override; diff --git a/src/core/algorithm/diskann/diskann_streamer.h b/src/core/algorithm/diskann/diskann_streamer.h index 983e5235b..321992cf6 100644 --- a/src/core/algorithm/diskann/diskann_streamer.h +++ b/src/core/algorithm/diskann/diskann_streamer.h @@ -27,7 +27,7 @@ class DiskAnnStreamer : public IndexStreamer { public: DiskAnnStreamer(); - ~DiskAnnStreamer(); + ~DiskAnnStreamer() override; DiskAnnStreamer(const DiskAnnStreamer &) = delete; DiskAnnStreamer &operator=(const DiskAnnStreamer &) = delete; diff --git a/src/core/algorithm/diskann/diskann_util.h b/src/core/algorithm/diskann/diskann_util.h index a7ff1cad5..d6b5bc952 100644 --- a/src/core/algorithm/diskann/diskann_util.h +++ b/src/core/algorithm/diskann/diskann_util.h @@ -79,10 +79,10 @@ class DiskAnnUtil { } template - static inline void convert_vector_to_residual(T *data, uint32_t blocksize_, + static inline void convert_vector_to_residual(T *data, uint32_t blocksize, size_t dim, void *centroid) { const T *centroid_ptr = reinterpret_cast(centroid); - for (size_t i = 0; i < blocksize_; i++) { + for (size_t i = 0; i < blocksize; i++) { for (uint64_t d = 0; d < dim; d++) { float data_float = data[i * dim + d]; data_float -= centroid_ptr[d]; @@ -102,35 +102,35 @@ class DiskAnnUtil { } static inline uint64_t get_node_sector(uint32_t node_per_sector, - uint32_t max_nodesize_, - uint32_t sectorsize_, + uint32_t max_nodesize, + uint32_t sectorsize, diskann_id_t node_id) { return (node_per_sector > 0 ? node_id / node_per_sector - : node_id * div_round_up(max_nodesize_, sectorsize_)); + : node_id * div_round_up(max_nodesize, sectorsize)); } static inline uint32_t *offset_to_node_neighbor(uint8_t *node_buf, - uint32_t elementsize_) { - return (uint32_t *)(node_buf + elementsize_); + uint32_t elementsize) { + return (uint32_t *)(node_buf + elementsize); } static inline uint8_t *offset_to_node(uint32_t node_per_sector, - uint32_t max_nodesize_, + uint32_t max_nodesize, uint8_t *sector_buf, diskann_id_t node_id) { return sector_buf + (node_per_sector == 0 ? 0 - : (node_id % node_per_sector) * max_nodesize_); + : (node_id % node_per_sector) * max_nodesize); } static inline const uint8_t *offset_to_node_const(uint32_t node_per_sector, - uint32_t max_nodesize_, + uint32_t max_nodesize, const uint8_t *sector_buf, diskann_id_t node_id) { return sector_buf + (node_per_sector == 0 ? 0 - : (node_id % node_per_sector) * max_nodesize_); + : (node_id % node_per_sector) * max_nodesize); } //! Resolve the quantizer implementation name from a serialized quantizer diff --git a/src/core/algorithm/flat/flat_streamer_entity.cc b/src/core/algorithm/flat/flat_streamer_entity.cc index 6f0e5ac86..a85299bcd 100644 --- a/src/core/algorithm/flat/flat_streamer_entity.cc +++ b/src/core/algorithm/flat/flat_streamer_entity.cc @@ -840,7 +840,7 @@ int FlatStreamerEntity::init_storage(IndexStorage::Pointer storage) { meta_.header.index_meta_size = str.size(); meta_.header.linear_list_count = 1; - AdjustSegmentSize(&meta_); + adjust_segment_size(&meta_); LOG_DEBUG( "Create Streamer Index, VecSize=%u, BlockSize=%u SegmentSize=%u " @@ -906,7 +906,7 @@ int FlatStreamerEntity::init_storage(IndexStorage::Pointer storage) { } int FlatStreamerEntity::load_linear_meta(IndexStorage::Pointer storage) { - AdjustSegmentSize(&meta_); + adjust_segment_size(&meta_); // Load Meta Segment auto segment = storage->get(FLAT_LINEAR_META_SEG_ID); diff --git a/src/core/algorithm/flat/flat_streamer_entity.h b/src/core/algorithm/flat/flat_streamer_entity.h index 80f4e01ac..79880d34d 100644 --- a/src/core/algorithm/flat/flat_streamer_entity.h +++ b/src/core/algorithm/flat/flat_streamer_entity.h @@ -313,7 +313,7 @@ class FlatStreamerEntity { } //! Rejust the segment size as to aligned by page size - void AdjustSegmentSize(StreamerLinearMeta *mt) { + void adjust_segment_size(StreamerLinearMeta *mt) { if (mt->segment_size < mt->header.block_size) { mt->segment_size = mt->header.block_size; } diff --git a/src/core/algorithm/flat/flat_utility.h b/src/core/algorithm/flat/flat_utility.h index e6f18b3cc..4020c8c9a 100644 --- a/src/core/algorithm/flat/flat_utility.h +++ b/src/core/algorithm/flat/flat_utility.h @@ -81,10 +81,10 @@ static inline void ReverseTranspose(size_t align_size, const void *src, } template -static inline void TransposeOne(const void *src, size_t M, size_t N, +static inline void TransposeOne(const void *src, size_t m, size_t n, void *dst) { - for (size_t i = 0; i < N; ++i) { - reinterpret_cast(dst)[i] = reinterpret_cast(src)[i * M]; + for (size_t i = 0; i < n; ++i) { + reinterpret_cast(dst)[i] = reinterpret_cast(src)[i * m]; } } diff --git a/src/core/algorithm/flat_sparse/flat_sparse_builder.h b/src/core/algorithm/flat_sparse/flat_sparse_builder.h index 58a102772..ded9d9f96 100644 --- a/src/core/algorithm/flat_sparse/flat_sparse_builder.h +++ b/src/core/algorithm/flat_sparse/flat_sparse_builder.h @@ -81,7 +81,7 @@ class FlatSparseBuilder : public IndexBuilder { IndexDumper *dumper, uint32_t *length); private: - enum BUILD_STATE { + enum BuildState { BUILD_STATE_INIT = 0, BUILD_STATE_INITED = 1, BUILD_STATE_TRAINED = 2, @@ -97,7 +97,7 @@ class FlatSparseBuilder : public IndexBuilder { std::condition_variable cond_{}; Stats stats_{}; - BUILD_STATE state_{BUILD_STATE_INIT}; + BuildState state_{BUILD_STATE_INIT}; }; diff --git a/src/core/algorithm/hnsw/hnsw_algorithm.cc b/src/core/algorithm/hnsw/hnsw_algorithm.cc index e0ac23e38..7be9c443c 100644 --- a/src/core/algorithm/hnsw/hnsw_algorithm.cc +++ b/src/core/algorithm/hnsw/hnsw_algorithm.cc @@ -72,7 +72,7 @@ int HnswAlgorithm::add_node(node_id_t id, level_t level, template int HnswAlgorithm::search(HnswContext *ctx) const { spin_lock_.lock(); - auto maxLevel = entity_.cur_max_level(); + auto max_level = entity_.cur_max_level(); auto entry_point = entity_.entry_point(); spin_lock_.unlock(); @@ -81,7 +81,7 @@ int HnswAlgorithm::search(HnswContext *ctx) const { } dist_t dist = ctx->dist_calculator().dist(entry_point); - for (level_t cur_level = maxLevel; cur_level >= 1; --cur_level) { + for (level_t cur_level = max_level; cur_level >= 1; --cur_level) { select_entry_point(cur_level, &entry_point, &dist, ctx); } diff --git a/src/core/algorithm/hnsw/hnsw_chunk.cc b/src/core/algorithm/hnsw/hnsw_chunk.cc index a9cf52578..e283bdd6f 100644 --- a/src/core/algorithm/hnsw/hnsw_chunk.cc +++ b/src/core/algorithm/hnsw/hnsw_chunk.cc @@ -109,7 +109,7 @@ int ChunkBroker::open(IndexStorage::Pointer stg, uint32_t &chunk_size, return IndexError_Duplicate; } stg_ = std::move(stg); - if (stg_->isHugePage()) { + if (stg_->is_huge_page()) { page_mask_ = ailego::MemoryHelper::HugePageSize() - 1; } else { page_mask_ = ailego::MemoryHelper::PageSize() - 1; diff --git a/src/core/algorithm/hnsw/hnsw_chunk.h b/src/core/algorithm/hnsw/hnsw_chunk.h index c58f6baf9..d4a5e9c5c 100644 --- a/src/core/algorithm/hnsw/hnsw_chunk.h +++ b/src/core/algorithm/hnsw/hnsw_chunk.h @@ -35,7 +35,7 @@ class ChunkBroker { public: typedef std::shared_ptr Pointer; - enum CHUNK_TYPE { + enum ChunkType { CHUNK_TYPE_HEADER = 1, CHUNK_TYPE_META = 2, CHUNK_TYPE_NODE = 3, diff --git a/src/core/algorithm/hnsw/hnsw_streamer_entity.cc b/src/core/algorithm/hnsw/hnsw_streamer_entity.cc index 6afa99c11..b15ba977d 100644 --- a/src/core/algorithm/hnsw/hnsw_streamer_entity.cc +++ b/src/core/algorithm/hnsw/hnsw_streamer_entity.cc @@ -373,7 +373,7 @@ int HnswStreamerEntity::init_chunks(const Chunk::Pointer &header_chunk) { int HnswStreamerEntity::open(IndexStorage::Pointer stg, uint64_t max_index_size, bool check_crc) { std::lock_guard lock(mutex_); - bool huge_page = stg->isHugePage(); + bool huge_page = stg->is_huge_page(); LOG_DEBUG("huge_page: %d", (int)huge_page); int ret = broker_->open(std::move(stg), chunk_size_, check_crc); if (ailego_unlikely(ret != 0)) { diff --git a/src/core/algorithm/hnsw/hnsw_streamer_entity.h b/src/core/algorithm/hnsw/hnsw_streamer_entity.h index c09190e90..356bd6c2b 100644 --- a/src/core/algorithm/hnsw/hnsw_streamer_entity.h +++ b/src/core/algorithm/hnsw/hnsw_streamer_entity.h @@ -112,7 +112,7 @@ class HnswStreamerEntity : public HnswEntity { HnswStreamerEntity(IndexStreamer::Stats &stats); //! Destructor - ~HnswStreamerEntity(); + ~HnswStreamerEntity() override; //! Get vector feature data by key const void *get_vector_by_key(key_t key) const override { @@ -299,7 +299,7 @@ class HnswStreamerEntity : public HnswEntity { } //! Called only in searching procedure per context, so no need to lock - void sync_chunks(ChunkBroker::CHUNK_TYPE type, size_t idx, + void sync_chunks(ChunkBroker::ChunkType type, size_t idx, std::vector *chunks) const { if (ailego_likely(idx < chunks->size())) { return; @@ -967,7 +967,7 @@ class HnswContiguousStreamerEntity : public HnswMmapStreamerEntity { //! Cloned entity shares contiguous memory via shared_ptr. const HnswEntity::Pointer clone() const override; - ~HnswContiguousStreamerEntity() = default; + ~HnswContiguousStreamerEntity() override = default; //! Build contiguous memory from chunks after open. //! Must be called after the entity is fully opened and all chunks are loaded. diff --git a/src/core/algorithm/hnsw_sparse/hnsw_sparse_algorithm.cc b/src/core/algorithm/hnsw_sparse/hnsw_sparse_algorithm.cc index a8e20ac3f..13671d12e 100644 --- a/src/core/algorithm/hnsw_sparse/hnsw_sparse_algorithm.cc +++ b/src/core/algorithm/hnsw_sparse/hnsw_sparse_algorithm.cc @@ -85,7 +85,7 @@ int HnswSparseAlgorithm::add_node(node_id_t id, level_t level, int HnswSparseAlgorithm::search(HnswSparseContext *ctx) const { spin_lock_.lock(); - auto maxLevel = entity_.cur_max_level(); + auto max_level = entity_.cur_max_level(); auto entry_point = entity_.entry_point(); spin_lock_.unlock(); @@ -94,7 +94,7 @@ int HnswSparseAlgorithm::search(HnswSparseContext *ctx) const { } dist_t dist = ctx->dist_calculator().dist(entry_point); - for (level_t cur_level = maxLevel; cur_level >= 1; --cur_level) { + for (level_t cur_level = max_level; cur_level >= 1; --cur_level) { select_entry_point(cur_level, &entry_point, &dist, ctx); } diff --git a/src/core/algorithm/hnsw_sparse/hnsw_sparse_builder.h b/src/core/algorithm/hnsw_sparse/hnsw_sparse_builder.h index b16ec4dd2..a69cb8c07 100644 --- a/src/core/algorithm/hnsw_sparse/hnsw_sparse_builder.h +++ b/src/core/algorithm/hnsw_sparse/hnsw_sparse_builder.h @@ -70,7 +70,7 @@ class HnswSparseBuilder : public IndexBuilder { constexpr static uint32_t kMaxNeighborCnt = 65535; private: - enum BUILD_STATE { + enum BuildState { BUILD_STATE_INIT = 0, BUILD_STATE_INITED = 1, BUILD_STATE_TRAINED = 2, @@ -96,7 +96,7 @@ class HnswSparseBuilder : public IndexBuilder { std::condition_variable cond_{}; Stats stats_{}; - BUILD_STATE state_{BUILD_STATE_INIT}; + BuildState state_{BUILD_STATE_INIT}; }; } // namespace core diff --git a/src/core/algorithm/hnsw_sparse/hnsw_sparse_chunk.h b/src/core/algorithm/hnsw_sparse/hnsw_sparse_chunk.h index dda1b9849..dc1f1b079 100644 --- a/src/core/algorithm/hnsw_sparse/hnsw_sparse_chunk.h +++ b/src/core/algorithm/hnsw_sparse/hnsw_sparse_chunk.h @@ -35,7 +35,7 @@ class SparseChunkBroker { public: typedef std::shared_ptr Pointer; - enum CHUNK_TYPE { + enum ChunkType { CHUNK_TYPE_HEADER = 1, CHUNK_TYPE_META = 2, CHUNK_TYPE_NODE = 3, diff --git a/src/core/algorithm/hnsw_sparse/hnsw_sparse_streamer_entity.h b/src/core/algorithm/hnsw_sparse/hnsw_sparse_streamer_entity.h index eaa1085e3..35e16c35f 100644 --- a/src/core/algorithm/hnsw_sparse/hnsw_sparse_streamer_entity.h +++ b/src/core/algorithm/hnsw_sparse/hnsw_sparse_streamer_entity.h @@ -126,7 +126,7 @@ class HnswSparseStreamerEntity : public HnswSparseEntity { HnswSparseStreamerEntity(IndexStreamer::Stats &stats); //! Destructor - ~HnswSparseStreamerEntity(); + ~HnswSparseStreamerEntity() override; //! Init entity int init(uint64_t max_index_size, size_t max_doc_cnt); @@ -263,7 +263,7 @@ class HnswSparseStreamerEntity : public HnswSparseEntity { } //! Called only in searching procedure per context, so no need to lock - void sync_chunks(SparseChunkBroker::CHUNK_TYPE type, size_t idx, + void sync_chunks(SparseChunkBroker::ChunkType type, size_t idx, std::vector *chunks) const { if (ailego_likely(idx < chunks->size())) { return; diff --git a/src/core/algorithm/ivf/ivf_builder.cc b/src/core/algorithm/ivf/ivf_builder.cc index 6d2352669..90c0ba995 100644 --- a/src/core/algorithm/ivf/ivf_builder.cc +++ b/src/core/algorithm/ivf/ivf_builder.cc @@ -479,7 +479,7 @@ int IVFBuilder::dump(const IndexDumper::Pointer &dumper) { return 0; } -int IVFBuilder::CheckAndUpdateMajorOrder(IndexMeta &meta) { +int IVFBuilder::check_and_update_major_order(IndexMeta &meta) { const std::string &metric_name = meta.metric_name(); auto metric = IndexFactory::CreateMetric(metric_name); if (!metric) { @@ -729,7 +729,7 @@ int IVFBuilder::dump_index(const IndexDumper::Pointer &dumper) { source_reader_->reset(); } }); - int ret = CheckAndUpdateMajorOrder(quantized_meta_); + int ret = check_and_update_major_order(quantized_meta_); ivf_check_error_code(ret); IVFDumper::Pointer ivf_dumper = std::make_shared( diff --git a/src/core/algorithm/ivf/ivf_builder.h b/src/core/algorithm/ivf/ivf_builder.h index fda20aec6..4fad12707 100644 --- a/src/core/algorithm/ivf/ivf_builder.h +++ b/src/core/algorithm/ivf/ivf_builder.h @@ -209,7 +209,7 @@ class IVFBuilder : public IndexBuilder { using VectorList = std::vector; //! Check MajorOrder in meta, and update the major order if needed - int CheckAndUpdateMajorOrder(IndexMeta &meta); + int check_and_update_major_order(IndexMeta &meta); //! Parse params int parse_centroids_num(const ailego::Params ¶ms); diff --git a/src/core/algorithm/ivf/ivf_distance_calculator.cc b/src/core/algorithm/ivf/ivf_distance_calculator.cc index f0c731c10..198f1c0bd 100644 --- a/src/core/algorithm/ivf/ivf_distance_calculator.cc +++ b/src/core/algorithm/ivf/ivf_distance_calculator.cc @@ -22,7 +22,7 @@ IVFDistanceCalculator::IVFDistanceCalculator(const IndexMeta &meta, uint32_t block_vec_cnt) : metric_ptr_(metric), block_vec_cnt_(block_vec_cnt) { row_distance_ = metric->distance(); - distanceXx1_ = metric->distance_matrix(block_vec_cnt, 1); + distance_xx1 = metric->distance_matrix(block_vec_cnt, 1); distances_.resize(33); for (size_t b = 32; b != 0; b /= 2) { distances_[b] = metric->distance_matrix(block_vec_cnt, b); @@ -38,7 +38,7 @@ IVFDistanceCalculator::IVFDistanceCalculator(const IndexMeta &meta, IVFDistanceCalculator::~IVFDistanceCalculator() { row_distance_ = nullptr; - distanceXx1_ = nullptr; + distance_xx1 = nullptr; distances_.clear(); } diff --git a/src/core/algorithm/ivf/ivf_distance_calculator.h b/src/core/algorithm/ivf/ivf_distance_calculator.h index 17a075dd4..458f8e029 100644 --- a/src/core/algorithm/ivf/ivf_distance_calculator.h +++ b/src/core/algorithm/ivf/ivf_distance_calculator.h @@ -61,7 +61,7 @@ class IVFDistanceCalculator { protected: IndexMetric::Pointer metric_ptr_{}; IndexMetric::MatrixDistance row_distance_{nullptr}; - IndexMetric::MatrixDistance distanceXx1_{nullptr}; + IndexMetric::MatrixDistance distance_xx1{nullptr}; std::vector distances_{}; size_t element_size_{0}; @@ -122,7 +122,7 @@ void IVFDistanceCalculator::query_features_distance(const void *query, float *distances) { if (column_major_order_) { if (fnum == block_vec_cnt_) { - distanceXx1_(feature, query, dimension_, distances); + distance_xx1(feature, query, dimension_, distances); } else { this->row_major_distance(query, feature, fnum, distances); } @@ -138,7 +138,7 @@ void IVFDistanceCalculator::query_features_distance(const void *query, float *distances) { if (column_major) { ailego_assert_with(fnum == block_vec_cnt_, "Invalid Block"); - distanceXx1_(feature, query, dimension_, distances); + distance_xx1(feature, query, dimension_, distances); } else { this->row_major_distance(query, feature, fnum, distances); } diff --git a/src/core/algorithm/ivf/ivf_utility.h b/src/core/algorithm/ivf/ivf_utility.h index e7d213194..9586b445f 100644 --- a/src/core/algorithm/ivf/ivf_utility.h +++ b/src/core/algorithm/ivf/ivf_utility.h @@ -127,10 +127,10 @@ class IVFUtility { //! Transpose one vector in block template - static inline void TransposeOne(const void *src, size_t M, size_t N, + static inline void TransposeOne(const void *src, size_t m, size_t n, void *dst) { - for (size_t i = 0; i < N; ++i) { - reinterpret_cast(dst)[i] = reinterpret_cast(src)[i * M]; + for (size_t i = 0; i < n; ++i) { + reinterpret_cast(dst)[i] = reinterpret_cast(src)[i * m]; } } }; diff --git a/src/core/algorithm/vamana/vamana_streamer_entity.cc b/src/core/algorithm/vamana/vamana_streamer_entity.cc index cdfe90af2..69df86103 100644 --- a/src/core/algorithm/vamana/vamana_streamer_entity.cc +++ b/src/core/algorithm/vamana/vamana_streamer_entity.cc @@ -341,7 +341,7 @@ void VamanaStreamerEntity::update_entry_point(node_id_t ep) { int VamanaStreamerEntity::open(IndexStorage::Pointer stg, uint64_t max_index_size, bool check_crc) { std::lock_guard lock(mutex_); - bool huge_page = stg->isHugePage(); + bool huge_page = stg->is_huge_page(); int ret = broker_->open(std::move(stg), chunk_size_, check_crc); if (ailego_unlikely(ret != 0)) { diff --git a/src/core/algorithm/vamana/vamana_streamer_entity.h b/src/core/algorithm/vamana/vamana_streamer_entity.h index 86d0bcaf7..26b78e638 100644 --- a/src/core/algorithm/vamana/vamana_streamer_entity.h +++ b/src/core/algorithm/vamana/vamana_streamer_entity.h @@ -93,7 +93,7 @@ class VamanaStreamerEntity : public VamanaEntity { public: VamanaStreamerEntity(IndexStreamer::Stats &stats); - ~VamanaStreamerEntity(); + ~VamanaStreamerEntity() override; const void *get_vector_by_key(key_t key) const override { auto id = get_id(key); @@ -202,7 +202,7 @@ class VamanaStreamerEntity : public VamanaEntity { //! Lazy chunk synchronization: fetches chunks from broker when needed. //! Protected by node_chunks_mutex_ to synchronize with add_vector's //! emplace_back during concurrent build. - void sync_chunks(ChunkBroker::CHUNK_TYPE type, size_t idx, + void sync_chunks(ChunkBroker::ChunkType type, size_t idx, std::vector *chunks) const { if (ailego_likely(idx < chunks->size())) { return; @@ -619,7 +619,7 @@ class VamanaContiguousStreamerEntity : public VamanaMmapStreamerEntity { //! Cloned entity shares contiguous memory via shared_ptr. const VamanaEntity::Pointer clone() const override; - ~VamanaContiguousStreamerEntity() = default; + ~VamanaContiguousStreamerEntity() override = default; // Build contiguous memory from chunks after open. int build_contiguous_memory(); diff --git a/src/core/framework/index_mapping.cc b/src/core/framework/index_mapping.cc index 6094ec9b6..b5c793d9c 100644 --- a/src/core/framework/index_mapping.cc +++ b/src/core/framework/index_mapping.cc @@ -91,7 +91,7 @@ int IndexMapping::open(const std::string &path, bool cow, bool full_mode) { path_ = path; full_mode_ = full_mode; copy_on_write_ = cow; - huge_page_ = Ishugetlbfs(path); + huge_page_ = ishugetlbfs(path); bool read_only = copy_on_write_ && !full_mode_; if (!file_.open(path.c_str(), read_only, false)) { @@ -126,7 +126,7 @@ int IndexMapping::create(const std::string &path, size_t seg_meta_capacity) { ailego::FileHelper::GetLastErrorString().c_str()); return IndexError_CreateFile; } - huge_page_ = Ishugetlbfs(path); + huge_page_ = ishugetlbfs(path); if (huge_page_) { return init_hugepage_meta_section(); } @@ -599,7 +599,7 @@ int IndexMapping::init_index_mapping(size_t len) { return 0; } -bool IndexMapping::Ishugetlbfs(const std::string &path) const { +bool IndexMapping::ishugetlbfs(const std::string &path) const { #ifdef __linux__ struct statfs buf; if (statfs(path.c_str(), &buf) != 0) { diff --git a/src/core/interface/index.cc b/src/core/interface/index.cc index b142a62d8..2ceb13bf9 100644 --- a/src/core/interface/index.cc +++ b/src/core/interface/index.cc @@ -183,14 +183,14 @@ int CreateReformerFromConverterMeta( // eliminate the pre-alloc of the context pool thread_local static std::array() - 1) * 2> - _context_list; + context_list; bool Index::init_context() { context_index_ = (magic_enum::enum_integer(param_.index_type) - 1) * 2 + static_cast(is_sparse_); - if (_context_list[context_index_] == nullptr) { - if ((_context_list[context_index_] = streamer_->create_context()) == + if (context_list[context_index_] == nullptr) { + if ((context_list[context_index_] = streamer_->create_context()) == nullptr) { LOG_ERROR("Failed to create context"); return false; @@ -201,7 +201,7 @@ bool Index::init_context() { core::IndexContext::Pointer &Index::acquire_context() { init_context(); - return _context_list[context_index_]; + return context_list[context_index_]; } int Index::train() { @@ -235,7 +235,7 @@ core::IndexProvider::Pointer Index::create_index_provider() const { return streamer_->create_provider(); } -int Index::ParseMetricName(const BaseIndexParam ¶m) { +int Index::parse_metric_name(const BaseIndexParam ¶m) { std::string metric_name; if (is_sparse_) { // only inner product is supported for sparse index @@ -275,7 +275,7 @@ int Index::ParseMetricName(const BaseIndexParam ¶m) { return 0; } -int Index::CreateAndInitMetric(const BaseIndexParam & /*param*/) { +int Index::create_and_init_metric(const BaseIndexParam & /*param*/) { auto &metric_name = proxima_index_meta_.metric_name(); metric_ = core::IndexFactory::CreateMetric(metric_name); @@ -297,8 +297,8 @@ int Index::CreateAndInitMetric(const BaseIndexParam & /*param*/) { return core::IndexError_Success; } -int Index::CreateAndInitConverterReformer(const QuantizerParam ¶m, - const BaseIndexParam &index_param) { +int Index::create_and_init_converter_reformer( + const QuantizerParam ¶m, const BaseIndexParam &index_param) { ailego::Params converter_params; std::string converter_name; if (is_sparse_) { @@ -396,11 +396,11 @@ int Index::CreateAndInitConverterReformer(const QuantizerParam ¶m, } } - return InitConverterReformer(converter_name, converter_params); + return init_converter_reformer(converter_name, converter_params); } -int Index::InitConverterReformer(const std::string &converter_name, - const ailego::Params &converter_params) { +int Index::init_converter_reformer(const std::string &converter_name, + const ailego::Params &converter_params) { proxima_index_meta_.set_converter(converter_name, 0, converter_params); converter_ = core::IndexFactory::CreateConverter(converter_name); if (converter_ == nullptr || @@ -428,7 +428,7 @@ int Index::InitConverterReformer(const std::string &converter_name, return core::IndexError_Success; } -int Index::Init(const BaseIndexParam ¶m) { +int Index::init(const BaseIndexParam ¶m) { param_ = param; // will lose the original type info is_sparse_ = param.is_sparse; @@ -446,7 +446,7 @@ int Index::Init(const BaseIndexParam ¶m) { // when quantizer=int8/int4, the converter.init() will change the metric to // QuantizedInteger with params - if (ParseMetricName(param) != 0) { + if (parse_metric_name(param) != 0) { LOG_ERROR("Failed to parse metric name"); return core::IndexError_Runtime; } @@ -455,20 +455,20 @@ int Index::Init(const BaseIndexParam ¶m) { const auto quantizer_param = param.quantizer_param ? param.quantizer_param : std::make_shared(); - if (CreateAndInitConverterReformer(*quantizer_param, param) != 0) { + if (create_and_init_converter_reformer(*quantizer_param, param) != 0) { LOG_ERROR("Failed to create and init converter"); return core::IndexError_Runtime; } // must after quantizer handled. e.g., cosine doesn't support int8 quantizer if (turbo_quantizer_ == nullptr) { - if (CreateAndInitMetric(param) != 0) { + if (create_and_init_metric(param) != 0) { LOG_ERROR("Failed to create and init metric"); return core::IndexError_Runtime; } } - if (CreateAndInitStreamer(param) != 0) { + if (create_and_init_streamer(param) != 0) { LOG_ERROR("Failed to create and init streamer"); return core::IndexError_Runtime; } diff --git a/src/core/interface/index_factory.cc b/src/core/interface/index_factory.cc index 77ad33764..4b02884f5 100644 --- a/src/core/interface/index_factory.cc +++ b/src/core/interface/index_factory.cc @@ -64,7 +64,7 @@ Index::Pointer IndexFactory::CreateAndInitIndex(const BaseIndexParam ¶m) { LOG_ERROR("Failed to create index"); return nullptr; } - if (0 != ptr->Init(param)) { + if (0 != ptr->init(param)) { LOG_ERROR("Failed to init index"); return nullptr; } diff --git a/src/core/interface/index_param.cc b/src/core/interface/index_param.cc index c0edf8a6b..2418aed35 100644 --- a/src/core/interface/index_param.cc +++ b/src/core/interface/index_param.cc @@ -89,8 +89,10 @@ IVFQueryParam::~IVFQueryParam() = default; BaseIndexQueryParam::Pointer IVFQueryParam::clone() const { auto cloned_this = std::make_shared(*this); - cloned_this->l1QueryParam = l1QueryParam ? l1QueryParam->clone() : nullptr; - cloned_this->l2QueryParam = l2QueryParam ? l2QueryParam->clone() : nullptr; + cloned_this->l1_query_param = + l1_query_param ? l1_query_param->clone() : nullptr; + cloned_this->l2_query_param = + l2_query_param ? l2_query_param->clone() : nullptr; return cloned_this; } @@ -116,21 +118,21 @@ BaseIndexParam::~BaseIndexParam() = default; IVFIndexParam::IVFIndexParam() : BaseIndexParam(IndexType::kIVF) {} IVFIndexParam::IVFIndexParam(int nlist, int niters, - std::shared_ptr l1Index, - std::shared_ptr l2Index) + std::shared_ptr l1_index, + std::shared_ptr l2_index) : BaseIndexParam(IndexType::kIVF), nlist(nlist), niters(niters), - l1Index(std::move(l1Index)), - l2Index(std::move(l2Index)) {} + l1_index(std::move(l1_index)), + l2_index(std::move(l2_index)) {} IVFIndexParam::IVFIndexParam(MetricType metric, int dim, int nlist, int niters, - std::shared_ptr l1Index, - std::shared_ptr l2Index) + std::shared_ptr l1_index, + std::shared_ptr l2_index) : BaseIndexParam(IndexType::kIVF, metric, dim), nlist(nlist), niters(niters), - l1Index(std::move(l1Index)), - l2Index(std::move(l2Index)) {} + l1_index(std::move(l1_index)), + l2_index(std::move(l2_index)) {} IVFIndexParam::IVFIndexParam(const IVFIndexParam &) = default; IVFIndexParam::IVFIndexParam(IVFIndexParam &&) = default; IVFIndexParam &IVFIndexParam::operator=(const IVFIndexParam &) = default; @@ -175,7 +177,7 @@ IVFRabitqIndexParam &IVFRabitqIndexParam::operator=(IVFRabitqIndexParam &&) = default; IVFRabitqIndexParam::~IVFRabitqIndexParam() = default; -ailego::JsonObject BaseIndexParam::SerializeToJsonObject( +ailego::JsonObject BaseIndexParam::serialize_to_json_object( bool omit_empty_value) const { ailego::JsonObject json_obj; @@ -216,12 +218,12 @@ ailego::JsonObject BaseIndexParam::SerializeToJsonObject( if (quantizer_param) { if (!omit_empty_value || quantizer_param->type != QuantizerType::kNone) { json_obj.set("quantizer_param", - quantizer_param->SerializeToJsonObject(omit_empty_value)); + quantizer_param->serialize_to_json_object(omit_empty_value)); } } else if (!omit_empty_value) { // no quantizer configured, keep the default(kNone) object as before json_obj.set("quantizer_param", - QuantizerParam().SerializeToJsonObject(false)); + QuantizerParam().serialize_to_json_object(false)); } // if (refiner_param) { // json.set("refiner_param", refiner_param->serialize_to_json()); @@ -234,9 +236,9 @@ ailego::JsonObject BaseIndexParam::SerializeToJsonObject( } -ailego::JsonObject FlatIndexParam::SerializeToJsonObject( +ailego::JsonObject FlatIndexParam::serialize_to_json_object( bool omit_empty_value) const { - auto json_obj = BaseIndexParam::SerializeToJsonObject(omit_empty_value); + auto json_obj = BaseIndexParam::serialize_to_json_object(omit_empty_value); if (!omit_empty_value || major_order != IndexMeta::MajorOrder::MO_UNDEFINED) { json_obj.set("major_order", ailego::JsonValue(magic_enum::enum_name(major_order).data())); @@ -253,9 +255,9 @@ ailego::JsonObject FlatIndexParam::SerializeToJsonObject( return json_obj; } -ailego::JsonObject HNSWIndexParam::SerializeToJsonObject( +ailego::JsonObject HNSWIndexParam::serialize_to_json_object( bool omit_empty_value) const { - auto json_obj = BaseIndexParam::SerializeToJsonObject(omit_empty_value); + auto json_obj = BaseIndexParam::serialize_to_json_object(omit_empty_value); json_obj.set("m", ailego::JsonValue(m)); json_obj.set("ef_construction", ailego::JsonValue(ef_construction)); if (!omit_empty_value || use_contiguous_memory) { @@ -265,7 +267,7 @@ ailego::JsonObject HNSWIndexParam::SerializeToJsonObject( return json_obj; } -bool BaseIndexParam::DeserializeFromJsonObject( +bool BaseIndexParam::deserialize_from_json_object( const ailego::JsonObject &json_obj) { DESERIALIZE_ENUM_FIELD(json_obj, index_type, IndexType); DESERIALIZE_ENUM_FIELD(json_obj, metric_type, MetricType); @@ -292,7 +294,7 @@ bool BaseIndexParam::DeserializeFromJsonObject( return false; } auto quantizer = QuantizerParam::Create(quantizer_type); - if (!quantizer->DeserializeFromJsonObject(quantizer_json_obj)) { + if (!quantizer->deserialize_from_json_object(quantizer_json_obj)) { LOG_ERROR("Error when deserialize json - field:quantizer_param"); } quantizer_param = std::move(quantizer); @@ -302,9 +304,9 @@ bool BaseIndexParam::DeserializeFromJsonObject( return true; } -bool FlatIndexParam::DeserializeFromJsonObject( +bool FlatIndexParam::deserialize_from_json_object( const ailego::JsonObject &json_obj) { - if (!BaseIndexParam::DeserializeFromJsonObject(json_obj)) { + if (!BaseIndexParam::deserialize_from_json_object(json_obj)) { return false; } @@ -319,9 +321,9 @@ bool FlatIndexParam::DeserializeFromJsonObject( return true; } -bool HNSWIndexParam::DeserializeFromJsonObject( +bool HNSWIndexParam::deserialize_from_json_object( const ailego::JsonObject &json_obj) { - if (!BaseIndexParam::DeserializeFromJsonObject(json_obj)) { + if (!BaseIndexParam::deserialize_from_json_object(json_obj)) { return false; } @@ -337,9 +339,9 @@ bool HNSWIndexParam::DeserializeFromJsonObject( return true; } -bool HNSWRabitqIndexParam::DeserializeFromJsonObject( +bool HNSWRabitqIndexParam::deserialize_from_json_object( const ailego::JsonObject &json_obj) { - if (!BaseIndexParam::DeserializeFromJsonObject(json_obj)) { + if (!BaseIndexParam::deserialize_from_json_object(json_obj)) { return false; } @@ -357,9 +359,9 @@ bool HNSWRabitqIndexParam::DeserializeFromJsonObject( return true; } -ailego::JsonObject HNSWRabitqIndexParam::SerializeToJsonObject( +ailego::JsonObject HNSWRabitqIndexParam::serialize_to_json_object( bool omit_empty_value) const { - auto json_obj = BaseIndexParam::SerializeToJsonObject(omit_empty_value); + auto json_obj = BaseIndexParam::serialize_to_json_object(omit_empty_value); json_obj.set("m", ailego::JsonValue(m)); json_obj.set("ef_construction", ailego::JsonValue(ef_construction)); json_obj.set("total_bits", ailego::JsonValue(total_bits)); @@ -370,9 +372,9 @@ ailego::JsonObject HNSWRabitqIndexParam::SerializeToJsonObject( return json_obj; } -bool IVFRabitqIndexParam::DeserializeFromJsonObject( +bool IVFRabitqIndexParam::deserialize_from_json_object( const ailego::JsonObject &json_obj) { - if (!BaseIndexParam::DeserializeFromJsonObject(json_obj)) { + if (!BaseIndexParam::deserialize_from_json_object(json_obj)) { return false; } @@ -388,9 +390,9 @@ bool IVFRabitqIndexParam::DeserializeFromJsonObject( return true; } -ailego::JsonObject IVFRabitqIndexParam::SerializeToJsonObject( +ailego::JsonObject IVFRabitqIndexParam::serialize_to_json_object( bool omit_empty_value) const { - auto json_obj = BaseIndexParam::SerializeToJsonObject(omit_empty_value); + auto json_obj = BaseIndexParam::serialize_to_json_object(omit_empty_value); json_obj.set("nlist", ailego::JsonValue(nlist)); json_obj.set("total_bits", ailego::JsonValue(total_bits)); if (!omit_empty_value || sample_count != 0) { @@ -399,9 +401,9 @@ ailego::JsonObject IVFRabitqIndexParam::SerializeToJsonObject( return json_obj; } -ailego::JsonObject VamanaIndexParam::SerializeToJsonObject( +ailego::JsonObject VamanaIndexParam::serialize_to_json_object( bool omit_empty_value) const { - auto json_obj = BaseIndexParam::SerializeToJsonObject(omit_empty_value); + auto json_obj = BaseIndexParam::serialize_to_json_object(omit_empty_value); json_obj.set("max_degree", ailego::JsonValue(max_degree)); json_obj.set("search_list_size", ailego::JsonValue(search_list_size)); json_obj.set("alpha", ailego::JsonValue(alpha)); @@ -422,9 +424,9 @@ ailego::JsonObject VamanaIndexParam::SerializeToJsonObject( return json_obj; } -bool DiskAnnIndexParam::DeserializeFromJsonObject( +bool DiskAnnIndexParam::deserialize_from_json_object( const ailego::JsonObject &json_obj) { - if (!BaseIndexParam::DeserializeFromJsonObject(json_obj)) { + if (!BaseIndexParam::deserialize_from_json_object(json_obj)) { return false; } @@ -440,18 +442,18 @@ bool DiskAnnIndexParam::DeserializeFromJsonObject( return true; } -ailego::JsonObject DiskAnnIndexParam::SerializeToJsonObject( +ailego::JsonObject DiskAnnIndexParam::serialize_to_json_object( bool omit_empty_value) const { - auto json_obj = BaseIndexParam::SerializeToJsonObject(omit_empty_value); + auto json_obj = BaseIndexParam::serialize_to_json_object(omit_empty_value); json_obj.set("max_degree", ailego::JsonValue(max_degree)); json_obj.set("list_size", ailego::JsonValue(list_size)); json_obj.set("pq_chunk_num", ailego::JsonValue(pq_chunk_num)); return json_obj; } -bool VamanaIndexParam::DeserializeFromJsonObject( +bool VamanaIndexParam::deserialize_from_json_object( const ailego::JsonObject &json_obj) { - if (!BaseIndexParam::DeserializeFromJsonObject(json_obj)) { + if (!BaseIndexParam::deserialize_from_json_object(json_obj)) { return false; } @@ -471,7 +473,7 @@ bool VamanaIndexParam::DeserializeFromJsonObject( return true; } -ailego::JsonObject QuantizerParam::SerializeToJsonObject( +ailego::JsonObject QuantizerParam::serialize_to_json_object( bool omit_empty_value) const { ailego::JsonObject json_obj; if (!omit_empty_value || type != QuantizerType::kNone) { @@ -484,7 +486,7 @@ ailego::JsonObject QuantizerParam::SerializeToJsonObject( return json_obj; } -bool QuantizerParam::DeserializeFromJsonObject( +bool QuantizerParam::deserialize_from_json_object( const ailego::JsonObject &json_obj) { DESERIALIZE_ENUM_FIELD(json_obj, type, QuantizerType); DESERIALIZE_VALUE_FIELD(json_obj, enable_rotate); @@ -500,17 +502,17 @@ QuantizerParam::Pointer QuantizerParam::Create(QuantizerType t) { } } -ailego::JsonObject PqQuantizerParam::SerializeToJsonObject( +ailego::JsonObject PqQuantizerParam::serialize_to_json_object( bool omit_empty_value) const { - auto json_obj = QuantizerParam::SerializeToJsonObject(omit_empty_value); + auto json_obj = QuantizerParam::serialize_to_json_object(omit_empty_value); json_obj.set("num_chunk", ailego::JsonValue(num_chunk)); json_obj.set("num_bits", ailego::JsonValue(num_bits)); return json_obj; } -bool PqQuantizerParam::DeserializeFromJsonObject( +bool PqQuantizerParam::deserialize_from_json_object( const ailego::JsonObject &json_obj) { - if (!QuantizerParam::DeserializeFromJsonObject(json_obj)) { + if (!QuantizerParam::deserialize_from_json_object(json_obj)) { return false; } DESERIALIZE_VALUE_FIELD(json_obj, num_chunk); diff --git a/src/core/interface/indexes/diskann_index.cc b/src/core/interface/indexes/diskann_index.cc index 83244f1e6..35efbd6b5 100644 --- a/src/core/interface/indexes/diskann_index.cc +++ b/src/core/interface/indexes/diskann_index.cc @@ -86,7 +86,7 @@ int DiskAnnIndex::merge(const std::vector &indexes, #else -int DiskAnnIndex::CreateAndInitStreamer(const BaseIndexParam ¶m) { +int DiskAnnIndex::create_and_init_streamer(const BaseIndexParam ¶m) { if (is_sparse_) { LOG_ERROR("Failed to create streamer. Sparse is not Supported."); return core::IndexError_Unsupported; @@ -180,7 +180,7 @@ int DiskAnnIndex::open(const std::string &file_path, return 0; } -int DiskAnnIndex::GenerateHolder() { +int DiskAnnIndex::generate_holder() { return BuildMultiPassHolder(param_.data_type, param_.dimension, doc_cache_, converter_, &holder_); } @@ -210,7 +210,7 @@ int DiskAnnIndex::add(const VectorData &vector, uint32_t doc_id) { } int DiskAnnIndex::train() { - int ret = GenerateHolder(); + int ret = generate_holder(); if (ret != 0) { LOG_ERROR("Failed to generate holder, err: %s", core::IndexError::What(ret)); diff --git a/src/core/interface/indexes/flat_index.cc b/src/core/interface/indexes/flat_index.cc index 08fc0ff02..29c5d2e70 100644 --- a/src/core/interface/indexes/flat_index.cc +++ b/src/core/interface/indexes/flat_index.cc @@ -149,7 +149,7 @@ int FlatIndex::open(const std::string &file_path, "Persisted flat index %s uses a legacy layout, falling back to the " "converter pipeline", file_path.c_str()); - int ret = FallbackToLegacyPipeline(); + int ret = fallback_to_legacy_pipeline(); if (ret != 0) { return ret; } @@ -165,11 +165,12 @@ int FlatIndex::open(const std::string &file_path, // opened an older file with a different storage precision. quantizer_params = persisted_meta.quantizer_params(); } - int ret = CreateAndInitTurboQuantizer(quantizer_name, quantizer_params); + int ret = + create_and_init_turbo_quantizer(quantizer_name, quantizer_params); if (ret != 0) { return ret; } - ret = CreateAndInitStreamer(param_); + ret = create_and_init_streamer(param_); if (ret != 0) { return ret; } @@ -178,7 +179,7 @@ int FlatIndex::open(const std::string &file_path, return Index::open(file_path, storage_options); } -int FlatIndex::FallbackToLegacyPipeline() { +int FlatIndex::fallback_to_legacy_pipeline() { turbo_quantizer_.reset(); streamer_.reset(); @@ -193,29 +194,30 @@ int FlatIndex::FallbackToLegacyPipeline() { input_vector_meta_.set_meta_type(proxima_index_meta_.meta_type()); streamer_vector_meta_ = input_vector_meta_; - if (ParseMetricName(param_) != 0) { + if (parse_metric_name(param_) != 0) { LOG_ERROR("Failed to parse metric name"); return core::IndexError_Runtime; } const auto quantizer_param = param_.quantizer_param ? param_.quantizer_param : std::make_shared(); - if (CreateAndInitLegacyConverterReformer(*quantizer_param, param_) != 0) { + if (create_and_init_legacy_converter_reformer(*quantizer_param, param_) != + 0) { LOG_ERROR("Failed to create and init legacy converter"); return core::IndexError_Runtime; } - if (CreateAndInitMetric(param_) != 0) { + if (create_and_init_metric(param_) != 0) { LOG_ERROR("Failed to create and init metric"); return core::IndexError_Runtime; } - if (CreateAndInitStreamer(param_) != 0) { + if (create_and_init_streamer(param_) != 0) { LOG_ERROR("Failed to create and init streamer"); return core::IndexError_Runtime; } return core::IndexError_Success; } -int FlatIndex::CreateAndInitConverterReformer( +int FlatIndex::create_and_init_converter_reformer( const QuantizerParam &quantizer_param, const BaseIndexParam &index_param) { const auto &flat_param = dynamic_cast(index_param); // Prefer the turbo quantizer path (quantized records + SIMD batch distance @@ -225,14 +227,15 @@ int FlatIndex::CreateAndInitConverterReformer( const std::string quantizer_name = SelectTurboQuantizerName(quantizer_param, flat_param); if (!quantizer_name.empty()) { - return CreateAndInitTurboQuantizer( + return create_and_init_turbo_quantizer( quantizer_name, MakeTurboQuantizerParams(quantizer_param, flat_param)); } - return CreateAndInitLegacyConverterReformer(quantizer_param, index_param); + return create_and_init_legacy_converter_reformer(quantizer_param, + index_param); } -int FlatIndex::CreateAndInitTurboQuantizer(const std::string &name, - const ailego::Params ¶ms) { +int FlatIndex::create_and_init_turbo_quantizer(const std::string &name, + const ailego::Params ¶ms) { auto quantizer = core::IndexFactory::CreateQuantizer(name); if (!quantizer) { LOG_ERROR("Failed to create turbo %s", name.c_str()); @@ -254,13 +257,14 @@ int FlatIndex::CreateAndInitTurboQuantizer(const std::string &name, return core::IndexError_Success; } -int FlatIndex::CreateAndInitLegacyConverterReformer( +int FlatIndex::create_and_init_legacy_converter_reformer( const QuantizerParam &quantizer_param, const BaseIndexParam &index_param) { const auto &flat_param = dynamic_cast(index_param); const auto storage_type = flat_param.storage_data_type; if (storage_type == DataType::DT_UNDEFINED || storage_type == flat_param.data_type) { - return Index::CreateAndInitConverterReformer(quantizer_param, index_param); + return Index::create_and_init_converter_reformer(quantizer_param, + index_param); } if (flat_param.is_sparse || flat_param.data_type != DataType::DT_FP32 || @@ -273,14 +277,14 @@ int FlatIndex::CreateAndInitLegacyConverterReformer( if (storage_type == DataType::DT_FP16) { if (flat_param.metric_type == MetricType::kCosine) { - return InitConverterReformer("CosineRawFp16Converter"); + return init_converter_reformer("CosineRawFp16Converter"); } - return InitConverterReformer("HalfFloatConverter"); + return init_converter_reformer("HalfFloatConverter"); } if (storage_type == DataType::DT_UINT8 && flat_param.metric_type == MetricType::kL2sq) { - return InitConverterReformer("RawUint8Converter"); + return init_converter_reformer("RawUint8Converter"); } LOG_ERROR("Unsupported Flat storage data type %d for metric %d", @@ -289,7 +293,7 @@ int FlatIndex::CreateAndInitLegacyConverterReformer( return core::IndexError_Unsupported; } -int FlatIndex::CreateAndInitStreamer(const BaseIndexParam ¶m) { +int FlatIndex::create_and_init_streamer(const BaseIndexParam ¶m) { param_ = dynamic_cast(param); proxima_index_params_.set(core::PARAM_FLAT_COLUMN_MAJOR_ORDER, diff --git a/src/core/interface/indexes/hnsw_index.cc b/src/core/interface/indexes/hnsw_index.cc index 335ef36bf..0b9703af5 100644 --- a/src/core/interface/indexes/hnsw_index.cc +++ b/src/core/interface/indexes/hnsw_index.cc @@ -73,7 +73,7 @@ int HNSWIndex::search_with_source( return Index::search(query, search_param, result); } -int HNSWIndex::CreateAndInitStreamer(const BaseIndexParam ¶m) { +int HNSWIndex::create_and_init_streamer(const BaseIndexParam ¶m) { param_ = dynamic_cast(param); // valid diff --git a/src/core/interface/indexes/hnsw_rabitq_index.cc b/src/core/interface/indexes/hnsw_rabitq_index.cc index 50a12752f..429850a85 100644 --- a/src/core/interface/indexes/hnsw_rabitq_index.cc +++ b/src/core/interface/indexes/hnsw_rabitq_index.cc @@ -25,7 +25,7 @@ namespace zvec::core_interface { -int HNSWRabitqIndex::CreateAndInitStreamer(const BaseIndexParam ¶m) { +int HNSWRabitqIndex::create_and_init_streamer(const BaseIndexParam ¶m) { #if !RABITQ_SUPPORTED (void)param; LOG_ERROR("RaBitQ is not supported on this platform (Linux x86_64 only)"); diff --git a/src/core/interface/indexes/ivf_index.cc b/src/core/interface/indexes/ivf_index.cc index 11399dab3..17059940a 100644 --- a/src/core/interface/indexes/ivf_index.cc +++ b/src/core/interface/indexes/ivf_index.cc @@ -22,7 +22,7 @@ namespace zvec::core_interface { -int IVFIndex::CreateAndInitStreamer(const BaseIndexParam ¶m) { +int IVFIndex::create_and_init_streamer(const BaseIndexParam ¶m) { if (is_sparse_) { LOG_ERROR("IVF Index not support sparse vector"); return core::IndexError_InvalidArgument; @@ -141,7 +141,7 @@ int IVFIndex::open(const std::string &file_path, return 0; } -int IVFIndex::GenerateHolder() { +int IVFIndex::generate_holder() { return BuildMultiPassHolder(param_.data_type, param_.dimension, doc_cache_, converter_, &holder_); } @@ -175,7 +175,7 @@ int IVFIndex::train() { return 0; } if (build_stage_ == BuildStage::kCollecting) { - int ret = GenerateHolder(); + int ret = generate_holder(); if (ret != 0) { return ret; } @@ -192,10 +192,10 @@ int IVFIndex::train() { } build_stage_ = BuildStage::kBuilt; } - return DumpAndOpen(); + return dump_and_open(); } -int IVFIndex::ResetBuilder() { +int IVFIndex::reset_builder() { auto next_builder = core::IndexFactory::CreateBuilder("IVFBuilder"); if (!next_builder) { return core::IndexError_NoExist; @@ -210,7 +210,7 @@ int IVFIndex::ResetBuilder() { return 0; } -int IVFIndex::DumpAndOpen() { +int IVFIndex::dump_and_open() { if (build_stage_ == BuildStage::kBuilt) { auto dumper = core::IndexFactory::CreateDumper("FileDumper"); if (!dumper) { @@ -241,7 +241,7 @@ int IVFIndex::DumpAndOpen() { // Release the full builder state before opening the persisted index. // If opening fails, retry only open: the replacement builder is empty. - ret = ResetBuilder(); + ret = reset_builder(); if (ret != 0) { return ret; } @@ -346,7 +346,7 @@ int IVFIndex::merge(const std::vector &indexes, } // A new merge (including a retry) rebuilds from its explicit inputs. Do not // reuse a partially trained builder or silently resume different inputs. - int ret = ResetBuilder(); + int ret = reset_builder(); if (ret != 0) { return ret; } @@ -359,6 +359,6 @@ int IVFIndex::merge(const std::vector &indexes, // Index::merge marks the reduce phase complete. IVF is not usable until // dump/open finishes; train() may resume that phase if it fails. is_trained_ = false; - return DumpAndOpen(); + return dump_and_open(); } } // namespace zvec::core_interface diff --git a/src/core/interface/indexes/ivf_rabitq_index.cc b/src/core/interface/indexes/ivf_rabitq_index.cc index bbf7151e8..412e569da 100644 --- a/src/core/interface/indexes/ivf_rabitq_index.cc +++ b/src/core/interface/indexes/ivf_rabitq_index.cc @@ -29,7 +29,7 @@ namespace zvec::core_interface { -int IVFRabitqIndex::CreateAndInitStreamer(const BaseIndexParam ¶m) { +int IVFRabitqIndex::create_and_init_streamer(const BaseIndexParam ¶m) { #if !RABITQ_SUPPORTED (void)param; LOG_ERROR("RaBitQ is not supported on this platform (Linux x86_64 only)"); @@ -139,7 +139,7 @@ int IVFRabitqIndex::open(const std::string &file_path, #endif // RABITQ_SUPPORTED } -int IVFRabitqIndex::GenerateHolder() { +int IVFRabitqIndex::generate_holder() { #if !RABITQ_SUPPORTED LOG_ERROR("RaBitQ is not supported on this platform (Linux x86_64 only)"); return core::IndexError_Unsupported; diff --git a/src/core/interface/indexes/vamana_index.cc b/src/core/interface/indexes/vamana_index.cc index 9e2ad969c..e2c73566e 100644 --- a/src/core/interface/indexes/vamana_index.cc +++ b/src/core/interface/indexes/vamana_index.cc @@ -41,7 +41,7 @@ int VamanaIndex::merge(const std::vector &indexes, return ret; } -int VamanaIndex::CreateAndInitStreamer(const BaseIndexParam ¶m) { +int VamanaIndex::create_and_init_streamer(const BaseIndexParam ¶m) { param_ = dynamic_cast(param); // Validate parameters diff --git a/src/core/metric/quantized_integer_metric_batch.h b/src/core/metric/quantized_integer_metric_batch.h index 9c1ee6f98..101930856 100644 --- a/src/core/metric/quantized_integer_metric_batch.h +++ b/src/core/metric/quantized_integer_metric_batch.h @@ -37,7 +37,7 @@ template