gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: add new approximate time cmp function


From: gnunet
Subject: [gnunet] branch master updated: add new approximate time cmp function
Date: Mon, 21 Mar 2022 03:38:24 +0100

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

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new ec8a825b0 add new approximate time cmp function
ec8a825b0 is described below

commit ec8a825b0e56c692c4879db10c6b25cd26bb42e4
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Mon Mar 21 03:37:29 2022 +0100

    add new approximate time cmp function
---
 src/include/gnunet_time_lib.h | 17 ++++++++++++++++-
 src/util/time.c               | 16 ++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h
index 96413c3cc..55af62b72 100644
--- a/src/include/gnunet_time_lib.h
+++ b/src/include/gnunet_time_lib.h
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2001-2013 GNUnet e.V.
+     Copyright (C) 2001-2022 GNUnet e.V.
 
      GNUnet is free software: you can redistribute it and/or modify it
      under the terms of the GNU Affero General Public License as published
@@ -516,6 +516,21 @@ struct GNUNET_TIME_Relative
 GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future);
 
 
+/**
+ * Test if @a a1 and @a a2 are equal within a margin of
+ * error of @a t.
+ *
+ * @param a1 time to compare
+ * @param a2 time to compare
+ * @param t tolerance to apply
+ * @return true if "|a1-a2|<=t" holds.
+ */
+bool
+GNUNET_TIME_absolute_approx_eq (struct GNUNET_TIME_Absolute a1,
+                                struct GNUNET_TIME_Absolute a2,
+                                struct GNUNET_TIME_Relative t);
+
+
 /**
  * Calculate the estimate time of arrival/completion
  * for an operation.
diff --git a/src/util/time.c b/src/util/time.c
index 68a6937a0..aeec2b3f9 100644
--- a/src/util/time.c
+++ b/src/util/time.c
@@ -58,6 +58,22 @@ GNUNET_TIME_get_offset ()
 }
 
 
+bool
+GNUNET_TIME_absolute_approx_eq (struct GNUNET_TIME_Absolute a1,
+                                struct GNUNET_TIME_Absolute a2,
+                                struct GNUNET_TIME_Relative t)
+{
+  struct GNUNET_TIME_Relative delta;
+
+  delta = GNUNET_TIME_relative_min (
+    GNUNET_TIME_absolute_get_difference (a1, a2),
+    GNUNET_TIME_absolute_get_difference (a2, a1));
+  return GNUNET_TIME_relative_cmp (delta,
+                                   <=,
+                                   t);
+}
+
+
 struct GNUNET_TIME_Timestamp
 GNUNET_TIME_absolute_to_timestamp (struct GNUNET_TIME_Absolute at)
 {

-- 
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]