Skip to content

Commit a6be265

Browse files
author
Hilik Yochai
committed
few bugs fix and complete missing methods
1 parent 3202aed commit a6be265

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

src/VecSim/algorithms/hnsw/abs_graph_data.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,14 @@ struct VectorMetaData
6262
enum Flags {
6363
DELETE_MARK = 0x1, // element is logically deleted, but still exists in the graph
6464
IN_PROCESS = 0x2, // element is being inserted into the graph
65-
PERMANENT_DELETE = 0x3,
65+
PERMANENT_DELETED = 0x4, // element no longer in the graph
6666
};
6767
VectorMetaData(const labelType &label, uint8_t max_level) :
6868
label_(label), max_level_(max_level), flags_(0) {}
69+
70+
VectorMetaData(const VectorMetaData &src) :
71+
label_(src.label_), max_level_(src.max_level_)
72+
{flags_ = char(src.flags_);}
6973

7074
// mark methods
7175
void mark(Flags flag) {

src/VecSim/algorithms/hnsw/graph_data_ram.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct VectorGraphData {
4343
};
4444

4545
char *others;
46-
// since level0_data has an variable size it must be last
46+
// since level0_data has a variable size it must be last
4747
LevelDataOnRam level0_data;
4848
};
4949

@@ -75,16 +75,25 @@ struct VectorGraphData {
7575
const char *
7676
RamGraphData::getVectorByInternalId(idType internal_id) const {
7777
return vectorBlocks_[internal_id / block_size_].getElement(internal_id % block_size_);
78-
}
78+
}
7979

80+
void
81+
RamGraphData::multiGetVectors(const std::vector<idType> &ids,
82+
std::vector<const char *> &results) const {
83+
results.reserve(ids.size());
84+
for (auto id:ids) {
85+
results.push_back(getVectorByInternalId(id));
86+
}
87+
}
88+
8089

8190

8291
idType
8392
RamGraphData::pushVector(const void *vector_data,
8493
int max_level,
8594
const labelType &label,
8695
WriteBatch *wb) {
87-
idToMetaData_.push_back(new VectorMetaData(label,max_level));
96+
idToMetaData_.push_back(VectorMetaData(label,max_level));
8897

8998
if (vectorBlocks_.size() == 0 ||
9099
vectorBlocks_.back().getLength() == block_size_) {
@@ -152,7 +161,7 @@ idType
152161
RamGraphData::getGarbadgeCollectionTarget(idType startingId) const {
153162
for (idType i = startingId; i < idToMetaData_.size(); i++) {
154163
auto const &v = vectorMetaDataById(i);
155-
if (v.ismarked(VectorMetaData::PERMANENT_DELETE)) {
164+
if (v.ismarked(VectorMetaData::PERMANENT_DELETED)) {
156165
return i;
157166
}
158167
}

src/VecSim/algorithms/hnsw/graph_data_ram.h

+13-11
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,22 @@ class RamGraphData : public absGraphData {
132132

133133
const VectorMetaData &
134134
vectorMetaDataById(idType internal_id) const override {
135-
return *idToMetaData_[internal_id];
135+
return idToMetaData_[internal_id];
136136
}
137137

138138
VectorMetaData &
139139
vectorMetaDataById(idType internal_id,
140140
WriteBatch *) override {
141-
return *idToMetaData_[internal_id];
141+
return idToMetaData_[internal_id];
142142
}
143143

144144
// premanently delete the vector and the edges "free" the id
145145
void
146146
deleteVectorAndEdges(idType internalId,
147-
WriteBatch *) override;
147+
WriteBatch *wb) override {
148+
vectorMetaDataById(internalId, wb).mark(
149+
VectorMetaData::PERMANENT_DELETED);
150+
}
148151

149152

150153
// outgoing edges
@@ -176,17 +179,16 @@ class RamGraphData : public absGraphData {
176179
public:
177180
// helper methods needed by hnsw
178181

179-
// get the first id that exists at level level
182+
// get the first id that exists at level "level"
183+
// at or after the statingId
180184
virtual idType
181185
getVectorIdByLevel(short level,
182-
idType startingId = 0) const = 0;
186+
idType startingId = 0) const = 0;
183187

184-
// get a pair of candidates to swap for the gc
185-
// first is a location that is permanent deleted
186-
// second is a location that is valid
187-
// start points is the last pair returned in the prev scan
188+
// get a permanent deleted entry (at or after start point)
189+
// to be used by the GC
188190
virtual idType
189-
getGarbadgeCollectionTarget(idType startPoint = 0) const = 0;
191+
getGarbadgeCollectionTarget(idType startingId = 0) const = 0;
190192

191193
virtual void
192194
shrinkToFit() override;
@@ -219,7 +221,7 @@ class RamGraphData : public absGraphData {
219221
private:
220222
vecsim_stl::vector<DataBlock> vectorBlocks_;
221223
vecsim_stl::vector<DataBlock> graphDataBlocks_;
222-
vecsim_stl::vector<VectorMetaData *> idToMetaData_;
224+
vecsim_stl::vector<VectorMetaData> idToMetaData_;
223225
std::shared_ptr<VecSimAllocator> allocator_;
224226
const size_t block_size_;
225227
const size_t vector_size_bytes_;

0 commit comments

Comments
 (0)