From 74fdac7d77a933f6b8ef894d1f2fbd3c9052fdcb Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Fri, 1 Sep 2023 08:50:55 +0200 Subject: Code cleanup --- src/lib/ndpi_hash.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/lib/ndpi_hash.c (limited to 'src/lib/ndpi_hash.c') diff --git a/src/lib/ndpi_hash.c b/src/lib/ndpi_hash.c new file mode 100644 index 000000000..4595368ef --- /dev/null +++ b/src/lib/ndpi_hash.c @@ -0,0 +1,82 @@ +/* + * ndpi_bitmap.c + * + * Copyright (C) 2011-23 - ntop.org and contributors + * + * This file is part of nDPI, an open source deep packet inspection + * library based on the OpenDPI and PACE technology by ipoque GmbH + * + * nDPI is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * nDPI is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with nDPI. If not, see . + * + */ + + +#include "ndpi_config.h" +#include "ndpi_api.h" + +/* ******************************************************************** */ + +/* Based on djb2 hash - http://www.cse.yorku.ca/~oz/hash.html */ +u_int32_t ndpi_quick_hash(unsigned char *str, u_int str_len) { + u_int32_t hash = 5381, i; + + for(i=0; i> 6); + } + + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + + return(hash); +} + +/* ******************************************************************** */ + +/* Same as above but with strings with lenght */ +u_int32_t ndpi_hash_string_len(char *str, u_int len) { + u_int32_t hash, i; + + for(hash = i = 0; i< len; ++i) { + hash += str[i]; + hash += (hash << 10); + hash ^= (hash >> 6); + } + + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + + return(hash); +} + + -- cgit v1.2.3