We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6bbe005 commit 61851c9Copy full SHA for 61851c9
include/pgvector/sparsevec.hpp
@@ -28,6 +28,8 @@ class SparseVector {
28
throw std::invalid_argument{"too many dimensions"};
29
}
30
dimensions_ = static_cast<int>(value.size());
31
+
32
+ // do not reserve capacity for indices/values since likely many zeros
33
for (size_t i = 0; i < value.size(); i++) {
34
float v = value[i];
35
if (v != 0) {
@@ -44,6 +46,7 @@ class SparseVector {
44
46
45
47
dimensions_ = dimensions;
48
49
+ // could probably reserve capacity for indices since not expecting zeros
50
for (const auto& [i, v] : map) {
51
if (i < 0 || i >= dimensions) {
52
throw std::invalid_argument{"sparsevec index out of bounds"};
0 commit comments