Skip to content

Commit 522176c

Browse files
committed
format code by clang-tidy
Former-commit-id: 524e527a20b8364c32d26f345ebe333e35f167f9
1 parent 9eb09e8 commit 522176c

38 files changed

+532
-229
lines changed

.clang-format

+2
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ AccessModifierOffset: -3
2323
AlwaysBreakAfterReturnType: All
2424
AllowShortBlocksOnASingleLine: false
2525
AllowShortFunctionsOnASingleLine: false
26+
AllowShortIfStatementsOnASingleLine: false
27+
AlignTrailingComments: true

cpp/src/config/YamlConfigMgr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class YamlConfigMgr : public ConfigMgr {
4747
SetConfigValue(const YAML::Node& node, const std::string& key, ConfigNode& config);
4848

4949
bool
50-
SetChildConfig(const YAML::Node& node, const std::string& name, ConfigNode& config);
50+
SetChildConfig(const YAML::Node& node, const std::string& child_name, ConfigNode& config);
5151

5252
bool
5353
SetSequence(const YAML::Node& node, const std::string& child_name, ConfigNode& config);

cpp/src/core/knowhere/knowhere/common/Config.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ struct Cfg {
4646
const int64_t &k,
4747
const int64_t &gpu_id,
4848
METRICTYPE type)
49-
: d(dim), k(k), gpu_id(gpu_id), metric_type(type) {}
49+
: metric_type(type), k(k), gpu_id(gpu_id), d(dim) {}
5050

5151
Cfg() = default;
5252

5353
virtual bool
54-
CheckValid(){};
54+
CheckValid(){
55+
return true;
56+
};
5557
};
5658
using Config = std::shared_ptr<Cfg>;
5759

cpp/src/core/knowhere/knowhere/common/Dataset.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ class Dataset {
127127
//}
128128

129129
private:
130-
SchemaPtr array_schema_;
131-
SchemaPtr tensor_schema_;
132130
std::vector<ArrayPtr> array_;
131+
SchemaPtr array_schema_;
133132
std::vector<TensorPtr> tensor_;
133+
SchemaPtr tensor_schema_;
134134
//Config meta_;
135135
};
136136

cpp/src/core/knowhere/knowhere/index/vector_index/helpers/IndexParameter.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ namespace zilliz {
2525
namespace knowhere {
2626

2727
faiss::MetricType GetMetricType(METRICTYPE &type) {
28-
if (type == METRICTYPE::L2) return faiss::METRIC_L2;
29-
if (type == METRICTYPE::IP) return faiss::METRIC_INNER_PRODUCT;
30-
if (type == METRICTYPE::INVALID) KNOWHERE_THROW_MSG("Metric type is invalid");
28+
if (type == METRICTYPE::L2) {
29+
return faiss::METRIC_L2;
30+
}
31+
if (type == METRICTYPE::IP) {
32+
return faiss::METRIC_INNER_PRODUCT;
33+
}
34+
35+
KNOWHERE_THROW_MSG("Metric type is invalid");
3136
}
3237

3338

cpp/src/core/knowhere/knowhere/index/vector_index/helpers/IndexParameter.h

+22-9
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@ struct IVFCfg : public Cfg {
5252
const int64_t &nlist,
5353
const int64_t &nprobe,
5454
METRICTYPE type)
55-
: nlist(nlist), nprobe(nprobe), Cfg(dim, k, gpu_id, type) {}
55+
: Cfg(dim, k, gpu_id, type), nlist(nlist), nprobe(nprobe) {
56+
}
5657

5758
IVFCfg() = default;
5859

5960
bool
60-
CheckValid() override {};
61+
CheckValid() override {
62+
return true;
63+
};
6164
};
6265
using IVFConfig = std::shared_ptr<IVFCfg>;
6366

@@ -72,12 +75,15 @@ struct IVFSQCfg : public IVFCfg {
7275
const int64_t &nprobe,
7376
const int64_t &nbits,
7477
METRICTYPE type)
75-
: nbits(nbits), IVFCfg(dim, k, gpu_id, nlist, nprobe, type) {}
78+
: IVFCfg(dim, k, gpu_id, nlist, nprobe, type), nbits(nbits) {
79+
}
7680

7781
IVFSQCfg() = default;
7882

7983
bool
80-
CheckValid() override {};
84+
CheckValid() override {
85+
return true;
86+
};
8187
};
8288
using IVFSQConfig = std::shared_ptr<IVFSQCfg>;
8389

@@ -98,12 +104,15 @@ struct IVFPQCfg : public IVFCfg {
98104
const int64_t &nbits,
99105
const int64_t &m,
100106
METRICTYPE type)
101-
: nbits(nbits), m(m), IVFCfg(dim, k, gpu_id, nlist, nprobe, type) {}
107+
: IVFCfg(dim, k, gpu_id, nlist, nprobe, type), m(m), nbits(nbits) {
108+
}
102109

103110
IVFPQCfg() = default;
104111

105112
bool
106-
CheckValid() override {};
113+
CheckValid() override {
114+
return true;
115+
};
107116
};
108117
using IVFPQConfig = std::shared_ptr<IVFPQCfg>;
109118

@@ -123,13 +132,17 @@ struct NSGCfg : public IVFCfg {
123132
const int64_t &out_degree,
124133
const int64_t &candidate_size,
125134
METRICTYPE type)
126-
: knng(knng), search_length(search_length), out_degree(out_degree), candidate_pool_size(candidate_size),
127-
IVFCfg(dim, k, gpu_id, nlist, nprobe, type) {}
135+
: IVFCfg(dim, k, gpu_id, nlist, nprobe, type),
136+
knng(knng), search_length(search_length),
137+
out_degree(out_degree), candidate_pool_size(candidate_size) {
138+
}
128139

129140
NSGCfg() = default;
130141

131142
bool
132-
CheckValid() override {};
143+
CheckValid() override {
144+
return true;
145+
};
133146
};
134147
using NSGConfig = std::shared_ptr<NSGCfg>;
135148

cpp/src/core/knowhere/knowhere/index/vector_index/nsg/NSG.cpp

+18-14
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void NsgIndex::Build_with_ids(size_t nb, const float *data, const long *ids, con
8181
//>> Debug code
8282
///
8383
int total_degree = 0;
84-
for (int i = 0; i < ntotal; ++i) {
84+
for (size_t i = 0; i < ntotal; ++i) {
8585
total_degree += nsg[i].size();
8686
}
8787

@@ -172,7 +172,7 @@ void NsgIndex::GetNeighbors(const float *query,
172172
for (size_t i = 0; i < init_ids.size(); ++i) {
173173
node_t id = init_ids[i];
174174

175-
if (id >= ntotal) {
175+
if (id >= static_cast<node_t>(ntotal)) {
176176
KNOWHERE_THROW_MSG("Build Index Error, id > ntotal");
177177
continue;
178178
}
@@ -262,7 +262,7 @@ void NsgIndex::GetNeighbors(const float *query, std::vector<Neighbor> &resset, s
262262
for (size_t i = 0; i < init_ids.size(); ++i) {
263263
node_t id = init_ids[i];
264264

265-
if (id >= ntotal) {
265+
if (id >= static_cast<node_t>(ntotal)) {
266266
KNOWHERE_THROW_MSG("Build Index Error, id > ntotal");
267267
continue;
268268
}
@@ -350,7 +350,7 @@ void NsgIndex::GetNeighbors(const float *query,
350350
node_t id = init_ids[i];
351351

352352
//assert(id < ntotal);
353-
if (id >= ntotal) {
353+
if (id >= static_cast<node_t>(ntotal)) {
354354
KNOWHERE_THROW_MSG("Build Index Error, id > ntotal");
355355
continue;
356356
}
@@ -461,7 +461,7 @@ void NsgIndex::Link() {
461461
//}
462462
/////
463463

464-
for (int i = 0; i < ntotal; ++i) {
464+
for (size_t i = 0; i < ntotal; ++i) {
465465
nsg[i].shrink_to_fit();
466466
}
467467
}
@@ -483,7 +483,9 @@ void NsgIndex::SyncPrune(size_t n,
483483
unsigned cursor = 0;
484484
std::sort(pool.begin(), pool.end());
485485
std::vector<Neighbor> result;
486-
if (pool[cursor].id == n) cursor++;
486+
if (pool[cursor].id == static_cast<node_t>(n)) {
487+
cursor++;
488+
}
487489
result.push_back(pool[cursor]); // init result with nearest neighbor
488490

489491
SelectEdge(cursor, pool, result, true);
@@ -518,7 +520,7 @@ void NsgIndex::InterInsert(unsigned n, std::vector<std::mutex> &mutex_vec, float
518520
int duplicate = false;
519521
{
520522
LockGuard lk(mutex_vec[current_neighbor]);
521-
for (int j = 0; j < out_degree; ++j) {
523+
for (size_t j = 0; j < out_degree; ++j) {
522524
if (nsn_dist_pool[j] == -1) break;
523525

524526
// 保证至少有一条边能连回来
@@ -551,14 +553,14 @@ void NsgIndex::InterInsert(unsigned n, std::vector<std::mutex> &mutex_vec, float
551553

552554
{
553555
LockGuard lk(mutex_vec[current_neighbor]);
554-
for (int j = 0; j < result.size(); ++j) {
556+
for (size_t j = 0; j < result.size(); ++j) {
555557
nsn_id_pool[j] = result[j].id;
556558
nsn_dist_pool[j] = result[j].distance;
557559
}
558560
}
559561
} else {
560562
LockGuard lk(mutex_vec[current_neighbor]);
561-
for (int j = 0; j < out_degree; ++j) {
563+
for (size_t j = 0; j < out_degree; ++j) {
562564
if (nsn_dist_pool[j] == -1) {
563565
nsn_id_pool.push_back(current_as_neighbor.id);
564566
nsn_dist_pool[j] = current_as_neighbor.distance;
@@ -605,9 +607,11 @@ void NsgIndex::CheckConnectivity() {
605607
boost::dynamic_bitset<> has_linked{ntotal, 0};
606608
int64_t linked_count = 0;
607609

608-
while (linked_count < ntotal) {
610+
while (linked_count < static_cast<int64_t>(ntotal)) {
609611
DFS(root, has_linked, linked_count);
610-
if (linked_count >= ntotal) break;
612+
if (linked_count >= static_cast<int64_t>(ntotal)) {
613+
break;
614+
}
611615
FindUnconnectedNode(has_linked, root);
612616
}
613617
}
@@ -697,16 +701,16 @@ void NsgIndex::Search(const float *query,
697701
} else{
698702
//#pragma omp parallel for schedule(dynamic, 50)
699703
#pragma omp parallel for
700-
for (int i = 0; i < nq; ++i) {
704+
for (unsigned int i = 0; i < nq; ++i) {
701705
// TODO(linxj): when to use openmp
702706
auto single_query = query + i * dim;
703707
GetNeighbors(single_query, resset[i], nsg, &params);
704708
}
705709
}
706710
rc.ElapseFromBegin("cost");
707711

708-
for (int i = 0; i < nq; ++i) {
709-
for (int j = 0; j < k; ++j) {
712+
for (unsigned int i = 0; i < nq; ++i) {
713+
for (unsigned int j = 0; j < k; ++j) {
710714
//ids[i * k + j] = resset[i][j].id;
711715

712716
// Fix(linxj): bug, reset[i][j] out of range

cpp/src/core/knowhere/knowhere/index/vector_index/nsg/NSGHelper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace algo {
2929
// TODO: impl search && insert && return insert pos. why not just find and swap?
3030
int InsertIntoPool(Neighbor *addr, unsigned K, Neighbor nn) {
3131
//>> Fix: Add assert
32-
for (int i = 0; i < K; ++i) {
32+
for (unsigned int i = 0; i < K; ++i) {
3333
assert(addr[i].id != nn.id);
3434
}
3535

cpp/src/core/test/utils.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ void DataGen::Generate(const int &dim, const int &nb, const int &nq) {
3838
this->dim = dim;
3939

4040
GenAll(dim, nb, xb, ids, nq, xq);
41-
assert(xb.size() == dim * nb);
42-
assert(xq.size() == dim * nq);
41+
assert(xb.size() == (size_t)dim * nb);
42+
assert(xq.size() == (size_t)dim * nq);
4343

4444
base_dataset = generate_dataset(nb, dim, xb.data(), ids.data());
4545
query_dataset = generate_query_dataset(nq, dim, xq.data());
4646

4747
}
4848
zilliz::knowhere::DatasetPtr DataGen::GenQuery(const int &nq) {
4949
xq.resize(nq * dim);
50-
for (size_t i = 0; i < nq * dim; ++i) {
50+
for (int i = 0; i < nq * dim; ++i) {
5151
xq[i] = xb[i];
5252
}
5353
return generate_query_dataset(nq, dim, xq.data());
@@ -72,7 +72,7 @@ void GenAll(const int64_t &dim,
7272
const int64_t &nq,
7373
float *xq) {
7474
GenBase(dim, nb, xb, ids);
75-
for (size_t i = 0; i < nq * dim; ++i) {
75+
for (int64_t i = 0; i < nq * dim; ++i) {
7676
xq[i] = xb[i];
7777
}
7878
}

cpp/src/db/DBImpl.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,8 @@ DBImpl::MergeFiles(const std::string& table_id, const meta::DateT& date, const m
638638
ENGINE_LOG_DEBUG << "Merging file " << file_schema.file_id_;
639639
index_size = index->Size();
640640

641-
if (index_size >= file_schema.index_file_size_) break;
641+
if (index_size >= file_schema.index_file_size_)
642+
break;
642643
}
643644

644645
// step 3: serialize to disk

cpp/src/db/Options.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ struct ArchiveConf {
5353

5454
private:
5555
void
56-
ParseCritirias(const std::string& type);
56+
ParseCritirias(const std::string& criterias);
5757
void
58-
ParseType(const std::string& criterias);
58+
ParseType(const std::string& type);
5959

6060
std::string type_;
6161
CriteriaT criterias_;

cpp/src/db/Utils.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ GetTableFilePath(const DBMetaOptions& options, meta::TableFileSchema& table_file
143143
if (boost::filesystem::exists(file_path)) {
144144
table_file.location_ = file_path;
145145
return Status::OK();
146-
} else {
147-
for (auto& path : options.slave_paths_) {
148-
parent_path = ConstructParentFolder(path, table_file);
149-
file_path = parent_path + "/" + table_file.file_id_;
150-
if (boost::filesystem::exists(file_path)) {
151-
table_file.location_ = file_path;
152-
return Status::OK();
153-
}
146+
}
147+
148+
for (auto& path : options.slave_paths_) {
149+
parent_path = ConstructParentFolder(path, table_file);
150+
file_path = parent_path + "/" + table_file.file_id_;
151+
if (boost::filesystem::exists(file_path)) {
152+
table_file.location_ = file_path;
153+
return Status::OK();
154154
}
155155
}
156156

cpp/src/db/engine/ExecutionEngineImpl.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ Status
342342
ExecutionEngineImpl::Init() {
343343
server::Config& config = server::Config::GetInstance();
344344
Status s = config.GetDBConfigBuildIndexGPU(gpu_num_);
345-
if (!s.ok()) return s;
345+
if (!s.ok())
346+
return s;
346347

347348
return Status::OK();
348349
}

cpp/src/main.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ main(int argc, char* argv[]) {
3939
std::cout << std::endl << "Welcome to use Milvus by Zilliz!" << std::endl;
4040
std::cout << "Milvus " << BUILD_TYPE << " version: v" << MILVUS_VERSION << " built at " << BUILD_TIME << std::endl;
4141

42-
static struct option long_options[] = {{"conf_file", required_argument, 0, 'c'},
43-
{"log_conf_file", required_argument, 0, 'l'},
44-
{"help", no_argument, 0, 'h'},
45-
{"daemon", no_argument, 0, 'd'},
46-
{"pid_file", required_argument, 0, 'p'},
47-
{NULL, 0, 0, 0}};
42+
static struct option long_options[] = {{"conf_file", required_argument, nullptr, 'c'},
43+
{"log_conf_file", required_argument, nullptr, 'l'},
44+
{"help", no_argument, nullptr, 'h'},
45+
{"daemon", no_argument, nullptr, 'd'},
46+
{"pid_file", required_argument, nullptr, 'p'},
47+
{nullptr, 0, nullptr, 0}};
4848

4949
int option_index = 0;
5050
int64_t start_daemonized = 0;

0 commit comments

Comments
 (0)