LRU cache: move to 64 bits long keys (#2346)

Tradeoff between key comparison efficiency (i.e. no `memcmp`) and key
length.
At least in the ipv4 cases, we have no more different entries with the
same key.
This commit is contained in:
Ivan Nardi
2024-03-15 10:12:51 +01:00
committed by GitHub
parent 97fae6e00a
commit 231748bb0e
10 changed files with 88 additions and 84 deletions
+4 -4
View File
@@ -28,14 +28,14 @@
/* ************************************************************************** */
u_int32_t mining_make_lru_cache_key(struct ndpi_flow_struct *flow) {
u_int32_t key;
u_int64_t mining_make_lru_cache_key(struct ndpi_flow_struct *flow) {
u_int64_t key;
/* network byte order */
if(flow->is_ipv6)
key = ndpi_quick_hash(flow->c_address.v6, 16) + ndpi_quick_hash(flow->s_address.v6, 16);
key = (ndpi_quick_hash64((const char *)flow->c_address.v6, 16) << 32) | (ndpi_quick_hash64((const char *)flow->s_address.v6, 16) & 0xFFFFFFFF);
else
key = flow->c_address.v4 + flow->s_address.v4;
key = ((u_int64_t)flow->c_address.v4 << 32) | flow->s_address.v4;
return key;
}