summaryrefslogtreecommitdiff
path: root/examples/server/utils.hpp
diff options
context:
space:
mode:
authorsasha0552 <admin@sasha0552.org>2024-06-08 07:50:31 +0000
committerGitHub <noreply@github.com>2024-06-08 10:50:31 +0300
commit7a16ce7db2a74a223f0f3b9cee66d4539c5bce8f (patch)
treef1235f9d8ee68d4c39403bd2bca1078062cab2d7 /examples/server/utils.hpp
parentda799b41891e34aac86ce4e173f9c4c0afd4fab3 (diff)
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
Diffstat (limited to 'examples/server/utils.hpp')
-rw-r--r--examples/server/utils.hpp7
1 files changed, 7 insertions, 0 deletions
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<llama_token> & 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);
}