Skip to content

Commit

Permalink
Re-format cpp code (milvus-io#22513)
Browse files Browse the repository at this point in the history
Signed-off-by: yah01 <[email protected]>
  • Loading branch information
yah01 authored Mar 2, 2023
1 parent fa86de5 commit bdd6bc7
Show file tree
Hide file tree
Showing 145 changed files with 3,291 additions and 1,446 deletions.
6 changes: 4 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Below is copied from milvus project
BasedOnStyle: Google
DerivePointerAlignment: false
ColumnLimit: 120
ColumnLimit: 80
IndentWidth: 4
AccessModifierOffset: -3
AlwaysBreakAfterReturnType: All
Expand All @@ -28,7 +28,9 @@ AllowShortIfStatementsOnASingleLine: false
AlignTrailingComments: true

# Appended Options
SortIncludes: false
SortIncludes: false
Standard: Latest
AlignAfterOpenBracket: Align
BinPackParameters: false
BinPackArguments: false
ReflowComments: false
15 changes: 11 additions & 4 deletions internal/core/src/common/BitsetView.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ class BitsetView : public knowhere::BitsetView {
BitsetView() = default;
~BitsetView() = default;

BitsetView(const std::nullptr_t value) : knowhere::BitsetView(value) { // NOLINT
BitsetView(const std::nullptr_t value)
: knowhere::BitsetView(value) { // NOLINT
}

BitsetView(const uint8_t* data, size_t num_bits) : knowhere::BitsetView(data, num_bits) { // NOLINT
BitsetView(const uint8_t* data, size_t num_bits)
: knowhere::BitsetView(data, num_bits) { // NOLINT
}

BitsetView(const BitsetType& bitset) // NOLINT
: BitsetView((uint8_t*)boost_ext::get_data(bitset), size_t(bitset.size())) {
: BitsetView((uint8_t*)boost_ext::get_data(bitset),
size_t(bitset.size())) {
}

BitsetView(const BitsetTypePtr& bitset_ptr) { // NOLINT
Expand All @@ -56,7 +59,11 @@ class BitsetView : public knowhere::BitsetView {

AssertInfo((offset & 0x7) == 0, "offset is not divisible by 8");
AssertInfo(offset + size <= this->size(),
fmt::format("index out of range, offset={}, size={}, bitset.size={}", offset, size, this->size()));
fmt::format(
"index out of range, offset={}, size={}, bitset.size={}",
offset,
size,
this->size()));
return {data() + (offset >> 3), size};
}
};
Expand Down
4 changes: 3 additions & 1 deletion internal/core/src/common/CDataType.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

namespace milvus {

template <typename T, typename = std::enable_if_t<std::is_fundamental_v<T> || std::is_same_v<T, std::string>>>
template <typename T,
typename = std::enable_if_t<std::is_fundamental_v<T> ||
std::is_same_v<T, std::string>>>
inline CDataType
GetDType() {
return None;
Expand Down
6 changes: 4 additions & 2 deletions internal/core/src/common/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ int cpu_num = DEFAULT_CPU_NUM;
void
SetIndexSliceSize(const int64_t size) {
index_file_slice_size = size;
LOG_SEGCORE_DEBUG_ << "set config index slice size: " << index_file_slice_size;
LOG_SEGCORE_DEBUG_ << "set config index slice size: "
<< index_file_slice_size;
}

void
SetThreadCoreCoefficient(const int64_t coefficient) {
thread_core_coefficient = coefficient;
LOG_SEGCORE_DEBUG_ << "set thread pool core coefficient: " << thread_core_coefficient;
LOG_SEGCORE_DEBUG_ << "set thread pool core coefficient: "
<< thread_core_coefficient;
}

void
Expand Down
34 changes: 25 additions & 9 deletions internal/core/src/common/FieldMeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,17 @@ datatype_name(DataType data_type) {
return "vector_binary";
}
default: {
auto err_msg = "Unsupported DataType(" + std::to_string((int)data_type) + ")";
auto err_msg =
"Unsupported DataType(" + std::to_string((int)data_type) + ")";
PanicInfo(err_msg);
}
}
}

inline bool
datatype_is_vector(DataType datatype) {
return datatype == DataType::VECTOR_BINARY || datatype == DataType::VECTOR_FLOAT;
return datatype == DataType::VECTOR_BINARY ||
datatype == DataType::VECTOR_FLOAT;
}

inline bool
Expand Down Expand Up @@ -148,25 +150,39 @@ class FieldMeta {
FieldMeta&
operator=(FieldMeta&&) = default;

FieldMeta(const FieldName& name, FieldId id, DataType type) : name_(name), id_(id), type_(type) {
FieldMeta(const FieldName& name, FieldId id, DataType type)
: name_(name), id_(id), type_(type) {
Assert(!is_vector());
}

FieldMeta(const FieldName& name, FieldId id, DataType type, int64_t max_length)
: name_(name), id_(id), type_(type), string_info_(StringInfo{max_length}) {
FieldMeta(const FieldName& name,
FieldId id,
DataType type,
int64_t max_length)
: name_(name),
id_(id),
type_(type),
string_info_(StringInfo{max_length}) {
Assert(is_string());
}

FieldMeta(
const FieldName& name, FieldId id, DataType type, int64_t dim, std::optional<knowhere::MetricType> metric_type)
: name_(name), id_(id), type_(type), vector_info_(VectorInfo{dim, metric_type}) {
FieldMeta(const FieldName& name,
FieldId id,
DataType type,
int64_t dim,
std::optional<knowhere::MetricType> metric_type)
: name_(name),
id_(id),
type_(type),
vector_info_(VectorInfo{dim, metric_type}) {
Assert(is_vector());
}

bool
is_vector() const {
Assert(type_ != DataType::NONE);
return type_ == DataType::VECTOR_BINARY || type_ == DataType::VECTOR_FLOAT;
return type_ == DataType::VECTOR_BINARY ||
type_ == DataType::VECTOR_FLOAT;
}

bool
Expand Down
3 changes: 2 additions & 1 deletion internal/core/src/common/QueryResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ struct SearchResult {
if (topk_per_nq_prefix_sum_.empty()) {
return 0;
}
AssertInfo(topk_per_nq_prefix_sum_.size() == total_nq_ + 1, "wrong topk_per_nq_prefix_sum_ size");
AssertInfo(topk_per_nq_prefix_sum_.size() == total_nq_ + 1,
"wrong topk_per_nq_prefix_sum_ size");
return topk_per_nq_prefix_sum_[total_nq_];
}

Expand Down
26 changes: 17 additions & 9 deletions internal/core/src/common/RangeSearchHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,28 @@ namespace {
using ResultPair = std::pair<float, int64_t>;
}
DatasetPtr
SortRangeSearchResult(DatasetPtr data_set, int64_t topk, int64_t nq, std::string metric_type) {
SortRangeSearchResult(DatasetPtr data_set,
int64_t topk,
int64_t nq,
std::string metric_type) {
/**
* nq: number of querys;
* lims: the size of lims is nq + 1, lims[i+1] - lims[i] refers to the size of RangeSearch result querys[i]
* for example, the nq is 5. In the seleted range,
* nq: number of queries;
* lims: the size of lims is nq + 1, lims[i+1] - lims[i] refers to the size of RangeSearch result queries[i]
* for example, the nq is 5. In the selected range,
* the size of RangeSearch result for each nq is [1, 2, 3, 4, 5],
* the lims will be [0, 1, 3, 6, 10, 15];
* ids: the size of ids is lim[nq],
* { i(0,0), i(0,1), …, i(0,k0-1),
* i(1,0), i(1,1), …, i(1,k1-1),
* …,
* i(n-1,0), i(n-1,1), …, i(n-1,kn-1)},
* i(0,0), i(0,1), …, i(0,k0-1) means the ids of RangeSearch result querys[0], k0 equals lim[1] - lim[0];
* i(0,0), i(0,1), …, i(0,k0-1) means the ids of RangeSearch result queries[0], k0 equals lim[1] - lim[0];
* dist: the size of ids is lim[nq],
* { d(0,0), d(0,1), …, d(0,k0-1),
* d(1,0), d(1,1), …, d(1,k1-1),
* …,
* d(n-1,0), d(n-1,1), …, d(n-1,kn-1)},
* d(0,0), d(0,1), …, d(0,k0-1) means the distances of RangeSearch result querys[0], k0 equals lim[1] - lim[0];
* d(0,0), d(0,1), …, d(0,k0-1) means the distances of RangeSearch result queries[0], k0 equals lim[1] - lim[0];
*/
auto lims = GetDatasetLims(data_set);
auto id = GetDatasetIDs(data_set);
Expand All @@ -65,11 +68,14 @@ SortRangeSearchResult(DatasetPtr data_set, int64_t topk, int64_t nq, std::string
* |------------+---------------| max_heap ascending_order
*
*/
std::function<bool(const ResultPair&, const ResultPair&)> cmp = std::less<std::pair<float, int64_t>>();
std::function<bool(const ResultPair&, const ResultPair&)> cmp =
std::less<std::pair<float, int64_t>>();
if (IsMetricType(metric_type, knowhere::metric::IP)) {
cmp = std::greater<std::pair<float, int64_t>>();
}
std::priority_queue<std::pair<float, int64_t>, std::vector<std::pair<float, int64_t>>, decltype(cmp)>
std::priority_queue<std::pair<float, int64_t>,
std::vector<std::pair<float, int64_t>>,
decltype(cmp)>
sub_result(cmp);

for (int j = lims[i]; j < lims[i + 1]; j++) {
Expand All @@ -94,7 +100,9 @@ SortRangeSearchResult(DatasetPtr data_set, int64_t topk, int64_t nq, std::string
}

void
CheckRangeSearchParam(float radius, float range_filter, std::string metric_type) {
CheckRangeSearchParam(float radius,
float range_filter,
std::string metric_type) {
/*
* IP: 1.0 range_filter radius
* |------------+---------------| min_heap descending_order
Expand Down
9 changes: 7 additions & 2 deletions internal/core/src/common/RangeSearchHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
namespace milvus {

DatasetPtr
SortRangeSearchResult(DatasetPtr data_set, int64_t topk, int64_t nq, std::string metric_type);
SortRangeSearchResult(DatasetPtr data_set,
int64_t topk,
int64_t nq,
std::string metric_type);

void
CheckRangeSearchParam(float radius, float range_filter, std::string metric_type);
CheckRangeSearchParam(float radius,
float range_filter,
std::string metric_type);
} // namespace milvus
29 changes: 20 additions & 9 deletions internal/core/src/common/Schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ namespace milvus {

using std::string;
static std::map<string, string>
RepeatedKeyValToMap(const google::protobuf::RepeatedPtrField<proto::common::KeyValuePair>& kvs) {
RepeatedKeyValToMap(
const google::protobuf::RepeatedPtrField<proto::common::KeyValuePair>&
kvs) {
std::map<string, string> mapping;
for (auto& kv : kvs) {
AssertInfo(!mapping.count(kv.key()), "repeat key(" + kv.key() + ") in protobuf");
AssertInfo(!mapping.count(kv.key()),
"repeat key(" + kv.key() + ") in protobuf");
mapping.emplace(kv.key(), kv.value());
}
return mapping;
Expand All @@ -42,15 +45,18 @@ Schema::ParseFrom(const milvus::proto::schema::CollectionSchema& schema_proto) {

// NOTE: only two system

for (const milvus::proto::schema::FieldSchema& child : schema_proto.fields()) {
for (const milvus::proto::schema::FieldSchema& child :
schema_proto.fields()) {
auto field_id = FieldId(child.fieldid());
auto name = FieldName(child.name());

if (field_id.get() < 100) {
// system field id
auto is_system = SystemProperty::Instance().SystemFieldVerify(name, field_id);
auto is_system =
SystemProperty::Instance().SystemFieldVerify(name, field_id);
AssertInfo(is_system,
"invalid system type: name(" + name.get() + "), id(" + std::to_string(field_id.get()) + ")");
"invalid system type: name(" + name.get() + "), id(" +
std::to_string(field_id.get()) + ")");
continue;
}

Expand All @@ -71,23 +77,28 @@ Schema::ParseFrom(const milvus::proto::schema::CollectionSchema& schema_proto) {
} else if (datatype_is_string(data_type)) {
auto type_map = RepeatedKeyValToMap(child.type_params());
AssertInfo(type_map.count(MAX_LENGTH), "max_length not found");
auto max_len = boost::lexical_cast<int64_t>(type_map.at(MAX_LENGTH));
auto max_len =
boost::lexical_cast<int64_t>(type_map.at(MAX_LENGTH));
schema->AddField(name, field_id, data_type, max_len);
} else {
schema->AddField(name, field_id, data_type);
}

if (child.is_primary_key()) {
AssertInfo(!schema->get_primary_field_id().has_value(), "repetitive primary key");
AssertInfo(!schema->get_primary_field_id().has_value(),
"repetitive primary key");
schema->set_primary_field_id(field_id);
}
}

AssertInfo(schema->get_primary_field_id().has_value(), "primary key should be specified");
AssertInfo(schema->get_primary_field_id().has_value(),
"primary key should be specified");

return schema;
}

const FieldMeta FieldMeta::RowIdMeta(FieldName("RowID"), RowFieldID, DataType::INT64);
const FieldMeta FieldMeta::RowIdMeta(FieldName("RowID"),
RowFieldID,
DataType::INT64);

} // namespace milvus
14 changes: 10 additions & 4 deletions internal/core/src/common/Schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class Schema {
std::optional<knowhere::MetricType> metric_type) {
auto field_id = FieldId(debug_id);
debug_id++;
auto field_meta = FieldMeta(FieldName(name), field_id, data_type, dim, metric_type);
auto field_meta =
FieldMeta(FieldName(name), field_id, data_type, dim, metric_type);
this->AddField(std::move(field_meta));
return field_id;
}
Expand All @@ -63,7 +64,10 @@ class Schema {

// string type
void
AddField(const FieldName& name, const FieldId id, DataType data_type, int64_t max_length) {
AddField(const FieldName& name,
const FieldId id,
DataType data_type,
int64_t max_length) {
auto field_meta = FieldMeta(name, id, data_type, max_length);
this->AddField(std::move(field_meta));
}
Expand Down Expand Up @@ -103,7 +107,8 @@ class Schema {
operator[](FieldId field_id) const {
Assert(field_id.get() >= 0);
AssertInfo(fields_.find(field_id) != fields_.end(),
"Cannot find field with field_id: " + std::to_string(field_id.get()));
"Cannot find field with field_id: " +
std::to_string(field_id.get()));
return fields_.at(field_id);
}

Expand Down Expand Up @@ -131,7 +136,8 @@ class Schema {
const FieldMeta&
operator[](const FieldName& field_name) const {
auto id_iter = name_ids_.find(field_name);
AssertInfo(id_iter != name_ids_.end(), "Cannot find field with field_name: " + field_name.get());
AssertInfo(id_iter != name_ids_.end(),
"Cannot find field with field_name: " + field_name.get());
return fields_.at(id_iter->second);
}

Expand Down
Loading

0 comments on commit bdd6bc7

Please sign in to comment.