Skip to content

Commit

Permalink
fix: Convert C-Style Casts to C++-Style Type Casts
Browse files Browse the repository at this point in the history
issue: milvus-io#35900

Signed-off-by: Abdullah Ahmed <[email protected]>
  • Loading branch information
abd-770 committed Sep 30, 2024
1 parent 1d8b9d4 commit 0d348be
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 31 deletions.
3 changes: 2 additions & 1 deletion internal/core/src/exec/expression/TermExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@ PhyTermFilterExpr::ExecVisitorImplForIndex<bool>() {
}
auto execute_sub_batch = [](Index* index_ptr, std::vector<uint8_t>& vals) {
TermIndexFunc<bool> func;
return std::move(func(index_ptr, vals.size(), reinterpret_cast<bool*>(vals.data())));
return std::move(
func(index_ptr, vals.size(), reinterpret_cast<bool*>(vals.data())));
};
auto res = ProcessIndexChunks<bool>(execute_sub_batch, vals);
return std::make_shared<ColumnVector>(std::move(res));
Expand Down
8 changes: 6 additions & 2 deletions internal/core/src/index/ScalarIndexSort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ ScalarIndexSort<T>::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<size_t>(index_length->size));
memcpy(&index_size,
index_length->data.get(),
static_cast<size_t>(index_length->size));

auto index_data = index_binary.GetByName("index_data");
data_.resize(index_size);
Expand All @@ -176,7 +178,9 @@ ScalarIndexSort<T>::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<size_t>(index_data->size));
memcpy(data_.data(),
index_data->data.get(),
static_cast<size_t>(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_);
Expand Down
3 changes: 2 additions & 1 deletion internal/core/src/index/VectorDiskIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ VectorDiskAnnIndex<T>::Query(const DatasetPtr dataset,
search_info.search_params_[DISK_ANN_QUERY_LIST];
}
// set beamwidth
search_config[DISK_ANN_QUERY_BEAMWIDTH] = static_cast<int>(search_beamwidth_);
search_config[DISK_ANN_QUERY_BEAMWIDTH] =
static_cast<int>(search_beamwidth_);
// set json reset field, will be removed later
search_config[DISK_ANN_PQ_CODE_BUDGET] = 0.0;
}
Expand Down
24 changes: 16 additions & 8 deletions internal/core/src/indexbuilder/index_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BuildIndexInfo*>(c_build_index_info);
auto build_index_info =
static_cast<BuildIndexInfo*>(c_build_index_info);
auto index_params =
std::make_unique<milvus::proto::indexcgo::IndexParams>();
auto res = index_params->ParseFromArray(serialized_index_params, len);
Expand All @@ -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<BuildIndexInfo*>(c_build_index_info);
auto build_index_info =
static_cast<BuildIndexInfo*>(c_build_index_info);
auto type_params =
std::make_unique<milvus::proto::indexcgo::TypeParams>();
auto res = type_params->ParseFromArray(serialized_type_params, len);
Expand Down Expand Up @@ -651,7 +653,8 @@ AppendFieldMetaInfoV2(CBuildIndexInfo c_build_index_info,
enum CDataType field_type,
int64_t dim) {
try {
auto build_index_info = static_cast<BuildIndexInfo*>(c_build_index_info);
auto build_index_info =
static_cast<BuildIndexInfo*>(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;
Expand All @@ -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<BuildIndexInfo*>(c_build_index_info);
auto build_index_info =
static_cast<BuildIndexInfo*>(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;
Expand All @@ -700,7 +704,8 @@ AppendIndexMetaInfo(CBuildIndexInfo c_build_index_info,
int64_t build_id,
int64_t version) {
try {
auto build_index_info = static_cast<BuildIndexInfo*>(c_build_index_info);
auto build_index_info =
static_cast<BuildIndexInfo*>(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;
Expand All @@ -721,7 +726,8 @@ CStatus
AppendInsertFilePath(CBuildIndexInfo c_build_index_info,
const char* c_file_path) {
try {
auto build_index_info = static_cast<BuildIndexInfo*>(c_build_index_info);
auto build_index_info =
static_cast<BuildIndexInfo*>(c_build_index_info);
std::string insert_file_path(c_file_path);
build_index_info->insert_files.emplace_back(insert_file_path);

Expand Down Expand Up @@ -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<BuildIndexInfo*>(c_build_index_info);
auto build_index_info =
static_cast<BuildIndexInfo*>(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;
Expand Down Expand Up @@ -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<BuildIndexInfo*>(c_build_index_info);
auto build_index_info =
static_cast<BuildIndexInfo*>(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()) {
Expand Down
4 changes: 3 additions & 1 deletion internal/core/src/log/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<long long*>(&val)); // NOLINT
ret = fscanf(thread_stat,
"%lld ",
reinterpret_cast<long long*>(&val)); // NOLINT
if (i == 22) {
break;
}
Expand Down
4 changes: 2 additions & 2 deletions internal/core/src/query/SearchOnGrowing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>(bitset.size()), segment.get_active_count(timestamp));
auto active_count = std::min(static_cast<int64_t>(bitset.size()),
segment.get_active_count(timestamp));

// step 1.1: get meta
// step 1.2: get which vector field to search
Expand Down
10 changes: 5 additions & 5 deletions internal/core/src/segcore/FieldIndexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const float*>(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<const float*>(
field_raw_data->get_chunk_data(chunk_id)) +
chunk_offset * dim,
chunk_copysz * dim * sizeof(float));
offset += chunk_copysz;
}
data_addr = vec_data.get();
Expand Down
6 changes: 4 additions & 2 deletions internal/core/src/segcore/IndexConfigGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(config_.get_chunk_rows()) / static_cast<int>(config_.get_nlist()), 48));
build_params_[knowhere::indexparam::SSIZE] =
std::to_string(std::max(static_cast<int>(config_.get_chunk_rows()) /
static_cast<int>(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
Expand Down
6 changes: 4 additions & 2 deletions internal/core/src/segcore/SegmentGrowingImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ SegmentGrowingImpl::bulk_subscript(FieldId field_id,
DataType::VECTOR_SPARSE_FLOAT) {
bulk_subscript_sparse_float_vector_impl(
field_id,
static_cast<const ConcurrentVector<SparseFloatVector>*>(vec_ptr),
static_cast<const ConcurrentVector<SparseFloatVector>*>(
vec_ptr),
seg_offsets,
count,
result->mutable_vectors()->mutable_sparse_float_vector());
Expand Down Expand Up @@ -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<const uint8_t*>(vec.get_element(offset));
auto src = reinterpret_cast<const uint8_t*>(
vec.get_element(offset));
memcpy(dst, src, element_sizeof);
}
}
Expand Down
6 changes: 4 additions & 2 deletions internal/core/src/segcore/SegmentInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ SegmentInternalInterface::Search(
query::ExecPlanNodeVisitor visitor(*this, timestamp, placeholder_group);
auto results = std::make_unique<SearchResult>();
*results = visitor.get_moved_result(*plan->plan_node_);
results->segment_ = static_cast<void*>(const_cast<milvus::segcore::SegmentInternalInterface*>(this));
results->segment_ = static_cast<void*>(
const_cast<milvus::segcore::SegmentInternalInterface*>(this));
return results;
}

Expand All @@ -101,7 +102,8 @@ SegmentInternalInterface::Retrieve(tracer::TraceContext* trace_ctx,
auto results = std::make_unique<proto::segcore::RetrieveResults>();
query::ExecPlanNodeVisitor visitor(*this, timestamp);
auto retrieve_results = visitor.get_retrieve_result(*plan->plan_node_);
retrieve_results.segment_ = static_cast<void*>(const_cast<milvus::segcore::SegmentInternalInterface*>(this));
retrieve_results.segment_ = static_cast<void*>(
const_cast<milvus::segcore::SegmentInternalInterface*>(this));
results->set_has_more_result(retrieve_results.has_more_result);

auto result_rows = retrieve_results.result_offsets_.size();
Expand Down
4 changes: 2 additions & 2 deletions internal/core/src/segcore/SegmentSealedImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const void*>(vec_data->Data()));
auto dataset = knowhere::GenDataSet(
row_count, dim, static_cast<const void*>(vec_data->Data()));
dataset->SetIsOwner(false);
dataset->SetIsSparse(is_sparse);

Expand Down
6 changes: 4 additions & 2 deletions internal/core/src/segcore/load_index_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<milvus::segcore::LoadIndexInfo*>(c_load_index_info);
auto load_index_info =
static_cast<milvus::segcore::LoadIndexInfo*>(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);
Expand Down Expand Up @@ -411,7 +412,8 @@ void
AppendStorageInfo(CLoadIndexInfo c_load_index_info,
const char* uri,
int64_t version) {
auto load_index_info = static_cast<milvus::segcore::LoadIndexInfo*>(c_load_index_info);
auto load_index_info =
static_cast<milvus::segcore::LoadIndexInfo*>(c_load_index_info);
load_index_info->uri = uri;
load_index_info->index_store_version = version;
}
Expand Down
4 changes: 3 additions & 1 deletion internal/core/src/segcore/plan_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ ParsePlaceholderGroup(CSearchPlan c_plan,

try {
auto res = milvus::query::ParsePlaceholderGroup(
plan, static_cast<const uint8_t*>(placeholder_group_blob), blob_size);
plan,
static_cast<const uint8_t*>(placeholder_group_blob),
blob_size);

auto status = CStatus();
status.error_code = milvus::Success;
Expand Down

0 comments on commit 0d348be

Please sign in to comment.