summaryrefslogtreecommitdiff
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
parent8fac1ec21fc54a050822258d8873b9a87a2bd2fe (diff)
downloadskalibs-193a7be520502f24e995b71768dd89c37b3776eb.tar.xz
Fix iter_func type; add tain_earliest
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r--package/deps.mak4
-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
11 files changed, 38 insertions, 7 deletions
diff --git a/package/deps.mak b/package/deps.mak
index 4a787d6..fc084ea 100644
--- a/package/deps.mak
+++ b/package/deps.mak
@@ -107,7 +107,7 @@ src/libdatastruct/gensetdyn_deepfree.o src/libdatastruct/gensetdyn_deepfree.lo:
src/libdatastruct/gensetdyn_delete.o src/libdatastruct/gensetdyn_delete.lo: src/libdatastruct/gensetdyn_delete.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h
src/libdatastruct/gensetdyn_free.o src/libdatastruct/gensetdyn_free.lo: src/libdatastruct/gensetdyn_free.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/include/skalibs/stralloc.h
src/libdatastruct/gensetdyn_init.o src/libdatastruct/gensetdyn_init.lo: src/libdatastruct/gensetdyn_init.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/include/skalibs/stralloc.h
-src/libdatastruct/gensetdyn_iter.o src/libdatastruct/gensetdyn_iter.lo: src/libdatastruct/gensetdyn_iter.c src/include/skalibs/bitarray.h src/include/skalibs/gensetdyn.h
+src/libdatastruct/gensetdyn_iter_nocancel.o src/libdatastruct/gensetdyn_iter_nocancel.lo: src/libdatastruct/gensetdyn_iter_nocancel.c src/include/skalibs/bitarray.h src/include/skalibs/gensetdyn.h
src/libdatastruct/gensetdyn_iter_withcancel.o src/libdatastruct/gensetdyn_iter_withcancel.lo: src/libdatastruct/gensetdyn_iter_withcancel.c src/include/skalibs/gensetdyn.h
src/libdatastruct/gensetdyn_new.o src/libdatastruct/gensetdyn_new.lo: src/libdatastruct/gensetdyn_new.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h
src/libdatastruct/gensetdyn_ready.o src/libdatastruct/gensetdyn_ready.lo: src/libdatastruct/gensetdyn_ready.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/include/skalibs/stralloc.h
@@ -599,6 +599,8 @@ src/libstddjb/tai_unpack_little.o src/libstddjb/tai_unpack_little.lo: src/libstd
src/libstddjb/tain_add.o src/libstddjb/tain_add.lo: src/libstddjb/tain_add.c src/include/skalibs/tai.h
src/libstddjb/tain_addsec.o src/libstddjb/tain_addsec.lo: src/libstddjb/tain_addsec.c src/include/skalibs/tai.h src/include/skalibs/uint64.h
src/libstddjb/tain_approx.o src/libstddjb/tain_approx.lo: src/libstddjb/tain_approx.c src/include/skalibs/tai.h
+src/libstddjb/tain_earliest1.o src/libstddjb/tain_earliest1.lo: src/libstddjb/tain_earliest1.c src/include/skalibs/tai.h
+src/libstddjb/tain_earliestv.o src/libstddjb/tain_earliestv.lo: src/libstddjb/tain_earliestv.c src/include/skalibs/tai.h
src/libstddjb/tain_fmt.o src/libstddjb/tain_fmt.lo: src/libstddjb/tain_fmt.c src/include/skalibs/fmtscan.h src/include/skalibs/tai.h
src/libstddjb/tain_frac.o src/libstddjb/tain_frac.lo: src/libstddjb/tain_frac.c src/include/skalibs/tai.h
src/libstddjb/tain_from_localtmn.o src/libstddjb/tain_from_localtmn.lo: src/libstddjb/tain_from_localtmn.c src/include/skalibs/djbtime.h
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] ;
+}