summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-06-13 22:19:05 +0000
committerLaurent Bercot <ska@appnovation.com>2023-06-13 22:19:05 +0000
commit193a7be520502f24e995b71768dd89c37b3776eb (patch)
tree29a1d10e1e74220c9d0d463bbcb03aa7c1954583 /src
parent8fac1ec21fc54a050822258d8873b9a87a2bd2fe (diff)
downloadskalibs-193a7be520502f24e995b71768dd89c37b3776eb.tar.xz
Fix iter_func type; add tain_earliest
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r--src/include/skalibs/functypes.h2
-rw-r--r--src/include/skalibs/tai.h6
-rw-r--r--src/libdatastruct/genset_deepfree.c4
-rw-r--r--src/libdatastruct/genset_iter_nocancel.c2
-rw-r--r--src/libdatastruct/genset_iter_withcancel.c1
-rw-r--r--src/libdatastruct/gensetdyn_deepfree.c4
-rw-r--r--src/libdatastruct/gensetdyn_iter_nocancel.c (renamed from src/libdatastruct/gensetdyn_iter.c)4
-rw-r--r--src/libdatastruct/gensetdyn_iter_withcancel.c1
-rw-r--r--src/libstddjb/tain_earliest1.c8
-rw-r--r--src/libstddjb/tain_earliestv.c9
10 files changed, 35 insertions, 6 deletions
diff --git a/src/include/skalibs/functypes.h b/src/include/skalibs/functypes.h
index 958b16f..b015f53 100644
--- a/src/include/skalibs/functypes.h
+++ b/src/include/skalibs/functypes.h
@@ -19,7 +19,7 @@ typedef cmp_func *cmp_func_ref ;
typedef void *dtok_func (uint32_t, void *) ;
typedef dtok_func *dtok_func_ref ;
-typedef int iter_func (char *, void *) ;
+typedef int iter_func (void *, void *) ;
typedef iter_func *iter_func_ref ;
typedef void free_func (void *) ;
diff --git a/src/include/skalibs/tai.h b/src/include/skalibs/tai.h
index 8bf2386..0e38b8c 100644
--- a/src/include/skalibs/tai.h
+++ b/src/include/skalibs/tai.h
@@ -125,6 +125,12 @@ extern int tain_sub (tain *, tain const *, tain const *) ;
extern int tain_less (tain const *, tain const *) gccattr_pure ;
#define tain_future(deadline) tain_less(&STAMP, (deadline))
+extern void tain_earliest1 (tain *, tain const *) ;
+extern void tain_earliestv (tain *, tain const *const *, unsigned int) ;
+#define tain_array(...) ((tain const *const[]){__VA_ARGS__})
+#define tain_earliestn(t, n, ...) tain_earliestv(t, tain_array(__VA_ARGS__), (n))
+#define tain_earliest(t, ...) tain_earliestn(t, sizeof(tain_array(__VA_ARGS__))/sizeof(tain const *), __VA_ARGS__)
+
#define TAIN_PACK 12
extern void tain_pack (char *, tain const *) ;
extern void tain_unpack (char const *, tain *) ;
diff --git a/src/libdatastruct/genset_deepfree.c b/src/libdatastruct/genset_deepfree.c
index c58a5f9..7b4a728 100644
--- a/src/libdatastruct/genset_deepfree.c
+++ b/src/libdatastruct/genset_deepfree.c
@@ -3,10 +3,10 @@
#include <skalibs/functypes.h>
#include <skalibs/genset.h>
-static int freeiter (char *s, void *aux)
+static int freeiter (void *s, void *aux)
{
free_func_ref f = aux ;
- (*f)((void *)s) ;
+ (*f)(s) ;
return 1 ;
}
diff --git a/src/libdatastruct/genset_iter_nocancel.c b/src/libdatastruct/genset_iter_nocancel.c
index 339f4b6..28da323 100644
--- a/src/libdatastruct/genset_iter_nocancel.c
+++ b/src/libdatastruct/genset_iter_nocancel.c
@@ -1,5 +1,7 @@
/* ISC license. */
+#include <stdint.h>
+
#include <skalibs/bitarray.h>
#include <skalibs/genset.h>
diff --git a/src/libdatastruct/genset_iter_withcancel.c b/src/libdatastruct/genset_iter_withcancel.c
index 1220dbc..6b70c68 100644
--- a/src/libdatastruct/genset_iter_withcancel.c
+++ b/src/libdatastruct/genset_iter_withcancel.c
@@ -2,6 +2,7 @@
#include <stdint.h>
#include <errno.h>
+
#include <skalibs/genset.h>
int genset_iter_withcancel (genset *g, iter_func_ref f, iter_func_ref cancelf, void *stuff)
diff --git a/src/libdatastruct/gensetdyn_deepfree.c b/src/libdatastruct/gensetdyn_deepfree.c
index 2b0c87c..623120f 100644
--- a/src/libdatastruct/gensetdyn_deepfree.c
+++ b/src/libdatastruct/gensetdyn_deepfree.c
@@ -3,10 +3,10 @@
#include <skalibs/functypes.h>
#include <skalibs/gensetdyn.h>
-static int freeiter (char *s, void *aux)
+static int freeiter (void *s, void *aux)
{
free_func_ref f = aux ;
- (*f)((void *)s) ;
+ (*f)(s) ;
return 1 ;
}
diff --git a/src/libdatastruct/gensetdyn_iter.c b/src/libdatastruct/gensetdyn_iter_nocancel.c
index 8470adf..a06b6b5 100644
--- a/src/libdatastruct/gensetdyn_iter.c
+++ b/src/libdatastruct/gensetdyn_iter_nocancel.c
@@ -1,6 +1,8 @@
/* ISC license. */
-#include <sys/types.h>
+#include <stddef.h>
+#include <stdint.h>
+
#include <skalibs/bitarray.h>
#include <skalibs/gensetdyn.h>
diff --git a/src/libdatastruct/gensetdyn_iter_withcancel.c b/src/libdatastruct/gensetdyn_iter_withcancel.c
index 0a250ce..b883e58 100644
--- a/src/libdatastruct/gensetdyn_iter_withcancel.c
+++ b/src/libdatastruct/gensetdyn_iter_withcancel.c
@@ -2,6 +2,7 @@
#include <stdint.h>
#include <errno.h>
+
#include <skalibs/gensetdyn.h>
int gensetdyn_iter_withcancel (gensetdyn *g, iter_func_ref f, iter_func_ref cancelf, void *stuff)
diff --git a/src/libstddjb/tain_earliest1.c b/src/libstddjb/tain_earliest1.c
new file mode 100644
index 0000000..af6ba3a
--- /dev/null
+++ b/src/libstddjb/tain_earliest1.c
@@ -0,0 +1,8 @@
+/* ISC license. */
+
+#include <skalibs/tai.h>
+
+void tain_earliest1 (tain *t, tain const *u)
+{
+ if (tain_less(u, t)) *t = *u ;
+}
diff --git a/src/libstddjb/tain_earliestv.c b/src/libstddjb/tain_earliestv.c
new file mode 100644
index 0000000..f4fd36b
--- /dev/null
+++ b/src/libstddjb/tain_earliestv.c
@@ -0,0 +1,9 @@
+/* ISC license. */
+
+#include <skalibs/tai.h>
+
+void tain_earliestv (tain *t, tain const *const *v, unsigned int n)
+{
+ for (unsigned int i = 0 ; i < n ; i++)
+ if (tain_less(v[i], t)) *t = *v[i] ;
+}