From daf2fa796588f15bb17ac9edd2296f2ffff7f6a3 Mon Sep 17 00:00:00 2001 From: Marius Bancila Date: Wed, 17 Jan 2018 12:31:55 +0200 Subject: [PATCH] name generator ref --- README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 136f14f..8d279a6 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Generators: | `uuid_default_generator` | a function object that generates new UUIDs, using an operating system method to create one (`CoCreateGuid` on Windows, `uuid_generate` on Linux, `CFUUIDCreate` on Mac) | | ` basic_uuid_random_generator` | a function object that generates version 4 UUIDs using a pseudo-random number generator engine. | | `uuid_random_generator` | a basic_uuid_random_generator using the Marsenne Twister engine, i.e. `basic_uuid_random_generator` | +| `uuid_name_generator` | a function object that generates version 5, name-based UUIDs using SHA1 hashing. | Utilities: @@ -80,6 +81,15 @@ assert(guid.size() == 16); assert(guid.version() == uuids::uuid_version::random_number_based); assert(guid.variant() == uuids::uuid_variant::rfc); ``` +* Creating a new UUID with the name generator +``` +uuids::uuid_name_generator gen; +uuid const guid = gen(); +assert(!guid.nil()); +assert(guid.size() == 16); +assert(guid.version() == uuids::uuid_version::name_based_sha1); +assert(guid.variant() == uuids::uuid_variant::rfc); +``` * Create a UUID from a string ``` using namespace std::string_literals; @@ -192,11 +202,6 @@ auto h2 = std::hash{}; assert(h1(str) == h2(guid)); ``` -## Limitations -The library can only create new uuids using the underlaying operating system resources. - -An alternative to this library could be the [boost::uuid](http://www.boost.org/doc/libs/1_65_1/libs/uuid/) library. This has a similar model, but supports creating all variant of uuids, including md5 and sha1 name based, time based, and random number based values. - ## Support The library is supported on all major operating systems: Windows, Linux and Mac OS. @@ -207,3 +212,6 @@ A testing project is available in the sources. To build and execute the tests do * Run the command `cmake ..` from the `build` directory; if you do not have CMake you must install it first. * Build the project created in the previous step * Run the executable. + +## Credits +The SHA1 implementation is based on the [TinySHA1](https://github.com/mohaps/TinySHA1) library.