Browse Source

Added some hashing support for the Uuid class

tags/2021-05-28
jules 7 years ago
parent
commit
13a6acfe15
4 changed files with 26 additions and 1 deletions
  1. +2
    -0
      modules/juce_core/containers/juce_HashMap.h
  2. +1
    -1
      modules/juce_core/juce_core.h
  3. +20
    -0
      modules/juce_core/misc/juce_Uuid.cpp
  4. +3
    -0
      modules/juce_core/misc/juce_Uuid.h

+ 2
- 0
modules/juce_core/containers/juce_HashMap.h View File

@@ -47,6 +47,8 @@ struct DefaultHashFunctions
static int generateHash (const var& key, int upperLimit) noexcept { return generateHash (key.toString(), upperLimit); }
/** Generates a simple hash from a void ptr. */
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); }
};


+ 1
- 1
modules/juce_core/juce_core.h View File

@@ -250,6 +250,7 @@ namespace juce
#include "text/juce_LocalisedStrings.h"
#include "text/juce_Base64.h"
#include "misc/juce_Result.h"
#include "misc/juce_Uuid.h"
#include "containers/juce_Variant.h"
#include "containers/juce_NamedValueSet.h"
#include "containers/juce_DynamicObject.h"
@@ -280,7 +281,6 @@ namespace juce
#include "maths/juce_Expression.h"
#include "maths/juce_Random.h"
#include "misc/juce_RuntimePermissions.h"
#include "misc/juce_Uuid.h"
#include "misc/juce_WindowsRegistry.h"
#include "threads/juce_ChildProcess.h"
#include "threads/juce_DynamicLibrary.h"


+ 20
- 0
modules/juce_core/misc/juce_Uuid.cpp View File

@@ -134,4 +134,24 @@ uint8 Uuid::getClockSeqAndReserved() const noexcept { return uuid[8]; }
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::hash() const noexcept
{
uint64 result = 0;
for (auto n : uuid)
result = ((uint64) 101) * result + n;
return result;
}
} // 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

+ 3
- 0
modules/juce_core/misc/juce_Uuid.h View File

@@ -105,6 +105,9 @@ public:
/** Returns the node section of the UUID. */
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.


Loading…
Cancel
Save