Skip to content

Commit d9647ce

Browse files
committed
resolving PR comments
1 parent cd5f534 commit d9647ce

5 files changed

Lines changed: 91 additions & 112 deletions

File tree

include/abstract_graph_store.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,28 @@ namespace diskann
1313
class AbstractGraphStore
1414
{
1515
public:
16-
AbstractGraphStore(const size_t max_pts) : _capacity(max_pts)
16+
AbstractGraphStore(const size_t total_pts) : _capacity(total_pts)
1717
{
1818
}
1919

2020
virtual int load(const std::string &index_path_prefix) = 0;
21-
virtual int store(const std::string &index_path_prefix, const size_t active_points) = 0;
21+
virtual int store(const std::string &index_path_prefix, const size_t num_points) = 0;
2222

23+
// not synchronised, user should use lock when necvessary.
2324
virtual std::vector<location_t> &get_neighbours(const location_t i) = 0;
2425
virtual void set_neighbours(const location_t i, std::vector<location_t> &neighbors) = 0;
2526

2627
virtual size_t resize_graph(const size_t new_size) = 0;
2728
virtual void clear_graph() = 0;
2829

29-
virtual size_t get_num_frozen_points() = 0;
30-
virtual size_t get_max_range_of_loaded_graph() = 0;
30+
virtual size_t get_max_range_of_graph() = 0;
3131

3232
virtual uint32_t get_max_observed_degree() = 0;
3333
virtual void set_max_observed_degree(uint32_t max_observed_degree) = 0;
3434

3535
virtual uint32_t get_start() = 0;
3636
virtual void set_start(uint32_t start) = 0;
3737

38-
// Active points in graph, it is different then total_points capacity
39-
/*virtual size_t get_active_points() = 0;
40-
virtual void set_active_points(size_t active_points) = 0;*/
41-
4238
// returns new size after shrinking graph
4339
virtual size_t shrink_to_fit() = 0;
4440

include/in_mem_graph_store.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@ namespace diskann
1111
class InMemGraphStore : public AbstractGraphStore
1212
{
1313
public:
14-
InMemGraphStore(const size_t max_pts, const size_t frozen_points);
14+
InMemGraphStore(const size_t total_pts, const size_t num_frozen_points);
1515

1616
int load(const std::string &index_path_prefix);
17-
int store(const std::string &index_path_prefix, const size_t active_points);
17+
int store(const std::string &index_path_prefix, const size_t num_points);
1818

1919
virtual std::vector<location_t> &get_neighbours(const location_t i) override;
2020
virtual void set_neighbours(const location_t i, std::vector<location_t> &neighbors) override;
2121

2222
virtual size_t resize_graph(const size_t new_size) override;
2323
virtual void clear_graph() override;
2424

25-
virtual size_t get_num_frozen_points() override;
26-
virtual size_t get_max_range_of_loaded_graph() override;
25+
virtual size_t get_max_range_of_graph() override;
2726
virtual uint32_t get_max_observed_degree() override;
2827
virtual void set_max_observed_degree(uint32_t max_observed_degree) override;
2928
virtual uint32_t get_start() override;
@@ -40,7 +39,7 @@ class InMemGraphStore : public AbstractGraphStore
4039
int save_graph(const std::string &index_path_prefix, const size_t active_points);
4140

4241
private:
43-
size_t _max_range_of_loaded_graph = 0;
42+
size_t _max_range_of_graph = 0;
4443
uint32_t _max_observed_degree = 0;
4544
uint32_t _start = 0;
4645
size_t _num_frozen_pts;

include/index.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ template <typename T, typename TagT = uint32_t, typename LabelT = uint32_t> clas
351351
// externally and won't be returned by search. At least 1 frozen point is
352352
// needed for a dynamic index. The frozen points have consecutive locations.
353353
// See also _start below.
354+
size_t _num_frozen_pts;
354355
size_t _node_size;
355356
size_t _data_len;
356357
size_t _neighbor_len;

src/in_mem_graph_store.cpp

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
namespace diskann
88
{
99

10-
InMemGraphStore::InMemGraphStore(const size_t max_pts, const size_t frozen_points)
11-
: AbstractGraphStore(max_pts), _num_frozen_pts(frozen_points)
10+
InMemGraphStore::InMemGraphStore(const size_t total_pts, const size_t num_frozen_pts)
11+
: AbstractGraphStore(total_pts), _num_frozen_pts(num_frozen_pts)
1212
{
1313
}
1414

1515
int InMemGraphStore::load(const std::string &index_path_prefix)
1616
{
17-
return load_impl(index_path_prefix, get_total_points() - _num_frozen_pts);
17+
return load_impl(index_path_prefix, get_total_points());
1818
}
19-
int InMemGraphStore::store(const std::string &index_path_prefix, const size_t active_points)
19+
int InMemGraphStore::store(const std::string &index_path_prefix, const size_t num_points)
2020
{
21-
return save_graph(index_path_prefix, active_points);
21+
return save_graph(index_path_prefix, num_points);
2222
}
2323
std::vector<location_t> &InMemGraphStore::get_neighbours(const location_t i)
2424
{
@@ -114,9 +114,9 @@ location_t InMemGraphStore::load_impl(const std::string &filename, size_t expect
114114
{
115115
diskann::cout << "." << std::flush;
116116
}
117-
if (k > _max_range_of_loaded_graph)
117+
if (k > _max_range_of_graph)
118118
{
119-
_max_range_of_loaded_graph = k;
119+
_max_range_of_graph = k;
120120
}
121121
}
122122

@@ -130,8 +130,7 @@ location_t InMemGraphStore::load_impl(const std::string &filename, size_t expect
130130
{
131131
size_t expected_file_size;
132132
size_t file_frozen_pts;
133-
size_t file_offset = 0; // will need this for single file format support
134-
auto max_points = get_total_points(); // from parent class holding max_pts
133+
size_t file_offset = 0; // will need this for single file format support
135134

136135
std::ifstream in;
137136
in.exceptions(std::ios::badbit | std::ios::failbit);
@@ -152,7 +151,7 @@ location_t InMemGraphStore::load_impl(const std::string &filename, size_t expect
152151
std::stringstream stream;
153152
if (file_frozen_pts == 1)
154153
{
155-
stream << "ERROR: When loading index, detected dynamic index, but "
154+
stream << "ERROR: When loading graph, detected dynamic index, but "
156155
"constructor asks for static index. Exitting."
157156
<< std::endl;
158157
}
@@ -172,13 +171,13 @@ location_t InMemGraphStore::load_impl(const std::string &filename, size_t expect
172171

173172
// If user provides more points than max_points
174173
// resize the _graph to the larger size.
174+
auto max_points = get_total_points() - _num_frozen_pts; // from parent class holding max_pts
175175
if (max_points < expected_max_points)
176176
{
177177
diskann::cout << "Number of points in data: " << expected_max_points
178178
<< " is greater than max_points: " << max_points
179179
<< " Setting max points to: " << expected_max_points << std::endl;
180-
_graph.resize(expected_max_points + _num_frozen_pts);
181-
// _max_points = expected_max_points;
180+
_graph.resize(expected_max_points + file_frozen_pts);
182181
}
183182

184183
size_t bytes_read = vamana_metadata_size;
@@ -203,9 +202,9 @@ location_t InMemGraphStore::load_impl(const std::string &filename, size_t expect
203202
bytes_read += sizeof(uint32_t) * ((size_t)k + 1);
204203
if (nodes_read % 10000000 == 0)
205204
diskann::cout << "." << std::flush;
206-
if (k > _max_range_of_loaded_graph)
205+
if (k > _max_range_of_graph)
207206
{
208-
_max_range_of_loaded_graph = k;
207+
_max_range_of_graph = k;
209208
}
210209
}
211210

@@ -214,7 +213,7 @@ location_t InMemGraphStore::load_impl(const std::string &filename, size_t expect
214213
return nodes_read;
215214
}
216215

217-
int InMemGraphStore::save_graph(const std::string &index_path_prefix, const size_t active_points)
216+
int InMemGraphStore::save_graph(const std::string &index_path_prefix, const size_t num_points)
218217
{
219218
std::ofstream out;
220219
open_file_to_write(out, index_path_prefix);
@@ -228,10 +227,9 @@ int InMemGraphStore::save_graph(const std::string &index_path_prefix, const size
228227
uint32_t ep_u32 = _start;
229228
out.write((char *)&ep_u32, sizeof(uint32_t));
230229
out.write((char *)&_num_frozen_pts, sizeof(size_t));
231-
// Note: at this point, either active_points == _max_points or any frozen points have
232-
// been temporarily moved to active_points, so active_points + _num_frozen_points is the valid
233-
// location limit(active_points corresponds to _nd in index.h).
234-
for (uint32_t i = 0; i < active_points + _num_frozen_pts; i++)
230+
231+
// Note: num_points = _nd + _num_frozen_points
232+
for (uint32_t i = 0; i < num_points; i++)
235233
{
236234
uint32_t GK = (uint32_t)_graph[i].size();
237235
out.write((char *)&GK, sizeof(uint32_t));
@@ -246,13 +244,9 @@ int InMemGraphStore::save_graph(const std::string &index_path_prefix, const size
246244
return (int)index_size;
247245
}
248246

249-
size_t InMemGraphStore::get_num_frozen_points()
250-
{
251-
return _num_frozen_pts;
252-
}
253-
size_t InMemGraphStore::get_max_range_of_loaded_graph()
247+
size_t InMemGraphStore::get_max_range_of_graph()
254248
{
255-
return _max_range_of_loaded_graph;
249+
return _max_range_of_graph;
256250
}
257251
uint32_t InMemGraphStore::get_max_observed_degree()
258252
{

0 commit comments

Comments
 (0)