Matching 2 vectors and finding indices #1790
-
In a scenario where I have 2 vectors, let's assume that vector 1 is a 16 character data source and vector 2 is a syntax tokens, and if the elements in vector 1 are found in vector 2, can I get both its index value and the index value of the element in vector 2 that it matches quickly with eve? I'm sorry, this question is very difficult for me to explain :D I get support from Translator unfortunately Basic Example #include <iostream>
#include <vector>
#include <string>
using namespace std;
struct Token {
int index; // Eşleşen karakterin indeksi
char syntax_char; // Eşleşen JSON syntax karakteri
};
int main() {
// JSON string
std::string json_string = "{\"key1\":\"value1\",\"key2\":\"value2\"}";
// JSON özel karakterleri içeren vektör
std::vector<char> syntax_characters = {'{', '}', ':', '[', ']', ',', '"', '\\'};
// Ana tokenizer vector
std::vector<Token> tokenizer_vector;
// String'i analiz et
for (size_t i = 0; i < json_string.size(); i++) {
bool found = false;
// Karakteri syntax karakterleri ile karşılaştır
for (char syntax_char : syntax_characters) {
if (json_string[i] == syntax_char) {
found = true;
break;
}
}
// Karakter syntax karakteri ise token oluştur
if (found) {
Token token;
token.index = i;
token.syntax_char = json_string[i];
// Token'ı ana tokenizer vector'e ekle
tokenizer_vector.push_back(token);
}
}
// Ana tokenizer vector'ü yazdır
std::cout << "Ana Tokenizer Vector:\n";
for (const Token& token : tokenizer_vector) {
std::cout << "Index: " << token.index << ", Karakter: " << token.syntax_char << std::endl;
}
return 0;
}
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
I'm not quite sure what you mean, but I believe you want to try to lex JSON. I looked at the split problem at one point for I suspect the same might be mostly in your case.
The function you asked about is What you want is
but you will probably push into the number of registers. You can do some clever "store one char in this half, one char in that half" and what not too. There is also a trick described here #1052 but I don't know how easy it'd be for you to do.
Didn't have time to finish, will look later. You can also look at folly::split here https://github.com/facebook/folly/blob/786435b3c442cd24837e6cf3b26a0c71d1d1e77f/folly/detail/SplitStringSimdImpl.h#L119 |
Beta Was this translation helpful? Give feedback.
-
Actually - if you can wait for the weekend and ok to update - I can put something in the lirary |
Beta Was this translation helpful? Give feedback.
-
FYI: i created a pr with some functionality you need. Will let you know when it's merged |
Beta Was this translation helpful? Give feedback.
FYI: i created a pr with some functionality you need.
#1797
Will let you know when it's merged