| @@ -47,6 +47,8 @@ struct DefaultHashFunctions | |||||
| static int generateHash (const var& key, int upperLimit) noexcept { return generateHash (key.toString(), upperLimit); } | static int generateHash (const var& key, int upperLimit) noexcept { return generateHash (key.toString(), upperLimit); } | ||||
| /** Generates a simple hash from a void ptr. */ | /** Generates a simple hash from a void ptr. */ | ||||
| static int generateHash (const void* key, int upperLimit) noexcept { return generateHash ((pointer_sized_uint) key, upperLimit); } | static int generateHash (const void* key, int upperLimit) noexcept { return generateHash ((pointer_sized_uint) key, upperLimit); } | ||||
| /** Generates a simple hash from a UUID. */ | |||||
| static int generateHash (const Uuid& key, int upperLimit) noexcept { return generateHash (key.hash(), upperLimit); } | |||||
| }; | }; | ||||
| @@ -250,6 +250,7 @@ namespace juce | |||||
| #include "text/juce_LocalisedStrings.h" | #include "text/juce_LocalisedStrings.h" | ||||
| #include "text/juce_Base64.h" | #include "text/juce_Base64.h" | ||||
| #include "misc/juce_Result.h" | #include "misc/juce_Result.h" | ||||
| #include "misc/juce_Uuid.h" | |||||
| #include "containers/juce_Variant.h" | #include "containers/juce_Variant.h" | ||||
| #include "containers/juce_NamedValueSet.h" | #include "containers/juce_NamedValueSet.h" | ||||
| #include "containers/juce_DynamicObject.h" | #include "containers/juce_DynamicObject.h" | ||||
| @@ -280,7 +281,6 @@ namespace juce | |||||
| #include "maths/juce_Expression.h" | #include "maths/juce_Expression.h" | ||||
| #include "maths/juce_Random.h" | #include "maths/juce_Random.h" | ||||
| #include "misc/juce_RuntimePermissions.h" | #include "misc/juce_RuntimePermissions.h" | ||||
| #include "misc/juce_Uuid.h" | |||||
| #include "misc/juce_WindowsRegistry.h" | #include "misc/juce_WindowsRegistry.h" | ||||
| #include "threads/juce_ChildProcess.h" | #include "threads/juce_ChildProcess.h" | ||||
| #include "threads/juce_DynamicLibrary.h" | #include "threads/juce_DynamicLibrary.h" | ||||
| @@ -134,4 +134,24 @@ uint8 Uuid::getClockSeqAndReserved() const noexcept { return uuid[8]; } | |||||
| uint8 Uuid::getClockSeqLow() const noexcept { return uuid[9]; } | uint8 Uuid::getClockSeqLow() const noexcept { return uuid[9]; } | ||||
| uint64 Uuid::getNode() const noexcept { return (((uint64) ByteOrder::bigEndianShort (uuid + 10)) << 32) + ByteOrder::bigEndianInt (uuid + 12); } | uint64 Uuid::getNode() const noexcept { return (((uint64) ByteOrder::bigEndianShort (uuid + 10)) << 32) + ByteOrder::bigEndianInt (uuid + 12); } | ||||
| uint64 Uuid::hash() const noexcept | |||||
| { | |||||
| uint64 result = 0; | |||||
| for (auto n : uuid) | |||||
| result = ((uint64) 101) * result + n; | |||||
| return result; | |||||
| } | |||||
| } // namespace juce | } // namespace juce | ||||
| #if ! DOXYGEN | |||||
| namespace std | |||||
| { | |||||
| template <> struct hash<juce::Uuid> | |||||
| { | |||||
| size_t operator() (const juce::Uuid& u) const noexcept { return (size_t) u.hash(); } | |||||
| }; | |||||
| } | |||||
| #endif | |||||
| @@ -105,6 +105,9 @@ public: | |||||
| /** Returns the node section of the UUID. */ | /** Returns the node section of the UUID. */ | ||||
| uint64 getNode() const noexcept; | uint64 getNode() const noexcept; | ||||
| /** Returns a hash of the UUID. */ | |||||
| uint64 hash() const noexcept; | |||||
| //============================================================================== | //============================================================================== | ||||
| /** Returns a pointer to the internal binary representation of the ID. | /** Returns a pointer to the internal binary representation of the ID. | ||||