From e8a9af22667d2e6b77cb4da266ce7b69edb77e72 Mon Sep 17 00:00:00 2001 From: Quint Daenen Date: Thu, 16 Dec 2021 15:43:14 +0100 Subject: [PATCH] Add FUNDING file. --- .github/FUNDING.yml | 1 + README.md | 4 ++-- src/UUID.mo | 27 ++++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..c326dcd --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +custom: ["https://icdevs.org/donations.html"] diff --git a/README.md b/README.md index 2a5556d..e26d173 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,6 @@ UUID.toText(await g.new()); // F253F1F0-2885-169F-169F-2885F253F1F0 ``` -## ICDevs.org +--- -This library was incentivized by https://ICDevs.org. You can view more about the bounty at https://forum.dfinity.org/t/icdevs-org-bounty-4-uuid-motoko-library/8648 and https://icdevs.org/bounties/2021/11/17/UUID-motoko-library.html. The bounty was funded by The Dragginz Team and the award was graciously donated by di-wu to the treasury of ICDevs.org so that we could pursue more bounties. If you use this library and gain value from it, please consider a donation to ICDevs at https://icdevs.org/donations.html. +This library was incentivized by [ICDevs](https://ICDevs.org). You can view more about the bounty on the [forum](https://forum.dfinity.org/t/icdevs-org-bounty-4-uuid-motoko-library/8648) or [website](https://icdevs.org/bounties/2021/11/17/UUID-motoko-library.html). The bounty was funded by The Dragginz Team and the award was graciously donated by [di-wu](https://github.com/di-wu) to the treasury of ICDevs.org so that we could pursue more bounties. If you use this library and gain value from it, please consider a [donation](https://icdevs.org/donations.html) to ICDevs. diff --git a/src/UUID.mo b/src/UUID.mo index 74effbc..e921a95 100644 --- a/src/UUID.mo +++ b/src/UUID.mo @@ -1,5 +1,12 @@ import Hex "mo:encoding/Hex"; import List "mo:base/List"; +import Bool "mo:base/Bool"; +import Array "mo:base/Array"; +import Nat8 "mo:base/Nat8"; +import Nat32 "mo:base/Nat32"; +import Hash "mo:base/Hash"; +import Text "mo:base/Text"; +import Buffer "mo:base/Buffer"; module { // A UUID is a 128 bit (16 byte) Universal Unique IDentifier as defined in RFC 4122. @@ -18,4 +25,22 @@ module { let (p3, xs3) = List.split(2, xs2); t # Hex.encode(List.toArray(p3)) # "-" # Hex.encode(List.toArray(xs3)); }; -}; + + public func equal(uuid : UUID, uuid2 : UUID): Bool{ + return Array.equal(uuid, uuid2, Nat8.equal); + }; + + public func hash(uuid : UUID): Hash.Hash{ + var buffer = Buffer.Buffer(16); //128 bit - 16 byte + for(n8 in uuid.vals()){ + var n = Nat8.toNat(n8); + var n32 = Nat32.fromNat(n); + buffer.add(n32); + }; + return Hash.hashNat8(buffer.toArray()); + }; + + // public func hash(uuid : UUID): Hash.Hash{ + // return Text.hash(toText(uuid)); + // }; +}; \ No newline at end of file