18#ifndef TRINITY_FUZZYFIND_H
19#define TRINITY_FUZZYFIND_H
29 template <
typename Container,
typename NeedleContainer,
typename ContainsOperator =
bool(std::
string const&, std::
string const&),
typename T =
void>
30 auto FuzzyFindIn(Container
const& container, NeedleContainer
const& needles, ContainsOperator
const& contains =
StringContainsStringI,
int(*bonus)(
decltype((*std::begin(std::declval<Container>())))) =
nullptr)
32 using IteratorResult =
decltype((*std::begin(container)));
33 using MappedType = std::conditional_t<std::is_reference_v<IteratorResult>, std::reference_wrapper<std::remove_reference_t<IteratorResult>>, IteratorResult>;
34 std::multimap<size_t, MappedType, std::greater<size_t>> results;
36 for (
auto outerIt = std::begin(container), outerEnd = std::end(container); outerIt != outerEnd; ++outerIt)
39 for (
auto innerIt = std::begin(needles), innerEnd = std::end(needles); innerIt != innerEnd; ++innerIt)
40 if (contains(*outerIt, *innerIt))
47 count += bonus(*outerIt);
49 results.emplace(count, *outerIt);
bool StringContainsStringI(std::string_view haystack, std::string_view needle)
auto FuzzyFindIn(Container const &container, NeedleContainer const &needles, ContainsOperator const &contains=StringContainsStringI, int(*bonus)(decltype((*std::begin(std::declval< Container >()))))=nullptr)