qlibs / mph

C++20 [Minimal] Static Perfect Hash library
176 stars 9 forks source link

Is there a string size limitation when creating the lookup table? #6

Open FranciscoThiesen opened 2 months ago

FranciscoThiesen commented 2 months ago

Hi, @krzysztof-jusiak

This is a really cool library! When reading the code I was left with 2 questions:

int main() { static_assert(mph::find("make") == true); static_assert(mph::find("model") == true); static_assert(mph::find("year") == true); static_assert(mph::find("unknown") == false); }



Thanks,
Francisco
kris-jusiak commented 2 months ago

Hi @FranciscoThiesen ,

constexpr auto dict = std::array<std::string_view, 3>{
    "make"sv,
    "model"sv,
    "year"sv
};

is equivalent to writing

constexpr auto dict = std::array<std::string_view, 3>{
    pair{"make"sv, 0}
    pair{"model"sv, 1}
    pair{"year"sv, 2}
};
FranciscoThiesen commented 2 months ago

Thanks for the fast response, @krzysztof-jusiak

Is there an example of how can I provide a fallback mechanism to handle with strings with size > 64?

I saw on the other open issue that taking a segment of the string is a possibility, but I can't guarantee the uniqueness of a certain segment of size <= 64 for the strings on my set.