summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-12-29 14:16:27 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-12-29 14:16:27 +0000
commited40369c8610914085d568ec57701a035bf8dd29 (patch)
tree26425c589b590306fbba48140fabdd0abe4877bf /src/include
parenta8e40d0287f05f6e444035431b1cc7b340fe8d79 (diff)
downloadskalibs-ed40369c8610914085d568ec57701a035bf8dd29.tar.xz
Add genqdyn
Diffstat (limited to 'src/include')
-rw-r--r--src/include/skalibs/datastruct.h1
-rw-r--r--src/include/skalibs/genqdyn.h33
2 files changed, 34 insertions, 0 deletions
diff --git a/src/include/skalibs/datastruct.h b/src/include/skalibs/datastruct.h
index 1c7d816..7e2813e 100644
--- a/src/include/skalibs/datastruct.h
+++ b/src/include/skalibs/datastruct.h
@@ -3,6 +3,7 @@
#ifndef DATASTRUCT_H
#define DATASTRUCT_H
+#include <skalibs/genqdyn.h>
#include <skalibs/genset.h>
#include <skalibs/gensetdyn.h>
#include <skalibs/avlnode.h>
diff --git a/src/include/skalibs/genqdyn.h b/src/include/skalibs/genqdyn.h
new file mode 100644
index 0000000..0f7751b
--- /dev/null
+++ b/src/include/skalibs/genqdyn.h
@@ -0,0 +1,33 @@
+/* ISC license. */
+
+#ifndef SKALIBS_GENQDYN_H
+#define SKALIBS_GENQDYN_H
+
+#include <sys/types.h>
+#include <skalibs/stralloc.h>
+
+typedef struct genqdyn_s genqdyn, *genqdyn_ref ;
+struct genqdyn_s
+{
+ stralloc queue ;
+ size_t esize ;
+ size_t head ;
+ unsigned int num ;
+ unsigned int den ;
+} ;
+
+#define GENQDYN_ZERO { .queue = STRALLOC_ZERO, .esize = 1, .head = 0, .num = 0, .den = 1 }
+extern genqdyn const genqdyn_zero ;
+
+#define GENQDYN_INIT(type, n, d) { .queue = STRALLOC_ZERO, .esize = sizeof(type), .head = 0, .num = n, .den = d }
+extern void genqdyn_init (genqdyn *, size_t, unsigned int, unsigned int) ;
+
+#define genqdyn_n(g) ((g)->queue.len / (g)->esize - (g)->head) ;
+
+extern void genqdyn_free (genqdyn *) ;
+extern int genqdyn_push (genqdyn *, void const *) ;
+#define GENQDYN_PEEK(type, g) ((type *)((g)->queue.s + (g)->esize * (g)->head))
+#define genqdyn_peek(g) GENQDYN_PEEK(void, (g))
+extern int genqdyn_pop(genqdyn *) ;
+
+#endif