gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r8887 - in gnunet/src: include util


From: gnunet
Subject: [GNUnet-SVN] r8887 - in gnunet/src: include util
Date: Sat, 29 Aug 2009 14:26:36 -0600

Author: grothoff
Date: 2009-08-29 14:26:36 -0600 (Sat, 29 Aug 2009)
New Revision: 8887

Modified:
   gnunet/src/include/gnunet_time_lib.h
   gnunet/src/util/time.c
Log:
eta

Modified: gnunet/src/include/gnunet_time_lib.h
===================================================================
--- gnunet/src/include/gnunet_time_lib.h        2009-08-29 20:03:47 UTC (rev 
8886)
+++ gnunet/src/include/gnunet_time_lib.h        2009-08-29 20:26:36 UTC (rev 
8887)
@@ -163,7 +163,23 @@
                                                                 
GNUNET_TIME_Absolute
                                                                 future);
 
+
 /**
+ * Calculate the estimate time of arrival/completion 
+ * for an operation.
+ *
+ * @param start when did the operation start?
+ * @param finished how much has been done?
+ * @param total how much must be done overall (same unit as for "finished")
+ * @return remaining duration for the operation,
+ *        assuming it continues at the same speed
+ */
+struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta (struct 
GNUNET_TIME_Absolute start,
+                                                      uint64_t finished,
+                                                      uint64_t total);
+
+
+/**
  * Compute the time difference between the given start and end times.
  * Use this function instead of actual subtraction to ensure that
  * "FOREVER" and overflows are handeled correctly.

Modified: gnunet/src/util/time.c
===================================================================
--- gnunet/src/util/time.c      2009-08-29 20:03:47 UTC (rev 8886)
+++ gnunet/src/util/time.c      2009-08-29 20:26:36 UTC (rev 8887)
@@ -238,7 +238,38 @@
   return ret;
 }
 
+
 /**
+ * Calculate the estimate time of arrival/completion 
+ * for an operation.
+ *
+ * @param start when did the operation start?
+ * @param finished how much has been done?
+ * @param total how much must be done overall (same unit as for "finished")
+ * @return remaining duration for the operation,
+ *        assuming it continues at the same speed
+ */
+struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta (struct 
GNUNET_TIME_Absolute start,
+                                                      uint64_t finished,
+                                                      uint64_t total)
+{
+  struct GNUNET_TIME_Relative dur;
+  double exp;
+  struct GNUNET_TIME_Relative ret;
+
+  GNUNET_break (finished > total);
+  if (finished >= total)
+    return GNUNET_TIME_UNIT_ZERO;
+  if (finished == 0)
+    return GNUNET_TIME_UNIT_FOREVER;
+  dur = GNUNET_TIME_absolute_get_duration (start);
+  exp = ((double)dur.value) * ((double) total) / ((double)finished);
+  ret.value = ((uint64_t) exp) - dur.value;
+  return ret;
+}
+
+
+/**
  * Add relative times together.
  *
  * @return FOREVER if either argument is FOREVER or on overflow; a1+a2 
otherwise





reply via email to

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