@@ -81,7 +81,7 @@ void NsgIndex::Build_with_ids(size_t nb, const float *data, const long *ids, con
81
81
// >> Debug code
82
82
// /
83
83
int total_degree = 0 ;
84
- for (int i = 0 ; i < ntotal; ++i) {
84
+ for (size_t i = 0 ; i < ntotal; ++i) {
85
85
total_degree += nsg[i].size ();
86
86
}
87
87
@@ -172,7 +172,7 @@ void NsgIndex::GetNeighbors(const float *query,
172
172
for (size_t i = 0 ; i < init_ids.size (); ++i) {
173
173
node_t id = init_ids[i];
174
174
175
- if (id >= ntotal) {
175
+ if (id >= static_cast < node_t >( ntotal) ) {
176
176
KNOWHERE_THROW_MSG (" Build Index Error, id > ntotal" );
177
177
continue ;
178
178
}
@@ -262,7 +262,7 @@ void NsgIndex::GetNeighbors(const float *query, std::vector<Neighbor> &resset, s
262
262
for (size_t i = 0 ; i < init_ids.size (); ++i) {
263
263
node_t id = init_ids[i];
264
264
265
- if (id >= ntotal) {
265
+ if (id >= static_cast < node_t >( ntotal) ) {
266
266
KNOWHERE_THROW_MSG (" Build Index Error, id > ntotal" );
267
267
continue ;
268
268
}
@@ -350,7 +350,7 @@ void NsgIndex::GetNeighbors(const float *query,
350
350
node_t id = init_ids[i];
351
351
352
352
// assert(id < ntotal);
353
- if (id >= ntotal) {
353
+ if (id >= static_cast < node_t >( ntotal) ) {
354
354
KNOWHERE_THROW_MSG (" Build Index Error, id > ntotal" );
355
355
continue ;
356
356
}
@@ -461,7 +461,7 @@ void NsgIndex::Link() {
461
461
// }
462
462
// ///
463
463
464
- for (int i = 0 ; i < ntotal; ++i) {
464
+ for (size_t i = 0 ; i < ntotal; ++i) {
465
465
nsg[i].shrink_to_fit ();
466
466
}
467
467
}
@@ -483,7 +483,9 @@ void NsgIndex::SyncPrune(size_t n,
483
483
unsigned cursor = 0 ;
484
484
std::sort (pool.begin (), pool.end ());
485
485
std::vector<Neighbor> result;
486
- if (pool[cursor].id == n) cursor++;
486
+ if (pool[cursor].id == static_cast <node_t >(n)) {
487
+ cursor++;
488
+ }
487
489
result.push_back (pool[cursor]); // init result with nearest neighbor
488
490
489
491
SelectEdge (cursor, pool, result, true );
@@ -518,7 +520,7 @@ void NsgIndex::InterInsert(unsigned n, std::vector<std::mutex> &mutex_vec, float
518
520
int duplicate = false ;
519
521
{
520
522
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) {
522
524
if (nsn_dist_pool[j] == -1 ) break ;
523
525
524
526
// 保证至少有一条边能连回来
@@ -551,14 +553,14 @@ void NsgIndex::InterInsert(unsigned n, std::vector<std::mutex> &mutex_vec, float
551
553
552
554
{
553
555
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) {
555
557
nsn_id_pool[j] = result[j].id ;
556
558
nsn_dist_pool[j] = result[j].distance ;
557
559
}
558
560
}
559
561
} else {
560
562
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) {
562
564
if (nsn_dist_pool[j] == -1 ) {
563
565
nsn_id_pool.push_back (current_as_neighbor.id );
564
566
nsn_dist_pool[j] = current_as_neighbor.distance ;
@@ -605,9 +607,11 @@ void NsgIndex::CheckConnectivity() {
605
607
boost::dynamic_bitset<> has_linked{ntotal, 0 };
606
608
int64_t linked_count = 0 ;
607
609
608
- while (linked_count < ntotal) {
610
+ while (linked_count < static_cast < int64_t >( ntotal) ) {
609
611
DFS (root, has_linked, linked_count);
610
- if (linked_count >= ntotal) break ;
612
+ if (linked_count >= static_cast <int64_t >(ntotal)) {
613
+ break ;
614
+ }
611
615
FindUnconnectedNode (has_linked, root);
612
616
}
613
617
}
@@ -697,16 +701,16 @@ void NsgIndex::Search(const float *query,
697
701
} else {
698
702
// #pragma omp parallel for schedule(dynamic, 50)
699
703
#pragma omp parallel for
700
- for (int i = 0 ; i < nq; ++i) {
704
+ for (unsigned int i = 0 ; i < nq; ++i) {
701
705
// TODO(linxj): when to use openmp
702
706
auto single_query = query + i * dim;
703
707
GetNeighbors (single_query, resset[i], nsg, ¶ms);
704
708
}
705
709
}
706
710
rc.ElapseFromBegin (" cost" );
707
711
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) {
710
714
// ids[i * k + j] = resset[i][j].id;
711
715
712
716
// Fix(linxj): bug, reset[i][j] out of range
0 commit comments