Failed to lookupRange via deserialized SuRF
iele opened this issue · 3 comments
iele commented
I am trying to wrap SuRF lib with JNI. But I found a bug when testing serialize & deserialize function.
Then I modified the simple_example.cpp and the bug still happend.
Test code:
#include <iostream>
#include <vector>
#include "include/surf.hpp"
using namespace surf;
int main() {
std::vector<std::string> keys = {
"f",
"far",
"fast",
"s",
"top",
"toy",
"trie",
};
// basic surf
SuRF* surf = new SuRF(keys);
char* data = surf->serialize();
surf = SuRF::deSerialize(data);
std::cout << surf->lookupKey("f");
std::cout << surf->lookupKey("far");
std::cout << surf->lookupKey("fast");
std::cout << surf->lookupKey("s");
std::cout << surf->lookupKey("top");
std::cout << surf->lookupRange("a", true, "a", true);
std::cout << surf->lookupRange("fa", true, "fast", true);
std::cout << surf->lookupRange("st", true, "top", true);
std::cout << surf->lookupRange("fat", true, "trie", true);
std::cout << surf->lookupRange("st", true, "z", true);
return 0;
}
huanchenz commented
Thank you for the bug report! I forgot to initialize the iterator during deserialization. The fix has been pushed to the repo :)
iele commented
Thank you for the bug report! I forgot to initialize the iterator during deserialization. The fix has been pushed to the repo :)
Very nice! I am gonna try it!
iele commented
It works, thanks a lot.