Skip to content

Commit

Permalink
format everything
Browse files Browse the repository at this point in the history
  • Loading branch information
1yefuwang1 committed Mar 12, 2024
1 parent a25822c commit eaa2054
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BasedOnStyle: Google
BasedOnStyle : Google
19 changes: 13 additions & 6 deletions src/sqlite_functions.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "sqlite_functions.h"

#include <sqlite3ext.h>

#include <string>
Expand Down Expand Up @@ -160,18 +161,21 @@ void VectorToMsgPack(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
}

if (sqlite3_value_type(argv[0]) != SQLITE_BLOB) {
sqlite3_result_error(ctx, "vector_to_msgpack expects vector of type blob", -1);
sqlite3_result_error(ctx, "vector_to_msgpack expects vector of type blob",
-1);
return;
}

std::string_view vector_blob(
reinterpret_cast<const char *>(sqlite3_value_blob(argv[0])),
sqlite3_value_bytes(argv[0]));

// todo: avoid copying by not constructing a new vector. Because we only need read-only access here.
// todo: avoid copying by not constructing a new vector. Because we only need
// read-only access here.
auto vector = sqlite_vector::Vector::FromBlob(vector_blob);
if (!vector.ok()) {
std::string err = absl::StrFormat("Failed to parse vector due to: %s", vector.status().message());
std::string err = absl::StrFormat("Failed to parse vector due to: %s",
vector.status().message());
sqlite3_result_error(ctx, err.c_str(), err.length());
return;
}
Expand All @@ -190,18 +194,21 @@ void VectorToJson(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
}

if (sqlite3_value_type(argv[0]) != SQLITE_BLOB) {
sqlite3_result_error(ctx, "vector_to_msgpack expects vector of type blob", -1);
sqlite3_result_error(ctx, "vector_to_msgpack expects vector of type blob",
-1);
return;
}

std::string_view vector_blob(
reinterpret_cast<const char *>(sqlite3_value_blob(argv[0])),
sqlite3_value_bytes(argv[0]));

// todo: avoid copying by not constructing a new vector. Because we only need read-only access here.
// todo: avoid copying by not constructing a new vector. Because we only need
// read-only access here.
auto vector = sqlite_vector::Vector::FromBlob(vector_blob);
if (!vector.ok()) {
std::string err = absl::StrFormat("Failed to parse vector due to: %s", vector.status().message());
std::string err = absl::StrFormat("Failed to parse vector due to: %s",
vector.status().message());
sqlite3_result_error(ctx, err.c_str(), err.length());
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/virtual_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ int VirtualTable::Filter(sqlite3_vtab_cursor* pCur, int idxNum,
query_vector.dim(), vtab->dimension());
return SQLITE_ERROR;
} else {
cursor->query_vector = std::move(vtab->space_.normalize ? query_vector.Normalize() : query_vector);
cursor->query_vector = std::move(
vtab->space_.normalize ? query_vector.Normalize() : query_vector);
auto knn = vtab->index_->searchKnnCloserFirst(
cursor->query_vector.data().data(), k);

Expand Down

0 comments on commit eaa2054

Please sign in to comment.