MCPcopy Create free account
hub / github.com/asg017/sqlite-vss / parse_constructor

Function parse_constructor

src/sqlite-vss.cpp:709–783  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

707}
708
709unique_ptr<vector<VssIndexColumn>> parse_constructor(int argc,
710 const char *const *argv) {
711
712 auto columns = unique_ptr<vector<VssIndexColumn>>(new vector<VssIndexColumn>());
713
714 for (int i = 3; i < argc; i++) {
715
716 string arg = string(argv[i]);
717
718 size_t lparen = arg.find("(");
719 size_t rparen = arg.find(")");
720
721 if (lparen == string::npos || rparen == string::npos ||
722 lparen >= rparen) {
723 return nullptr;
724 }
725
726 string name = arg.substr(0, lparen);
727 string sDimensions = arg.substr(lparen + 1, rparen - lparen - 1);
728
729 sqlite3_int64 dimensions = atoi(sDimensions.c_str());
730
731 size_t factoryStart, factoryStringStartFrom;
732 string factory;
733
734 if ((factoryStart = arg.find("factory", rparen)) != string::npos &&
735 (factoryStringStartFrom = arg.find("=", factoryStart)) !=
736 string::npos) {
737
738 size_t lquote = arg.find("\"", factoryStringStartFrom);
739 size_t rquote = arg.find_last_of("\"");
740
741 if (lquote == string::npos || rquote == string::npos ||
742 lquote >= rquote) {
743 return nullptr;
744 }
745 factory = arg.substr(lquote + 1, rquote - lquote - 1);
746
747 } else {
748 factory = string("Flat,IDMap2");
749 }
750
751 faiss::MetricType metric_type;
752 size_t metricStart, metricStringStartFrom;
753
754 if ((metricStart = arg.find("metric_type", rparen)) != string::npos &&
755 (metricStringStartFrom = arg.find("=", metricStart)) != string::npos) {
756
757 size_t lquote = arg.find_first_not_of(" ", metricStringStartFrom + 1);
758 size_t rquote = arg.find(",", lquote);
759
760 if(lquote == -1) {
761 throw std::invalid_argument( "invalid metric_type value" );
762 }
763
764 if (rquote == string::npos) {
765 rquote = arg.size();
766 }

Callers 1

initFunction · 0.85

Calls 1

parse_metric_typeFunction · 0.85

Tested by

no test coverage detected