Skip to content

Commit

Permalink
use std::string_view instead and deal with cross compilation later
Browse files Browse the repository at this point in the history
  • Loading branch information
1yefuwang1 committed Jun 16, 2024
1 parent 5dcf6a6 commit 9499f6e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/index_options.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#include "index_options.h"

#include <string_view>

#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "re2/re2.h"

namespace vectorlite {

absl::StatusOr<IndexOptions> IndexOptions::FromString(
absl::string_view index_options) {
std::string_view index_options) {
static const re2::RE2 hnsw_reg("^hnsw\\((.*)\\)$");
std::string key_value;
if (!re2::RE2::FullMatch(index_options, hnsw_reg, &key_value)) {
Expand All @@ -25,7 +26,7 @@ absl::StatusOr<IndexOptions> IndexOptions::FromString(
std::string key;
std::string value;

absl::string_view input(key_value);
std::string_view input(key_value);
while (re2::RE2::FindAndConsume(&input, kv_reg, &key, &value)) {
if (key == "max_elements") {
if (!absl::SimpleAtoi<size_t>(value, &options.max_elements)) {
Expand Down
5 changes: 3 additions & 2 deletions src/index_options.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#include <string_view>

#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"

namespace vectorlite {

Expand All @@ -21,7 +22,7 @@ struct IndexOptions {
// All parameters except max_elemnts are optional, default values are used
// if not specified.
static absl::StatusOr<IndexOptions> FromString(
absl::string_view index_options);
std::string_view index_options);
};

} // namespace vectorlite
2 changes: 1 addition & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace vectorlite {

bool IsValidColumnName(absl::string_view name) {
bool IsValidColumnName(std::string_view name) {
if (name.empty() || sqlite3_keyword_check(name.data(), name.size()) != 0) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include <optional>
#include <string_view>
#include <utility>

#include "absl/strings/string_view.h"
#include "hnswlib/hnswlib.h"

namespace vectorlite {
Expand All @@ -16,7 +16,7 @@ namespace vectorlite {
// - It must not be a reserved keyword.
// The input is of string type because built-in regex doesn't work with
// string_view
bool IsValidColumnName(absl::string_view name);
bool IsValidColumnName(std::string_view name);

// Returns which SIMD instruction set is used at build time.
// e.g. SSE, AVX, AVX512
Expand Down
2 changes: 1 addition & 1 deletion src/vector_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ absl::StatusOr<NamedVectorSpace> CreateNamedVectorSpace(
}

absl::StatusOr<NamedVectorSpace> NamedVectorSpace::FromString(
absl::string_view space_str) {
std::string_view space_str) {
static const re2::RE2 reg("([\\w]+)\\((\\d+),\\s*\"([\\w]+)\"\\)");

std::string vector_name;
Expand Down
4 changes: 2 additions & 2 deletions src/vector_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <memory>
#include <optional>
#include <string_view>

#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "hnswlib/hnswlib.h"

namespace vectorlite {
Expand Down Expand Up @@ -38,7 +38,7 @@ struct NamedVectorSpace : public VectorSpace {
// "l2"), "hnsw(max_elements=1000)") The `vector(384, "l2")` is the vector
// space string. Supported space type are "l2", "cos", "ip"
static absl::StatusOr<NamedVectorSpace> FromString(
absl::string_view space_str);
std::string_view space_str);
};

absl::StatusOr<NamedVectorSpace> CreateNamedVectorSpace(
Expand Down
2 changes: 1 addition & 1 deletion src/virtual_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int VirtualTable::Create(sqlite3* db, void* pAux, int argc,
return SQLITE_ERROR;
}

absl::string_view index_options_str = argv[1 + kModuleParamOffset];
std::string_view index_options_str = argv[1 + kModuleParamOffset];
DLOG(INFO) << "index_options_str: " << index_options_str;
auto index_options = IndexOptions::FromString(index_options_str);
if (!index_options.ok()) {
Expand Down

0 comments on commit 9499f6e

Please sign in to comment.