From 35d0d31350a0ade1641e2b9d55df2ed697b5c650 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 5 Nov 2014 13:54:38 -0800 Subject: [PATCH] change the NodeHash to a cuckoohash_map with CityHash --- cmake/modules/FindLibcuckoo.cmake | 9 +++++++ libraries/networking/CMakeLists.txt | 2 +- libraries/networking/src/LimitedNodeList.h | 8 ++++--- libraries/networking/src/UUIDCityHasher.cpp | 12 ++++++++++ libraries/networking/src/UUIDCityHasher.h | 26 +++++++++++++++++++++ 5 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 libraries/networking/src/UUIDCityHasher.cpp create mode 100644 libraries/networking/src/UUIDCityHasher.h diff --git a/cmake/modules/FindLibcuckoo.cmake b/cmake/modules/FindLibcuckoo.cmake index dad3d8513e..4e87c650c2 100644 --- a/cmake/modules/FindLibcuckoo.cmake +++ b/cmake/modules/FindLibcuckoo.cmake @@ -21,9 +21,18 @@ hifi_library_search_hints("libcuckoo") find_path(LIBCUCKOO_INCLUDE_DIRS libcuckoo/cuckoohash_map.hh PATH_SUFFIXES include HINTS ${LIBCUCKOO_SEARCH_DIRS}) +find_library(CITYHASH_LIBRARY_RELEASE NAME cityhash PATH_SUFFIXES lib HINTS ${LIBCUCKOO_SEARCH_DIRS}) +find_library(CITYHASH_LIBRARY_DEBUG NAME cityhash PATH_SUFFIXES lib HINTS ${LIBCUCKOO_SEARCH_DIRS}) + +include(SelectLibraryConfigurations) +select_library_configurations(CITYHASH) + +set(LIBCUCKOO_LIBRARIES ${CITYHASH_LIBRARY}) + include(FindPackageHandleStandardArgs) find_package_handle_standard_args( libcuckoo "Could NOT find libcuckoo. Read libraries/networking/externals/libcuckoo/readme.txt" LIBCUCKOO_INCLUDE_DIRS + LIBCUCKOO_LIBRARIES ) \ No newline at end of file diff --git a/libraries/networking/CMakeLists.txt b/libraries/networking/CMakeLists.txt index 021401853f..b650c0942c 100644 --- a/libraries/networking/CMakeLists.txt +++ b/libraries/networking/CMakeLists.txt @@ -25,7 +25,7 @@ endif () include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}") # append OpenSSL to our list of libraries to link -list(APPEND ${TARGET_NAME}_LIBRARIES_TO_LINK "${OPENSSL_LIBRARIES}") +list(APPEND ${TARGET_NAME}_LIBRARIES_TO_LINK "${OPENSSL_LIBRARIES}" "${LIBCUCKOO_LIBRARIES}") # append libcuckoo includes to our list of includes to bubble list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES "${LIBCUCKOO_INCLUDE_DIRS}") diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 9e5610ba4e..100e3a53ea 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -26,12 +26,13 @@ #include #include #include -#include +#include #include #include "DomainHandler.h" #include "Node.h" +#include "UUIDCityHasher.h" const int MAX_PACKET_SIZE = 1500; @@ -51,9 +52,10 @@ class HifiSockAddr; typedef QSet NodeSet; typedef QSharedPointer SharedNodePointer; -typedef QHash NodeHash; Q_DECLARE_METATYPE(SharedNodePointer) +typedef cuckoohash_map NodeHash; + typedef quint8 PingType_t; namespace PingType { const PingType_t Agnostic = 0; @@ -159,7 +161,7 @@ protected: void changeSocketBufferSizes(int numBytes); QUuid _sessionUUID; - NodeHash _nodeHash; + cuckoohash_map _nodeHash; QMutex _nodeHashMutex; QUdpSocket _nodeSocket; QUdpSocket* _dtlsSocket; diff --git a/libraries/networking/src/UUIDCityHasher.cpp b/libraries/networking/src/UUIDCityHasher.cpp new file mode 100644 index 0000000000..731e287fc0 --- /dev/null +++ b/libraries/networking/src/UUIDCityHasher.cpp @@ -0,0 +1,12 @@ +// +// UUIDCityHasher.cpp +// libraries/networking/src +// +// Created by Stephen Birarda on 2014-11-05. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "UUIDCityHasher.h" diff --git a/libraries/networking/src/UUIDCityHasher.h b/libraries/networking/src/UUIDCityHasher.h new file mode 100644 index 0000000000..e27e3bdf1b --- /dev/null +++ b/libraries/networking/src/UUIDCityHasher.h @@ -0,0 +1,26 @@ +// +// UUIDCityHasher.h +// libraries/networking/src +// +// Created by Stephen Birarda on 2014-11-05. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_UUIDCityHasher_h +#define hifi_UUIDCityHasher_h + +#include + +#include "UUID.h" + +class UUIDCityHasher { +public: + size_t operator()(const QUuid& key) const { + return CityHash64(key.toRfc4122().constData(), NUM_BYTES_RFC4122_UUID); + } +}; + +#endif // hifi_UUIDCityHasher_h \ No newline at end of file