Skip to content

Commit

Permalink
convert to c++ style casting -1
Browse files Browse the repository at this point in the history
  • Loading branch information
abd-770 committed Sep 22, 2024
1 parent 783443a commit db8faa5
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 50 deletions.
18 changes: 9 additions & 9 deletions internal/core/src/common/binary_set_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ NewBinarySet(CBinarySet* c_binary_set) {

void
DeleteBinarySet(CBinarySet c_binary_set) {
auto binary_set = (knowhere::BinarySet*)c_binary_set;
auto binary_set = static_cast<knowhere::BinarySet*>(c_binary_set);
delete binary_set;
}

Expand All @@ -48,9 +48,9 @@ AppendIndexBinary(CBinarySet c_binary_set,
const char* c_index_key) {
auto status = CStatus();
try {
auto binary_set = (knowhere::BinarySet*)c_binary_set;
auto binary_set = static_cast<knowhere::BinarySet*>(c_binary_set);

Check warning on line 51 in internal/core/src/common/binary_set_c.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/common/binary_set_c.cpp#L51

Added line #L51 was not covered by tests
std::string index_key(c_index_key);
uint8_t* index = (uint8_t*)index_binary;
uint8_t* index = static_cast<uint8_t*>(index_binary);

Check warning on line 53 in internal/core/src/common/binary_set_c.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/common/binary_set_c.cpp#L53

Added line #L53 was not covered by tests
uint8_t* dup = new uint8_t[index_size]();
memcpy(dup, index, index_size);
std::shared_ptr<uint8_t[]> data(dup);
Expand All @@ -67,15 +67,15 @@ AppendIndexBinary(CBinarySet c_binary_set,

int
GetBinarySetSize(CBinarySet c_binary_set) {
auto binary_set = (knowhere::BinarySet*)c_binary_set;
auto binary_set = static_cast<knowhere::BinarySet*>(c_binary_set);

Check warning on line 70 in internal/core/src/common/binary_set_c.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/common/binary_set_c.cpp#L70

Added line #L70 was not covered by tests
return binary_set->binary_map_.size();
}

void
GetBinarySetKeys(CBinarySet c_binary_set, void* data) {
auto binary_set = (knowhere::BinarySet*)c_binary_set;
auto binary_set = static_cast<knowhere::BinarySet*>(c_binary_set);

Check warning on line 76 in internal/core/src/common/binary_set_c.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/common/binary_set_c.cpp#L76

Added line #L76 was not covered by tests
auto& map_ = binary_set->binary_map_;
const char** data_ = (const char**)data;
const char** data_ = static_cast<const char**>(data);

Check warning on line 78 in internal/core/src/common/binary_set_c.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/common/binary_set_c.cpp#L78

Added line #L78 was not covered by tests
std::size_t i = 0;
for (auto it = map_.begin(); it != map_.end(); ++it, i++) {
data_[i] = it->first.c_str();
Expand All @@ -84,7 +84,7 @@ GetBinarySetKeys(CBinarySet c_binary_set, void* data) {

int
GetBinarySetValueSize(CBinarySet c_binary_set, const char* key) {
auto binary_set = (knowhere::BinarySet*)c_binary_set;
auto binary_set = static_cast<knowhere::BinarySet*>(c_binary_set);

Check warning on line 87 in internal/core/src/common/binary_set_c.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/common/binary_set_c.cpp#L87

Added line #L87 was not covered by tests
int64_t ret_ = 0;
try {
std::string key_(key);
Expand All @@ -98,12 +98,12 @@ GetBinarySetValueSize(CBinarySet c_binary_set, const char* key) {
CStatus
CopyBinarySetValue(void* data, const char* key, CBinarySet c_binary_set) {
auto status = CStatus();
auto binary_set = (knowhere::BinarySet*)c_binary_set;
auto binary_set = static_cast<knowhere::BinarySet*>(c_binary_set);

Check warning on line 101 in internal/core/src/common/binary_set_c.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/common/binary_set_c.cpp#L101

Added line #L101 was not covered by tests
try {
auto binary = binary_set->GetByName(key);
status.error_code = milvus::ErrorCode::Success;
status.error_msg = "";
memcpy((uint8_t*)data, binary->data.get(), binary->size);
memcpy(static_cast<uint8_t*>(data), binary->data.get(), binary->size);

Check warning on line 106 in internal/core/src/common/binary_set_c.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/common/binary_set_c.cpp#L106

Added line #L106 was not covered by tests
} catch (std::exception& e) {
status.error_code = milvus::ErrorCode::UnexpectedError;
status.error_msg = strdup(e.what());
Expand Down
7 changes: 5 additions & 2 deletions internal/core/src/exec/expression/TermExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ PhyTermFilterExpr::InitPkCacheOffset() {
segment_->search_ids(*id_array, query_timestamp_);
cached_bits_.resize(active_count_, false);
for (const auto& offset : seg_offsets) {
auto _offset = (int64_t)offset.get();
auto _offset = static_cast<int64_t>(offset.get());
cached_bits_[_offset] = true;
}
cached_offsets_inited_ = true;
Expand Down Expand Up @@ -528,7 +528,10 @@ PhyTermFilterExpr::ExecVisitorImplForIndex<bool>() {
auto execute_sub_batch = [](Index* index_ptr,
const std::vector<uint8_t>& vals) {
TermIndexFunc<bool> func;
return std::move(func(index_ptr, vals.size(), (bool*)vals.data()));
return std::move(func(index_ptr, vals.size(),
const_cast<bool*>(static_cast<const bool*>(
static_cast<const void*>(vals.data())
))));
};
auto res = ProcessIndexChunks<bool>(execute_sub_batch, vals);
return std::make_shared<ColumnVector>(std::move(res));
Expand Down
6 changes: 3 additions & 3 deletions internal/core/src/index/ScalarIndexSort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ 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(), (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 +176,7 @@ 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(), (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 Expand Up @@ -207,7 +207,7 @@ ScalarIndexSort<T>::Load(milvus::tracer::TraceContext ctx,
auto size = data->DataSize();
auto deleter = [&](uint8_t*) {}; // avoid repeated deconstruction
auto buf = std::shared_ptr<uint8_t[]>(
(uint8_t*)const_cast<void*>(data->Data()), deleter);
static_cast<uint8_t*>(const_cast<void*>(data->Data())), deleter);

Check warning on line 210 in internal/core/src/index/ScalarIndexSort.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/index/ScalarIndexSort.cpp#L210

Added line #L210 was not covered by tests
binary_set.Append(key, buf, size);
}

Expand Down
2 changes: 1 addition & 1 deletion internal/core/src/index/StringIndexMarisa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ StringIndexMarisa::Load(milvus::tracer::TraceContext ctx,
auto size = data->DataSize();
auto deleter = [&](uint8_t*) {}; // avoid repeated deconstruction
auto buf = std::shared_ptr<uint8_t[]>(
(uint8_t*)const_cast<void*>(data->Data()), deleter);
static_cast<uint8_t*>(const_cast<void*>(data->Data())), deleter);

Check warning on line 241 in internal/core/src/index/StringIndexMarisa.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/index/StringIndexMarisa.cpp#L241

Added line #L241 was not covered by tests
binary_set.Append(key, buf, size);
}

Expand Down
6 changes: 3 additions & 3 deletions internal/core/src/index/VectorDiskIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ VectorDiskAnnIndex<T>::BuildWithDataset(const DatasetPtr& dataset,
}

int64_t offset = 0;
auto num = uint32_t(milvus::GetDatasetRows(dataset));
auto num = static_cast<uint32_t>(milvus::GetDatasetRows(dataset));
local_chunk_manager->Write(local_data_path, offset, &num, sizeof(num));
offset += sizeof(num);

auto dim = uint32_t(milvus::GetDatasetDim(dataset));
auto dim = static_cast<uint32_t>(milvus::GetDatasetDim(dataset));
local_chunk_manager->Write(local_data_path, offset, &dim, sizeof(dim));
offset += sizeof(dim);

Expand Down Expand Up @@ -256,7 +256,7 @@ VectorDiskAnnIndex<T>::Query(const DatasetPtr dataset,
search_info.search_params_[DISK_ANN_QUERY_LIST];
}
// set beamwidth
search_config[DISK_ANN_QUERY_BEAMWIDTH] = 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
2 changes: 1 addition & 1 deletion internal/core/src/index/VectorMemIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ VectorMemIndex<T>::Load(milvus::tracer::TraceContext ctx,
auto size = data->Size();
auto deleter = [&](uint8_t*) {}; // avoid repeated deconstruction
auto buf = std::shared_ptr<uint8_t[]>(
(uint8_t*)const_cast<void*>(data->Data()), deleter);
static_cast<uint8_t*>(const_cast<void*>(data->Data())), deleter);
binary_set.Append(key, buf, size);
}

Expand Down
4 changes: 2 additions & 2 deletions internal/core/src/segcore/FieldIndexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ VectorFieldIndexing::AppendSegmentIndexDense(int64_t reserved_offset,
: size_per_chunk;
std::memcpy(
vec_data.get() + offset * dim,
(const float*)field_raw_data->get_chunk_data(chunk_id) +
static_cast<const float*>(field_raw_data->get_chunk_data(chunk_id)) +
chunk_offset * dim,
chunk_copysz * dim * sizeof(float));
offset += chunk_copysz;
Expand Down Expand Up @@ -249,7 +249,7 @@ VectorFieldIndexing::AppendSegmentIndexDense(int64_t reserved_offset,
auto dataset = knowhere::GenDataSet(
chunk_sz,
dim,
(const float*)source->get_chunk_data(chunk_id) +
static_cast<const float*>(source->get_chunk_data(chunk_id)) +
chunk_offset * dim);
index_->AddWithDataset(dataset, conf);
index_cur_.fetch_add(chunk_sz);
Expand Down
4 changes: 2 additions & 2 deletions internal/core/src/segcore/SegmentInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ 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_ = (void*)this;
results->segment_ = static_cast<void*>(const_cast<milvus::segcore::SegmentInternalInterface*>(this));
return results;
}

Expand All @@ -101,7 +101,7 @@ 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_ = (void*)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 @@ -617,7 +617,7 @@ int64_t
SegmentSealedImpl::num_chunk_index(FieldId field_id) const {
auto& field_meta = schema_->operator[](field_id);
if (field_meta.is_vector()) {
return int64_t(vector_indexings_.is_ready(field_id));
return static_cast<int64_t>(vector_indexings_.is_ready(field_id));
}

return scalar_indexings_.count(field_id);
Expand Down Expand Up @@ -1944,7 +1944,7 @@ SegmentSealedImpl::generate_interim_index(const FieldId field_id) {
auto index_metric = field_binlog_config->GetMetricType();

auto dataset =
knowhere::GenDataSet(row_count, dim, (void*)vec_data->Data());
knowhere::GenDataSet(row_count, dim, static_cast<const void*>(vec_data->Data()));
dataset->SetIsOwner(false);
dataset->SetIsSparse(is_sparse);

Expand Down
6 changes: 3 additions & 3 deletions internal/core/src/segcore/collection_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ CCollection
NewCollection(const void* schema_proto_blob, const int64_t length) {
auto collection = std::make_unique<milvus::segcore::Collection>(
schema_proto_blob, length);
return (void*)collection.release();
return static_cast<void*>(collection.release());

Check warning on line 24 in internal/core/src/segcore/collection_c.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/segcore/collection_c.cpp#L24

Added line #L24 was not covered by tests
}

void
SetIndexMeta(CCollection collection,
const void* proto_blob,
const int64_t length) {
auto col = (milvus::segcore::Collection*)collection;
auto col = static_cast<milvus::segcore::Collection*>(collection);
col->parseIndexMeta(proto_blob, length);
}

void
DeleteCollection(CCollection collection) {
auto col = (milvus::segcore::Collection*)collection;
auto col = static_cast<milvus::segcore::Collection*>(collection);
delete col;
}

Expand Down
26 changes: 13 additions & 13 deletions internal/core/src/segcore/load_index_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ NewLoadIndexInfo(CLoadIndexInfo* c_load_index_info) {

void
DeleteLoadIndexInfo(CLoadIndexInfo c_load_index_info) {
auto info = (milvus::segcore::LoadIndexInfo*)c_load_index_info;
auto info = static_cast<milvus::segcore::LoadIndexInfo*>(c_load_index_info);
delete info;
}

Expand All @@ -64,7 +64,7 @@ AppendIndexParam(CLoadIndexInfo c_load_index_info,
const char* c_index_value) {
try {
auto load_index_info =
(milvus::segcore::LoadIndexInfo*)c_load_index_info;
static_cast<milvus::segcore::LoadIndexInfo*>(c_load_index_info);
std::string index_key(c_index_key);
std::string index_value(c_index_value);
load_index_info->index_params[index_key] = index_value;
Expand Down Expand Up @@ -92,7 +92,7 @@ AppendFieldInfo(CLoadIndexInfo c_load_index_info,
const char* mmap_dir_path) {
try {
auto load_index_info =
(milvus::segcore::LoadIndexInfo*)c_load_index_info;
static_cast<milvus::segcore::LoadIndexInfo*>(c_load_index_info);
load_index_info->collection_id = collection_id;
load_index_info->partition_id = partition_id;
load_index_info->segment_id = segment_id;
Expand All @@ -117,8 +117,8 @@ CStatus
appendVecIndex(CLoadIndexInfo c_load_index_info, CBinarySet c_binary_set) {
try {
auto load_index_info =
(milvus::segcore::LoadIndexInfo*)c_load_index_info;
auto binary_set = (knowhere::BinarySet*)c_binary_set;
static_cast<milvus::segcore::LoadIndexInfo*>(c_load_index_info);
auto binary_set = static_cast<knowhere::BinarySet*>(c_binary_set);
auto& index_params = load_index_info->index_params;

milvus::index::CreateIndexInfo index_info;
Expand Down Expand Up @@ -175,9 +175,9 @@ CStatus
appendScalarIndex(CLoadIndexInfo c_load_index_info, CBinarySet c_binary_set) {
try {
auto load_index_info =
(milvus::segcore::LoadIndexInfo*)c_load_index_info;
static_cast<milvus::segcore::LoadIndexInfo*>(c_load_index_info);
auto field_type = load_index_info->field_type;
auto binary_set = (knowhere::BinarySet*)c_binary_set;
auto binary_set = static_cast<knowhere::BinarySet*>(c_binary_set);

Check warning on line 180 in internal/core/src/segcore/load_index_c.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/segcore/load_index_c.cpp#L180

Added line #L180 was not covered by tests
auto& index_params = load_index_info->index_params;
bool find_index_type =
index_params.count("index_type") > 0 ? true : false;
Expand Down Expand Up @@ -206,7 +206,7 @@ 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 = (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 @@ -322,7 +322,7 @@ CStatus
AppendIndexFilePath(CLoadIndexInfo c_load_index_info, const char* c_file_path) {
try {
auto load_index_info =
(milvus::segcore::LoadIndexInfo*)c_load_index_info;
static_cast<milvus::segcore::LoadIndexInfo*>(c_load_index_info);
std::string index_file_path(c_file_path);
load_index_info->index_files.emplace_back(index_file_path);

Expand All @@ -345,7 +345,7 @@ AppendIndexInfo(CLoadIndexInfo c_load_index_info,
int64_t version) {
try {
auto load_index_info =
(milvus::segcore::LoadIndexInfo*)c_load_index_info;
static_cast<milvus::segcore::LoadIndexInfo*>(c_load_index_info);
load_index_info->index_id = index_id;
load_index_info->index_build_id = build_id;
load_index_info->index_version = version;
Expand All @@ -367,7 +367,7 @@ AppendIndexEngineVersionToLoadInfo(CLoadIndexInfo c_load_index_info,
int32_t index_engine_version) {
try {
auto load_index_info =
(milvus::segcore::LoadIndexInfo*)c_load_index_info;
static_cast<milvus::segcore::LoadIndexInfo*>(c_load_index_info);
load_index_info->index_engine_version = index_engine_version;

auto status = CStatus();
Expand All @@ -386,7 +386,7 @@ CStatus
CleanLoadedIndex(CLoadIndexInfo c_load_index_info) {
try {
auto load_index_info =
(milvus::segcore::LoadIndexInfo*)c_load_index_info;
static_cast<milvus::segcore::LoadIndexInfo*>(c_load_index_info);
auto local_chunk_manager =
milvus::storage::LocalChunkManagerSingleton::GetInstance()
.GetChunkManager();
Expand All @@ -411,7 +411,7 @@ void
AppendStorageInfo(CLoadIndexInfo c_load_index_info,
const char* uri,
int64_t version) {
auto load_index_info = (milvus::segcore::LoadIndexInfo*)c_load_index_info;
auto load_index_info = static_cast<milvus::segcore::LoadIndexInfo*>(c_load_index_info);

Check warning on line 414 in internal/core/src/segcore/load_index_c.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/segcore/load_index_c.cpp#L414

Added line #L414 was not covered by tests
load_index_info->uri = uri;
load_index_info->index_store_version = version;
}
Expand Down
12 changes: 6 additions & 6 deletions internal/core/src/segcore/plan_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CreateSearchPlanByExpr(CCollection c_col,
const void* serialized_expr_plan,
const int64_t size,
CSearchPlan* res_plan) {
auto col = (milvus::segcore::Collection*)c_col;
auto col = static_cast<milvus::segcore::Collection*>(c_col);

try {
auto res = milvus::query::CreateSearchPlanByExpr(
Expand All @@ -36,7 +36,7 @@ CreateSearchPlanByExpr(CCollection c_col,
auto status = CStatus();
status.error_code = milvus::Success;
status.error_msg = "";
auto plan = (CSearchPlan)res.release();
auto plan = static_cast<CSearchPlan>(res.release());
*res_plan = plan;
return status;
} catch (milvus::SegcoreError& e) {
Expand All @@ -59,16 +59,16 @@ ParsePlaceholderGroup(CSearchPlan c_plan,
const void* placeholder_group_blob,
const int64_t blob_size,
CPlaceholderGroup* res_placeholder_group) {
auto plan = (milvus::query::Plan*)c_plan;
auto plan = static_cast<milvus::query::Plan*>(c_plan);

try {
auto res = milvus::query::ParsePlaceholderGroup(
plan, (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;
status.error_msg = "";
auto group = (CPlaceholderGroup)res.release();
auto group = static_cast<CPlaceholderGroup>(res.release());
*res_placeholder_group = group;
return status;
} catch (std::exception& e) {
Expand Down Expand Up @@ -147,7 +147,7 @@ CreateRetrievePlanByExpr(CCollection c_col,
auto status = CStatus();
status.error_code = milvus::Success;
status.error_msg = "";
auto plan = (CRetrievePlan)res.release();
auto plan = static_cast<CRetrievePlan>(res.release());

Check warning on line 150 in internal/core/src/segcore/plan_c.cpp

View check run for this annotation

Codecov / codecov/patch

internal/core/src/segcore/plan_c.cpp#L150

Added line #L150 was not covered by tests
*res_plan = plan;
return status;
} catch (milvus::SegcoreError& e) {
Expand Down
4 changes: 2 additions & 2 deletions internal/core/src/segcore/segment_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ AsyncSearch(CTraceContext c_trace,
CSearchPlan c_plan,
CPlaceholderGroup c_placeholder_group,
uint64_t timestamp) {
auto segment = (milvus::segcore::SegmentInterface*)c_segment;
auto plan = (milvus::query::Plan*)c_plan;
auto segment = static_cast<milvus::segcore::SegmentInterface*>(c_segment);
auto plan = static_cast<milvus::query::Plan*>(c_plan);
auto phg_ptr = reinterpret_cast<const milvus::query::PlaceholderGroup*>(
c_placeholder_group);

Expand Down
Loading

0 comments on commit db8faa5

Please sign in to comment.