gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet-scheme] 04/09: Define arbitraries for generating hashcodes.


From: gnunet
Subject: [gnunet-scheme] 04/09: Define arbitraries for generating hashcodes.
Date: Sat, 03 Dec 2022 14:14:34 +0100

This is an automated email from the git hooks/post-receive script.

maxime-devos pushed a commit to branch master
in repository gnunet-scheme.

commit 2eb02d84d6ea523e7a780f6788d8a35c60931bcf
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Sat Dec 3 13:05:50 2022 +0100

    Define arbitraries for generating hashcodes.
    
    * gnu/gnunet/hashcode/quickcheck.scm: New module.
    * Makefile.am (modules): Register new module.
    * doc/scheme-gnunet.tm (Hashcodes): Document.
---
 Makefile.am                        |  1 +
 doc/scheme-gnunet.tm               | 10 ++++++++++
 gnu/gnunet/hashcode/quickcheck.scm | 39 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index 87f5e64..810c4e4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -51,6 +51,7 @@ modules = \
   \
   gnu/gnunet/data-string.scm \
   gnu/gnunet/hashcode.scm \
+  gnu/gnunet/hashcode/quickcheck.scm \
   \
   gnu/gnunet/mq/envelope.scm \
   gnu/gnunet/mq/error-reporting.scm \
diff --git a/doc/scheme-gnunet.tm b/doc/scheme-gnunet.tm
index 5ef0851..9816852 100644
--- a/doc/scheme-gnunet.tm
+++ b/doc/scheme-gnunet.tm
@@ -399,6 +399,16 @@
   <var|slice> is not mutated. However, this imposes a small cost, as
   <var|slice> will then be copied behind the scenes.>
 
+  The module <scm|(gnu gnunet hashcode quickcheck)><index|(gnu gnunet
+  hashcode quickcheck)> defines a few <em|arbitraries> for use with
+  Guile-Quickcheck:
+
+  <\explain>
+    <scm|$hashcode:512><index|$hashcode:512>,
+    <scm|$hashcode:256><index|$hashcode:256>
+  </explain|Arbitraries generating hashcode:512 and hashcode:256
+  respectively.>
+
   <include|bytevector-slices.tm>
 
   <appendix|GNU Free Documentation License>
diff --git a/gnu/gnunet/hashcode/quickcheck.scm 
b/gnu/gnunet/hashcode/quickcheck.scm
new file mode 100644
index 0000000..72f9ac0
--- /dev/null
+++ b/gnu/gnunet/hashcode/quickcheck.scm
@@ -0,0 +1,39 @@
+;#!r6rs
+;;   This file is part of scheme-GNUnet, a partial Scheme port of GNUnet.
+;;   Copyright © 2022 GNUnet e.V.
+;;
+;;   scheme-GNUnet is free software: you can redistribute it and/or modify it
+;;   under the terms of the GNU Affero General Public License as published
+;;   by the Free Software Foundation, either version 3 of the License,
+;;   or (at your option) any later version.
+;;
+;;   scheme-GNUnet is distributed in the hope that it will be useful, but
+;;   WITHOUT ANY WARRANTY; without even the implied warranty of
+;;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;;   Affero General Public License for more details.
+;;
+;;   You should have received a copy of the GNU Affero General Public License
+;;   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+;;
+;;   SPDX-License-Identifier: AGPL-3.0-or-later
+(define-library (gnu gnunet hashcode quickcheck)
+  (import (only (rnrs base) begin define)
+         (only (quickcheck arbitrary)
+               arbitrary $record)
+         (only (gnu gnunet hashcode)
+               make-hashcode:512/share make-hashcode:256/share
+               hashcode:512->slice hashcode:256->slice)
+         (only (gnu gnunet utils bv-slice-quickcheck)
+               $sized-bytevector-slice/read-only))
+  (export $hashcode:512 $hashcode:256)
+  (begin
+    ;; TODO: give '000...' more weight
+    ;; (is it used as a special value somewhere?).
+    ;;
+    ;; The unshared variant would work too, but is less efficient.
+    (define $hashcode:512
+      ($record make-hashcode:512/share
+              (hashcode:512->slice $sized-bytevector-slice/read-only)))
+    (define $hashcode:256
+      ($record make-hashcode:256/share
+              (hashcode:256->slice $sized-bytevector-slice/read-only)))))

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]