From 7a16ce7db2a74a223f0f3b9cee66d4539c5bce8f Mon Sep 17 00:00:00 2001 From: sasha0552 Date: Sat, 8 Jun 2024 07:50:31 +0000 Subject: server : smart slot selection using Longest Common Prefix (#7728) * server : Smart selection of available slot using Longest Common Substring * add usage * remove trailing whitespaces * Use Longest Common Prefix (LCP) instead of LCS * Rename argument --- examples/server/utils.hpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'examples/server/utils.hpp') diff --git a/examples/server/utils.hpp b/examples/server/utils.hpp index b7bfb41d..63fde9c9 100644 --- a/examples/server/utils.hpp +++ b/examples/server/utils.hpp @@ -253,6 +253,13 @@ static size_t common_part(const std::vector & a, const std::vector< return i; } +static size_t common_part(const std::string & a, const std::string & b) { + size_t i; + for (i = 0; i < a.size() && i < b.size() && a[i] == b[i]; i++) {} + + return i; +} + static bool ends_with(const std::string & str, const std::string & suffix) { return str.size() >= suffix.size() && 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix); } -- cgit v1.2.3