Skip to content

Commit 82c0fd1

Browse files
author
Dmitry Yashunin
committed
Adding checks and refactoring
1 parent 4c28248 commit 82c0fd1

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

hnswlib/hnswalg.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace hnswlib {
2828
link_list_locks_(max_elements), link_list_update_locks_(max_update_element_locks), element_levels_(max_elements) {
2929
max_elements_ = max_elements;
3030

31-
num_deleted_ = false;
31+
num_deleted_ = 0;
3232
data_size_ = s->get_data_size();
3333
fstdistfunc_ = s->get_dist_func();
3434
dist_func_param_ = s->get_dist_func_param();
@@ -768,12 +768,17 @@ namespace hnswlib {
768768
* @param internalId
769769
*/
770770
void markDeletedInternal(tableint internalId) {
771+
assert(internalId < max_elements_);
771772
if (!isMarkedDeleted(internalId))
772773
{
773774
unsigned char *ll_cur = ((unsigned char *)get_linklist0(internalId))+2;
774775
*ll_cur |= DELETE_MARK;
775776
num_deleted_ += 1;
776777
}
778+
else
779+
{
780+
throw std::runtime_error("Element is deleted");
781+
}
777782
}
778783

779784
/**
@@ -795,12 +800,17 @@ namespace hnswlib {
795800
* @param internalId
796801
*/
797802
void unmarkDeletedInternal(tableint internalId) {
803+
assert(internalId < max_elements_);
798804
if (isMarkedDeleted(internalId))
799805
{
800806
unsigned char *ll_cur = ((unsigned char *)get_linklist0(internalId))+2;
801807
*ll_cur &= ~DELETE_MARK;
802808
num_deleted_ -= 1;
803809
}
810+
else
811+
{
812+
throw std::runtime_error("Element is not deleted");
813+
}
804814
}
805815

806816
/**

python_bindings/bindings.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ inline void ParallelFor(size_t start, size_t end, size_t numThreads, Function fn
7474

7575
}
7676

77-
inline void assert_true(bool expr, const std::string & msg) {
78-
if (expr == false)
79-
throw std::runtime_error("Unpickle Error: "+msg);
80-
return;
81-
}
8277

78+
inline void assert_true(bool expr, const std::string & msg) {
79+
if (expr == false)
80+
throw std::runtime_error("Unpickle Error: "+msg);
81+
return;
82+
}
8383

8484

8585
template<typename dist_t, typename data_t=float>

0 commit comments

Comments
 (0)