Skip to content

Commit 168c1c4

Browse files
committed
Clean up comments, remove an unneeded macro
1 parent 6ec6289 commit 168c1c4

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

hnswlib/hnswalg.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,9 +1147,9 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
11471147
filteredTopCandidates.pop();
11481148
}
11491149

1150-
auto newElement = mutuallyConnectNewElement(dataPoint, dataPointInternalId, filteredTopCandidates, level, true);
1151-
HNSWLIB_RETURN_IF_VALUE_NOT_OK(newElement);
1152-
currObj = HNSWLIB_EXTRACT_VALUE(newElement);
1150+
HNSWLIB_ASSIGN_OR_RETURN(
1151+
auto curObj,
1152+
mutuallyConnectNewElement(dataPoint, dataPointInternalId, filteredTopCandidates, level, true));
11531153
}
11541154
}
11551155
HNSWLIB_RETURN_OK_STATUS;
@@ -1268,9 +1268,9 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
12681268
top_candidates.pop();
12691269
}
12701270

1271-
auto newElement = mutuallyConnectNewElement(data_point, cur_c, top_candidates, level, false);
1272-
HNSWLIB_RETURN_IF_VALUE_NOT_OK(newElement);
1273-
currObj = HNSWLIB_EXTRACT_VALUE(newElement);
1271+
HNSWLIB_ASSIGN_OR_RETURN(
1272+
currObj,
1273+
mutuallyConnectNewElement(data_point, cur_c, top_candidates, level, false));
12741274
}
12751275
} else {
12761276
// Do nothing for the first element

hnswlib/hnswlib.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,29 +131,18 @@ static bool AVX512Capable() {
131131
namespace hnswlib {
132132

133133
// hnswlib can be compiled in two modes: with and without exceptions.
134-
// In the mode without exceptions, we use Abseil-style Status and StatusOr
135-
// return values but without actually introducing an Abseil dependency.
136-
// By default, we assume the legacy mode of using exceptions.
137-
138-
// The following macros are defined for functions that can throw exceptions
139-
// or return statuses:
140-
//
141-
// HNSWLIB_THROW_ERROR(message) -- throw an exception or return a sttatus
142-
// with the given message
143-
// HNSWLIB_STATUS_TYPE -- return type for a function without a return value
144-
// HNSWLIB_STATUS_OR_TYPE(t) -- return type for a function with a return value
145-
// HNSWLIB_RETURN_OK_STATUS -- return an OK status or simply return.
134+
// In the mode without exceptions, we use Status / StatusOr from Abseil.
135+
// By default, we assume the mode of using exceptions for compatibility.
146136

147137
#if !HNSWLIB_USE_ABSEIL
148138

149-
#define HNSWLIB_THROW_ERROR(message) \
150-
throw std::runtime_error(message);
151139
#define HNSWLIB_STATUS_TYPE void
152140
#define HNSWLIB_STATUS_OR_TYPE(t) t
141+
#define HNSWLIB_THROW_ERROR(message) throw std::runtime_error(message);
153142
#define HNSWLIB_RETURN_OK_STATUS return
143+
#define HNSWLIB_RETURN_IF_VALUE_NOT_OK(status_or_value) status_or_value
154144
#define HNSWLIB_EXTRACT_VALUE(status_or_value) (status_or_value)
155145
#define HNSWLIB_ASSIGN_OR_RETURN(lhs, expression) lhs = (expression)
156-
#define HNSWLIB_RETURN_IF_VALUE_NOT_OK(status_or_value) status_or_value
157146
#define HNSWLIB_ASSIGN_VALUE_OR_THROW_IN_TEST(identifier, expression) \
158147
auto identifier = (expression)
159148

0 commit comments

Comments
 (0)