From 0d348beedfd584b9afbc42e5f24d562885b5acbb Mon Sep 17 00:00:00 2001 From: Abdullah Ahmed Date: Mon, 30 Sep 2024 02:42:14 -0700 Subject: [PATCH] fix: Convert C-Style Casts to C++-Style Type Casts issue: #35900 Signed-off-by: Abdullah Ahmed --- .../core/src/exec/expression/TermExpr.cpp | 3 ++- internal/core/src/index/ScalarIndexSort.cpp | 8 +++++-- internal/core/src/index/VectorDiskIndex.cpp | 3 ++- internal/core/src/indexbuilder/index_c.cpp | 24 ++++++++++++------- internal/core/src/log/Log.cpp | 4 +++- internal/core/src/query/SearchOnGrowing.cpp | 4 ++-- internal/core/src/segcore/FieldIndexing.cpp | 10 ++++---- .../core/src/segcore/IndexConfigGenerator.cpp | 6 +++-- .../core/src/segcore/SegmentGrowingImpl.cpp | 6 +++-- .../core/src/segcore/SegmentInterface.cpp | 6 +++-- .../core/src/segcore/SegmentSealedImpl.cpp | 4 ++-- internal/core/src/segcore/load_index_c.cpp | 6 +++-- internal/core/src/segcore/plan_c.cpp | 4 +++- 13 files changed, 57 insertions(+), 31 deletions(-) diff --git a/internal/core/src/exec/expression/TermExpr.cpp b/internal/core/src/exec/expression/TermExpr.cpp index 6020ee1cea2d0..a43275146f24c 100644 --- a/internal/core/src/exec/expression/TermExpr.cpp +++ b/internal/core/src/exec/expression/TermExpr.cpp @@ -517,7 +517,8 @@ PhyTermFilterExpr::ExecVisitorImplForIndex() { } auto execute_sub_batch = [](Index* index_ptr, std::vector& vals) { TermIndexFunc func; - return std::move(func(index_ptr, vals.size(), reinterpret_cast(vals.data()))); + return std::move( + func(index_ptr, vals.size(), reinterpret_cast(vals.data()))); }; auto res = ProcessIndexChunks(execute_sub_batch, vals); return std::make_shared(std::move(res)); diff --git a/internal/core/src/index/ScalarIndexSort.cpp b/internal/core/src/index/ScalarIndexSort.cpp index 20c80c636c447..b6d4fc4fe8ad0 100644 --- a/internal/core/src/index/ScalarIndexSort.cpp +++ b/internal/core/src/index/ScalarIndexSort.cpp @@ -166,7 +166,9 @@ ScalarIndexSort::LoadWithoutAssemble(const BinarySet& index_binary, const Config& config) { size_t index_size; auto index_length = index_binary.GetByName("index_length"); - memcpy(&index_size, index_length->data.get(), static_cast(index_length->size)); + memcpy(&index_size, + index_length->data.get(), + static_cast(index_length->size)); auto index_data = index_binary.GetByName("index_data"); data_.resize(index_size); @@ -176,7 +178,9 @@ ScalarIndexSort::LoadWithoutAssemble(const BinarySet& index_binary, (size_t)index_num_rows->size); idx_to_offsets_.resize(total_num_rows_); valid_bitset = TargetBitmap(total_num_rows_, false); - memcpy(data_.data(), index_data->data.get(), static_cast(index_data->size)); + memcpy(data_.data(), + index_data->data.get(), + static_cast(index_data->size)); for (size_t i = 0; i < data_.size(); ++i) { idx_to_offsets_[data_[i].idx_] = i; valid_bitset.set(data_[i].idx_); diff --git a/internal/core/src/index/VectorDiskIndex.cpp b/internal/core/src/index/VectorDiskIndex.cpp index 92f5ce44e592f..5a05999745106 100644 --- a/internal/core/src/index/VectorDiskIndex.cpp +++ b/internal/core/src/index/VectorDiskIndex.cpp @@ -256,7 +256,8 @@ VectorDiskAnnIndex::Query(const DatasetPtr dataset, search_info.search_params_[DISK_ANN_QUERY_LIST]; } // set beamwidth - search_config[DISK_ANN_QUERY_BEAMWIDTH] = static_cast(search_beamwidth_); + search_config[DISK_ANN_QUERY_BEAMWIDTH] = + static_cast(search_beamwidth_); // set json reset field, will be removed later search_config[DISK_ANN_PQ_CODE_BUDGET] = 0.0; } diff --git a/internal/core/src/indexbuilder/index_c.cpp b/internal/core/src/indexbuilder/index_c.cpp index fce3295a8b526..c4029417f5f2a 100644 --- a/internal/core/src/indexbuilder/index_c.cpp +++ b/internal/core/src/indexbuilder/index_c.cpp @@ -592,7 +592,8 @@ AppendBuildIndexParam(CBuildIndexInfo c_build_index_info, const uint8_t* serialized_index_params, const uint64_t len) { try { - auto build_index_info = static_cast(c_build_index_info); + auto build_index_info = + static_cast(c_build_index_info); auto index_params = std::make_unique(); auto res = index_params->ParseFromArray(serialized_index_params, len); @@ -619,7 +620,8 @@ AppendBuildTypeParam(CBuildIndexInfo c_build_index_info, const uint8_t* serialized_type_params, const uint64_t len) { try { - auto build_index_info = static_cast(c_build_index_info); + auto build_index_info = + static_cast(c_build_index_info); auto type_params = std::make_unique(); auto res = type_params->ParseFromArray(serialized_type_params, len); @@ -651,7 +653,8 @@ AppendFieldMetaInfoV2(CBuildIndexInfo c_build_index_info, enum CDataType field_type, int64_t dim) { try { - auto build_index_info = static_cast(c_build_index_info); + auto build_index_info = + static_cast(c_build_index_info); build_index_info->collection_id = collection_id; build_index_info->partition_id = partition_id; build_index_info->segment_id = segment_id; @@ -674,7 +677,8 @@ AppendFieldMetaInfo(CBuildIndexInfo c_build_index_info, int64_t field_id, enum CDataType field_type) { try { - auto build_index_info = static_cast(c_build_index_info); + auto build_index_info = + static_cast(c_build_index_info); build_index_info->collection_id = collection_id; build_index_info->partition_id = partition_id; build_index_info->segment_id = segment_id; @@ -700,7 +704,8 @@ AppendIndexMetaInfo(CBuildIndexInfo c_build_index_info, int64_t build_id, int64_t version) { try { - auto build_index_info = static_cast(c_build_index_info); + auto build_index_info = + static_cast(c_build_index_info); build_index_info->index_id = index_id; build_index_info->index_build_id = build_id; build_index_info->index_version = version; @@ -721,7 +726,8 @@ CStatus AppendInsertFilePath(CBuildIndexInfo c_build_index_info, const char* c_file_path) { try { - auto build_index_info = static_cast(c_build_index_info); + auto build_index_info = + static_cast(c_build_index_info); std::string insert_file_path(c_file_path); build_index_info->insert_files.emplace_back(insert_file_path); @@ -756,7 +762,8 @@ AppendIndexStorageInfo(CBuildIndexInfo c_build_index_info, const char* c_index_store_path, int64_t data_store_version) { try { - auto build_index_info = static_cast(c_build_index_info); + auto build_index_info = + static_cast(c_build_index_info); std::string data_store_path(c_data_store_path), index_store_path(c_index_store_path); build_index_info->data_store_path = data_store_path; @@ -803,7 +810,8 @@ AppendOptionalFieldDataPath(CBuildIndexInfo c_build_index_info, const int32_t field_type, const char* c_file_path) { try { - auto build_index_info = static_cast(c_build_index_info); + auto build_index_info = + static_cast(c_build_index_info); std::string field_name_str(field_name); auto& opt_fields_map = build_index_info->opt_fields; if (opt_fields_map.find(field_id) == opt_fields_map.end()) { diff --git a/internal/core/src/log/Log.cpp b/internal/core/src/log/Log.cpp index e19db8271e3ec..929cc0a617dba 100644 --- a/internal/core/src/log/Log.cpp +++ b/internal/core/src/log/Log.cpp @@ -132,7 +132,9 @@ get_thread_starttime() { thread_stat, "%lld %s %s ", (long long*)&val, comm, &state); // NOLINT for (auto i = 4; i < 23; i++) { - ret = fscanf(thread_stat, "%lld ", reinterpret_cast(&val)); // NOLINT + ret = fscanf(thread_stat, + "%lld ", + reinterpret_cast(&val)); // NOLINT if (i == 22) { break; } diff --git a/internal/core/src/query/SearchOnGrowing.cpp b/internal/core/src/query/SearchOnGrowing.cpp index 6c82660272130..c3fe2cc86ccad 100644 --- a/internal/core/src/query/SearchOnGrowing.cpp +++ b/internal/core/src/query/SearchOnGrowing.cpp @@ -72,8 +72,8 @@ SearchOnGrowing(const segcore::SegmentGrowingImpl& segment, SearchResult& search_result) { auto& schema = segment.get_schema(); auto& record = segment.get_insert_record(); - auto active_count = - std::min(static_cast(bitset.size()), segment.get_active_count(timestamp)); + auto active_count = std::min(static_cast(bitset.size()), + segment.get_active_count(timestamp)); // step 1.1: get meta // step 1.2: get which vector field to search diff --git a/internal/core/src/segcore/FieldIndexing.cpp b/internal/core/src/segcore/FieldIndexing.cpp index 1b1b0083a799a..bb24accad8a35 100644 --- a/internal/core/src/segcore/FieldIndexing.cpp +++ b/internal/core/src/segcore/FieldIndexing.cpp @@ -198,11 +198,11 @@ VectorFieldIndexing::AppendSegmentIndexDense(int64_t reserved_offset, chunk_id == chunk_id_end ? vector_id_end - chunk_id * size_per_chunk + 1 : size_per_chunk; - std::memcpy( - vec_data.get() + offset * dim, - static_cast(field_raw_data->get_chunk_data(chunk_id)) + - chunk_offset * dim, - chunk_copysz * dim * sizeof(float)); + std::memcpy(vec_data.get() + offset * dim, + static_cast( + field_raw_data->get_chunk_data(chunk_id)) + + chunk_offset * dim, + chunk_copysz * dim * sizeof(float)); offset += chunk_copysz; } data_addr = vec_data.get(); diff --git a/internal/core/src/segcore/IndexConfigGenerator.cpp b/internal/core/src/segcore/IndexConfigGenerator.cpp index 07c5e6c4b3ec8..5303914dca0a3 100644 --- a/internal/core/src/segcore/IndexConfigGenerator.cpp +++ b/internal/core/src/segcore/IndexConfigGenerator.cpp @@ -47,8 +47,10 @@ VecIndexConfig::VecIndexConfig(const int64_t max_index_row_cout, build_params_[knowhere::meta::METRIC_TYPE] = metric_type_; build_params_[knowhere::indexparam::NLIST] = std::to_string(config_.get_nlist()); - build_params_[knowhere::indexparam::SSIZE] = std::to_string( - std::max(static_cast(config_.get_chunk_rows()) / static_cast(config_.get_nlist()), 48)); + build_params_[knowhere::indexparam::SSIZE] = + std::to_string(std::max(static_cast(config_.get_chunk_rows()) / + static_cast(config_.get_nlist()), + 48)); search_params_[knowhere::indexparam::NPROBE] = std::to_string(config_.get_nprobe()); // note for sparse vector index: drop_ratio_build is not allowed for growing diff --git a/internal/core/src/segcore/SegmentGrowingImpl.cpp b/internal/core/src/segcore/SegmentGrowingImpl.cpp index 669982bae00f1..1c48f7bcba437 100644 --- a/internal/core/src/segcore/SegmentGrowingImpl.cpp +++ b/internal/core/src/segcore/SegmentGrowingImpl.cpp @@ -496,7 +496,8 @@ SegmentGrowingImpl::bulk_subscript(FieldId field_id, DataType::VECTOR_SPARSE_FLOAT) { bulk_subscript_sparse_float_vector_impl( field_id, - static_cast*>(vec_ptr), + static_cast*>( + vec_ptr), seg_offsets, count, result->mutable_vectors()->mutable_sparse_float_vector()); @@ -722,7 +723,8 @@ SegmentGrowingImpl::bulk_subscript_impl(FieldId field_id, if (offset == INVALID_SEG_OFFSET) { memset(dst, 0, element_sizeof); } else { - auto src = reinterpret_cast(vec.get_element(offset)); + auto src = reinterpret_cast( + vec.get_element(offset)); memcpy(dst, src, element_sizeof); } } diff --git a/internal/core/src/segcore/SegmentInterface.cpp b/internal/core/src/segcore/SegmentInterface.cpp index 63da2afcb0640..d8601b85edca9 100644 --- a/internal/core/src/segcore/SegmentInterface.cpp +++ b/internal/core/src/segcore/SegmentInterface.cpp @@ -86,7 +86,8 @@ SegmentInternalInterface::Search( query::ExecPlanNodeVisitor visitor(*this, timestamp, placeholder_group); auto results = std::make_unique(); *results = visitor.get_moved_result(*plan->plan_node_); - results->segment_ = static_cast(const_cast(this)); + results->segment_ = static_cast( + const_cast(this)); return results; } @@ -101,7 +102,8 @@ SegmentInternalInterface::Retrieve(tracer::TraceContext* trace_ctx, auto results = std::make_unique(); query::ExecPlanNodeVisitor visitor(*this, timestamp); auto retrieve_results = visitor.get_retrieve_result(*plan->plan_node_); - retrieve_results.segment_ = static_cast(const_cast(this)); + retrieve_results.segment_ = static_cast( + const_cast(this)); results->set_has_more_result(retrieve_results.has_more_result); auto result_rows = retrieve_results.result_offsets_.size(); diff --git a/internal/core/src/segcore/SegmentSealedImpl.cpp b/internal/core/src/segcore/SegmentSealedImpl.cpp index e0a1fe31f6dd1..bd111b0937618 100644 --- a/internal/core/src/segcore/SegmentSealedImpl.cpp +++ b/internal/core/src/segcore/SegmentSealedImpl.cpp @@ -1978,8 +1978,8 @@ SegmentSealedImpl::generate_interim_index(const FieldId field_id) { build_config[knowhere::meta::NUM_BUILD_THREAD] = std::to_string(1); auto index_metric = field_binlog_config->GetMetricType(); - auto dataset = - knowhere::GenDataSet(row_count, dim, static_cast(vec_data->Data())); + auto dataset = knowhere::GenDataSet( + row_count, dim, static_cast(vec_data->Data())); dataset->SetIsOwner(false); dataset->SetIsSparse(is_sparse); diff --git a/internal/core/src/segcore/load_index_c.cpp b/internal/core/src/segcore/load_index_c.cpp index 105a5d605420d..9907d400a0950 100644 --- a/internal/core/src/segcore/load_index_c.cpp +++ b/internal/core/src/segcore/load_index_c.cpp @@ -206,7 +206,8 @@ appendScalarIndex(CLoadIndexInfo c_load_index_info, CBinarySet c_binary_set) { CStatus AppendIndex(CLoadIndexInfo c_load_index_info, CBinarySet c_binary_set) { - auto load_index_info = static_cast(c_load_index_info); + auto load_index_info = + static_cast(c_load_index_info); auto field_type = load_index_info->field_type; if (milvus::IsVectorDataType(field_type)) { return appendVecIndex(c_load_index_info, c_binary_set); @@ -411,7 +412,8 @@ void AppendStorageInfo(CLoadIndexInfo c_load_index_info, const char* uri, int64_t version) { - auto load_index_info = static_cast(c_load_index_info); + auto load_index_info = + static_cast(c_load_index_info); load_index_info->uri = uri; load_index_info->index_store_version = version; } diff --git a/internal/core/src/segcore/plan_c.cpp b/internal/core/src/segcore/plan_c.cpp index b3f3dfd2c499f..1d2169154a97e 100644 --- a/internal/core/src/segcore/plan_c.cpp +++ b/internal/core/src/segcore/plan_c.cpp @@ -63,7 +63,9 @@ ParsePlaceholderGroup(CSearchPlan c_plan, try { auto res = milvus::query::ParsePlaceholderGroup( - plan, static_cast(placeholder_group_blob), blob_size); + plan, + static_cast(placeholder_group_blob), + blob_size); auto status = CStatus(); status.error_code = milvus::Success;