Skip to content

Commit 8877640

Browse files
committed
Clean up comments, remove an unneeded macro
1 parent 53fc9a4 commit 8877640

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
@@ -1146,9 +1146,9 @@ class HierarchicalNSW : public AlgorithmInterface<dist_t> {
11461146
filteredTopCandidates.pop();
11471147
}
11481148

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

1270-
auto newElement = mutuallyConnectNewElement(data_point, cur_c, top_candidates, level, false);
1271-
HNSWLIB_RETURN_IF_VALUE_NOT_OK(newElement);
1272-
currObj = HNSWLIB_EXTRACT_VALUE(newElement);
1270+
HNSWLIB_ASSIGN_OR_RETURN(
1271+
currObj,
1272+
mutuallyConnectNewElement(data_point, cur_c, top_candidates, level, false));
12731273
}
12741274
} else {
12751275
// 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)