Skip to content

Commit 9684f4c

Browse files
revise hashing function
1 parent 1d516d3 commit 9684f4c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

common/ngram-cache.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ struct llama_ngram {
3939

4040
struct llama_ngram_hash_function {
4141
size_t operator()(const llama_ngram & ngram) const {
42-
size_t hash = 0;
43-
for (int i = 0; i < LLAMA_NGRAM_MAX; ++i) {
44-
hash ^= std::hash<llama_token>{}(ngram.tokens[i]);
42+
size_t hash = ngram.tokens[0];
43+
44+
for (int i = 1; i < LLAMA_NGRAM_MAX; ++i) {
45+
hash <<= 15;
46+
hash ^= ngram.tokens[i];
4547
}
48+
4649
return hash;
4750
}
4851
};

0 commit comments

Comments
 (0)