adds distance functions for integers as utils

Thu, 03 May 2018 10:09:49 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 03 May 2018 10:09:49 +0200
changeset 286
85f55abea563
parent 285
7be3ae7ffb58
child 287
98da78a1e69a

adds distance functions for integers as utils

src/ucx/utils.h file | annotate | diff | comparison | revisions
src/utils.c file | annotate | diff | comparison | revisions
--- a/src/ucx/utils.h	Thu May 03 09:49:38 2018 +0200
+++ b/src/ucx/utils.h	Thu May 03 10:09:49 2018 +0200
@@ -175,6 +175,25 @@
  */
 int ucx_longintcmp(const void *i1, const void *i2, void *data);
 
+
+/**
+ * Distance function for integers of type int.
+ * @param i1 pointer to integer one
+ * @param i2 pointer to integer two
+ * @param data omitted
+ * @return i1 minus i2
+ */
+intmax_t ucx_intdist(const void *i1, const void *i2, void *data);
+
+/**
+ * Distance function for integers of type long int.
+ * @param i1 pointer to long integer one
+ * @param i2 pointer to long integer two
+ * @param data omitted
+ * @return i1 minus i2
+ */
+intmax_t ucx_longintdist(const void *i1, const void *i2, void *data);
+
 /**
  * Compares two real numbers of type float.
  * @param f1 pointer to float one
--- a/src/utils.c	Thu May 03 09:49:38 2018 +0200
+++ b/src/utils.c	Thu May 03 10:09:49 2018 +0200
@@ -116,6 +116,18 @@
    }
 }
 
+intmax_t ucx_intdist(const void *i1, const void *i2, void *data) {
+   intmax_t a = *((const int*) i1);
+   intmax_t b = *((const int*) i2);
+   return a - b;
+}
+
+intmax_t ucx_longintdist(const void *i1, const void *i2, void *data) {
+   intmax_t a = *((const long int*) i1);
+   intmax_t b = *((const long int*) i2);
+   return a - b;
+}
+
 int ucx_floatcmp(const void *f1, const void *f2, void *epsilon) {
    float a = *((const float*) f1);
    float b = *((const float*) f2);

mercurial