summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-02-22 10:03:15 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-02-22 10:03:15 +0000
commita5079576ae9007fb1ca7ebcc911b5fb035cd2d06 (patch)
tree70f4014dd37d780dfb45182d26092cb1998d4eec /src/include
parent49d8fa1058aaf23c29e074b2314492ae40d2f557 (diff)
downloadskalibs-a5079576ae9007fb1ca7ebcc911b5fb035cd2d06.tar.xz
Types change: switch libdatastruct to uint32_t
Still needs to be reviewed.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/skalibs/avlnode.h27
-rw-r--r--src/include/skalibs/avltree.h17
-rw-r--r--src/include/skalibs/avltreen.h13
-rw-r--r--src/include/skalibs/functypes.h7
-rw-r--r--src/include/skalibs/genset.h19
-rw-r--r--src/include/skalibs/gensetdyn.h23
6 files changed, 57 insertions, 49 deletions
diff --git a/src/include/skalibs/avlnode.h b/src/include/skalibs/avlnode.h
index 245eef4..69e507b 100644
--- a/src/include/skalibs/avlnode.h
+++ b/src/include/skalibs/avlnode.h
@@ -3,44 +3,45 @@
#ifndef AVLNODE_H
#define AVLNODE_H
+#include <stdint.h>
#include <skalibs/gccattributes.h>
#include <skalibs/functypes.h>
#define AVLNODE_MAXDEPTH 49 /* enough for 2^32 nodes in the worst case */
-typedef int avliterfunc_t (unsigned int, unsigned int, void *) ;
+typedef int avliterfunc_t (uint32_t, unsigned int, void *) ;
typedef avliterfunc_t *avliterfunc_t_ref ;
typedef struct avlnode_s avlnode, *avlnode_ref ;
struct avlnode_s
{
- unsigned int data ;
- unsigned int child[2] ;
+ uint32_t data ;
+ uint32_t child[2] ;
signed char balance : 2 ;
} ;
-#define AVLNODE_ZERO { .data = 0, .child = { (unsigned int)-1, (unsigned int)-1 }, .balance = 0 }
+#define AVLNODE_ZERO { .data = 0, .child = { UINT32_MAX, UINT32_MAX }, .balance = 0 }
extern avlnode const avlnode_zero ;
-extern unsigned int avlnode_searchnode (avlnode const *, unsigned int, unsigned int, void const *, dtokfunc_t_ref, cmpfunc_t_ref, void *) ;
-extern int avlnode_search (avlnode const *, unsigned int, unsigned int, void const *, unsigned int *, dtokfunc_t_ref, cmpfunc_t_ref, void *) ;
-extern unsigned int avlnode_height (avlnode const *, unsigned int, unsigned int) gccattr_pure ;
+extern uint32_t avlnode_searchnode (avlnode const *, uint32_t, uint32_t, void const *, dtokfunc_t_ref, cmpfunc_t_ref, void *) ;
+extern int avlnode_search (avlnode const *, uint32_t, uint32_t, void const *, uint32_t *, dtokfunc_t_ref, cmpfunc_t_ref, void *) ;
+extern unsigned int avlnode_height (avlnode const *, uint32_t, uint32_t) gccattr_pure ;
-extern unsigned int avlnode_extremenode (avlnode const *, unsigned int, unsigned int, int) gccattr_pure ;
+extern uint32_t avlnode_extremenode (avlnode const *, uint32_t, uint32_t, int) gccattr_pure ;
#define avlnode_minnode(s, max, r) avlnode_extremenode(s, max, (r), 0)
#define avlnode_maxnode(s, max, r) avlnode_extremenode(s, max, (r), 1)
-extern int avlnode_extreme (avlnode const *, unsigned int, unsigned int, int, unsigned int *) ;
+extern int avlnode_extreme (avlnode const *, uint32_t, uint32_t, int, uint32_t *) ;
#define avlnode_min(s, max, r, data) avlnode_extreme(s, max, (r), 0, data)
#define avlnode_max(s, max, r, data) avlnode_extreme(s, max, (r), 1, data)
-extern unsigned int avlnode_insertnode (avlnode *, unsigned int, unsigned int, unsigned int, dtokfunc_t_ref, cmpfunc_t_ref, void *) ;
-extern unsigned int avlnode_delete (avlnode *, unsigned int, unsigned int *, void const *, dtokfunc_t_ref, cmpfunc_t_ref, void *) ;
+extern uint32_t avlnode_insertnode (avlnode *, uint32_t, uint32_t, uint32_t, dtokfunc_t_ref, cmpfunc_t_ref, void *) ;
+extern uint32_t avlnode_delete (avlnode *, uint32_t, uint32_t *, void const *, dtokfunc_t_ref, cmpfunc_t_ref, void *) ;
#define avlnode_deletenode(s, max, r, i, dtok, f, p) avlnode_delete(s, max, r, (*(dtok))((s)[i].data), dtok, f, p)
-extern unsigned int avlnode_iter_nocancel (avlnode *, unsigned int, unsigned int, unsigned int, avliterfunc_t_ref, void *) ;
+extern uint32_t avlnode_iter_nocancel (avlnode *, uint32_t, uint32_t, uint32_t, avliterfunc_t_ref, void *) ;
#define avlnode_iter(tree, max, root, f, stuff) (avlnode_iter_nocancel(tree, max, max, root, f, stuff) == (max))
-extern int avlnode_iter_withcancel (avlnode *, unsigned int, unsigned int, avliterfunc_t_ref, avliterfunc_t_ref, void *) ;
+extern int avlnode_iter_withcancel (avlnode *, uint32_t, uint32_t, avliterfunc_t_ref, avliterfunc_t_ref, void *) ;
#endif
diff --git a/src/include/skalibs/avltree.h b/src/include/skalibs/avltree.h
index 0b74235..1ce7385 100644
--- a/src/include/skalibs/avltree.h
+++ b/src/include/skalibs/avltree.h
@@ -3,6 +3,7 @@
#ifndef AVLTREE_H
#define AVLTREE_H
+#include <stdint.h>
#include <skalibs/functypes.h>
#include <skalibs/gensetdyn.h>
#include <skalibs/avlnode.h>
@@ -11,24 +12,24 @@ typedef struct avltree_s avltree, *avltree_ref ;
struct avltree_s
{
gensetdyn x ;
- unsigned int root ;
+ uint32_t root ;
dtokfunc_t_ref dtok ;
cmpfunc_t_ref kcmp ;
void *external ;
} ;
-#define AVLTREE_ZERO { .x = GENSETDYN_ZERO, .root = (unsigned int)-1, .dtok = 0, .kcmp = 0, .external = 0 }
+#define AVLTREE_ZERO { .x = GENSETDYN_ZERO, .root = UINT32_MAX, .dtok = 0, .kcmp = 0, .external = 0 }
extern avltree const avltree_zero ;
#define avltree_len(t) gensetdyn_n(&(t)->x)
-#define avltree_totalsize(t) ((t)->x.storage.len)
+#define avltree_totalsize(t) ((uint32_t)(t)->x.storage.len)
#define avltree_nodes(t) ((avlnode *)(t)->x.storage.s)
-#define avltree_data(t, i) (avltree_nodes(t)[i].data)
+#define avltree_data(t, i) ((uint32_t)avltree_nodes(t)[i].data)
#define avltree_root(t) ((t)->root)
#define avltree_setroot(t, r) ((t)->root = (r))
extern void avltree_free (avltree *) ;
-extern void avltree_init (avltree *, unsigned int, unsigned int, unsigned int, dtokfunc_t_ref, cmpfunc_t_ref, void *) ;
-#define AVLTREE_INIT(b, num, den, dtk, f, p) { .x = GENSETDYN_INIT(avlnode, (b), num, den), .root = (unsigned int)-1, .dtok = (dtk), .kcmp = (f), .external = (p) }
+extern void avltree_init (avltree *, uint32_t, uint32_t, uint32_t, dtokfunc_t_ref, cmpfunc_t_ref, void *) ;
+#define AVLTREE_INIT(b, num, den, dtk, f, p) { .x = GENSETDYN_INIT(avlnode, (b), num, den), .root = UINT32_MAX, .dtok = (dtk), .kcmp = (f), .external = (p) }
#define avltree_searchnode(t, k) avlnode_searchnode(avltree_nodes(t), avltree_totalsize(t), avltree_root(t), k, (t)->dtok, (t)->kcmp, (t)->external)
#define avltree_search(t, k, data) avlnode_search(avltree_nodes(t), avltree_totalsize(t), avltree_root(t), k, (data), (t)->dtok, (t)->kcmp, (t)->external)
@@ -43,9 +44,9 @@ extern void avltree_init (avltree *, unsigned int, unsigned int, unsigned int, d
#define avltree_min(t, data) avltree_extreme((t), 0, data)
#define avltree_max(t, data) avltree_extreme((t), 1, data)
-extern int avltree_newnode (avltree *, unsigned int, unsigned int *) ;
+extern int avltree_newnode (avltree *, uint32_t, uint32_t *) ;
#define avltree_insertnode(t, i) avltree_setroot(t, avlnode_insertnode(avltree_nodes(t), avltree_totalsize(t), avltree_root(t), i, (t)->dtok, (t)->kcmp, (t)->external))
-extern int avltree_insert (avltree *, unsigned int) ;
+extern int avltree_insert (avltree *, uint32_t) ;
#define avltree_deletenode(t, i) avltree_delete(t, (*(t)->dtok)(avltree_data(t, i)))
extern int avltree_delete (avltree *, void const *) ;
diff --git a/src/include/skalibs/avltreen.h b/src/include/skalibs/avltreen.h
index 542ac5d..09ef480 100644
--- a/src/include/skalibs/avltreen.h
+++ b/src/include/skalibs/avltreen.h
@@ -3,6 +3,7 @@
#ifndef AVLTREEN_H
#define AVLTREEN_H
+#include <stdint.h>
#include <skalibs/functypes.h>
#include <skalibs/genset.h>
#include <skalibs/avlnode.h>
@@ -14,20 +15,20 @@ typedef struct avltreen_s avltreen, *avltreen_ref ;
struct avltreen_s
{
genset x ;
- unsigned int root ;
+ uint32_t root ;
dtokfunc_t_ref dtok ;
cmpfunc_t_ref kcmp ;
void *external ;
} ;
-#define AVLTREEN_ZERO { .x = GENSET_ZERO, .root = (unsigned int)-1, .dtok = 0, .kcmp = 0, .external = 0 }
+#define AVLTREEN_ZERO { .x = GENSET_ZERO, .root = UINT32_MAX, .dtok = 0, .kcmp = 0, .external = 0 }
#define avltreen_totalsize(t) ((t)->x.max)
#define avltreen_len(t) genset_n(&(t)->x)
#define avltreen_nodes(t) ((avlnode *)(t)->x.storage)
#define avltreen_data(t, i) (avltreen_nodes(t)[i].data)
#define avltreen_root(t) ((t)->root)
#define avltreen_setroot(t, r) ((t)->root = (r))
-extern void avltreen_init (avltreen *, avlnode *, unsigned int *, unsigned int, dtokfunc_t_ref, cmpfunc_t_ref, void *) ;
+extern void avltreen_init (avltreen *, avlnode *, uint32_t *, uint32_t, dtokfunc_t_ref, cmpfunc_t_ref, void *) ;
#define avltreen_searchnode(t, k) avlnode_searchnode(avltreen_nodes(t), avltreen_totalsize(t), avltreen_root(t), (k), (t)->dtok, (t)->kcmp, (t)->external)
#define avltreen_search(t, k, data) avlnode_search(avltreen_nodes(t), avltreen_totalsize(t), avltreen_root(t), k, (data), (t)->dtok, (t)->kcmp, (t)->external)
@@ -42,9 +43,9 @@ extern void avltreen_init (avltreen *, avlnode *, unsigned int *, unsigned int,
#define avltreen_min(t, data) avltreen_extreme((t), 0, data)
#define avltreen_max(t, data) avltreen_extreme((t), 1, data)
-extern unsigned int avltreen_newnode (avltreen *, unsigned int) ;
+extern uint32_t avltreen_newnode (avltreen *, uint32_t) ;
#define avltreen_insertnode(t, i) avltreen_setroot(t, avlnode_insertnode(avltreen_nodes(t), avltreen_totalsize(t), avltreen_root(t), i, (t)->dtok, (t)->kcmp, (t)->external))
-extern int avltreen_insert (avltreen *, unsigned int) ;
+extern int avltreen_insert (avltreen *, uint32_t) ;
#define avltreen_deletenode(t, i) avltreen_delete(t, avltreen_data(t, i))
extern int avltreen_delete (avltreen *, void const *) ;
@@ -56,7 +57,7 @@ extern int avltreen_delete (avltreen *, void const *) ;
/* avltreeb: everything in one place. Stack or BSS, or heap if you insist */
-#define AVLTREEB_TYPE(size) struct { avlnode storage[size] ; unsigned int freelist[size] ; avltreen info ; }
+#define AVLTREEB_TYPE(size) struct { avlnode storage[size] ; uint32_t freelist[size] ; avltreen info ; }
#define avltreeb_init(t, size, dtk, f, p) avltreen_init(&(t)->info, (t)->storage, (t)->freelist, size, dtk, f, p)
#define avltreeb_totalsize(t) avltreen_totalsize(&(t)->info)
#define avltreeb_len(t) avltreen_len(&(t)->info)
diff --git a/src/include/skalibs/functypes.h b/src/include/skalibs/functypes.h
index f67a0bc..8308fda 100644
--- a/src/include/skalibs/functypes.h
+++ b/src/include/skalibs/functypes.h
@@ -3,16 +3,19 @@
#ifndef FUNCTYPES_H
#define FUNCTYPES_H
-#include <sys/types.h>
+#include <stdint.h>
#include <sys/uio.h>
typedef int uintcmpfunc_t (unsigned int, unsigned int, void *) ;
typedef uintcmpfunc_t *uintcmpfunc_t_ref ;
+typedef int uint32cmpfunc_t (uint32_t, uint32_t, void *) ;
+typedef uint32cmpfunc_t *uint32cmpfunc_t_ref ;
+
typedef int cmpfunc_t (void const *, void const *, void *) ;
typedef cmpfunc_t *cmpfunc_t_ref ;
-typedef void *dtokfunc_t (unsigned int, void *) ;
+typedef void *dtokfunc_t (uint32_t, void *) ;
typedef dtokfunc_t *dtokfunc_t_ref ;
typedef int iterfunc_t (char *, void *) ;
diff --git a/src/include/skalibs/genset.h b/src/include/skalibs/genset.h
index 83e0519..9241d1a 100644
--- a/src/include/skalibs/genset.h
+++ b/src/include/skalibs/genset.h
@@ -3,31 +3,32 @@
#ifndef GENSET_H
#define GENSET_H
+#include <stdint.h>
#include <skalibs/functypes.h>
typedef struct genset_s genset, *genset_ref ;
struct genset_s
{
char *storage ;
- unsigned int *freelist ;
- unsigned int esize ;
- unsigned int max ;
- unsigned int sp ;
+ uint32_t *freelist ;
+ uint32_t esize ;
+ uint32_t max ;
+ uint32_t sp ;
} ;
#define GENSET_ZERO { .storage = 0, .freelist = 0, .esize = 1, .max = 0, .sp = 0 }
-extern void genset_init (genset *, void *, unsigned int *, unsigned int, unsigned int) ;
+extern void genset_init (genset *, void *, uint32_t *, uint32_t, uint32_t) ;
#define GENSET_init(g, type, storage, fl, size) genset_init(g, storage, fl, sizeof(type), size)
#define genset_p(type, g, i) ((type *)((g)->storage + (i) * (g)->esize))
-extern unsigned int genset_new (genset *) ;
-extern int genset_delete (genset *, unsigned int) ;
+extern uint32_t genset_new (genset *) ;
+extern int genset_delete (genset *, uint32_t) ;
#define genset_n(g) ((g)->max - (g)->sp)
-extern unsigned int genset_iter_nocancel (genset *, unsigned int, iterfunc_t_ref, void *) ;
+extern uint32_t genset_iter_nocancel (genset *, uint32_t, iterfunc_t_ref, void *) ;
#define genset_iter(g, f, stuff) genset_iter_nocancel(g, (g)->max, f, stuff)
extern int genset_iter_withcancel (genset *, iterfunc_t_ref, iterfunc_t_ref, void *) ;
-#define GENSETB_TYPE(type, size) struct { type storage[size] ; unsigned int freelist[size] ; genset info ; }
+#define GENSETB_TYPE(type, size) struct { type storage[size] ; uint32_t freelist[size] ; genset info ; }
#define GENSETB_init(type, g, size) GENSET_init(&(g)->info, type, (g)->storage, (g)->freelist, size)
#define gensetb_p(type, g, i) genset_p(type, &(g)->info, i)
#define gensetb_new(g) genset_new(&(g)->info)
diff --git a/src/include/skalibs/gensetdyn.h b/src/include/skalibs/gensetdyn.h
index 5171a00..f851ae7 100644
--- a/src/include/skalibs/gensetdyn.h
+++ b/src/include/skalibs/gensetdyn.h
@@ -3,6 +3,7 @@
#ifndef GENSETDYN_H
#define GENSETDYN_H
+#include <stdint.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
#include <skalibs/functypes.h>
@@ -11,31 +12,31 @@ typedef struct gensetdyn_s gensetdyn, *gensetdyn_ref ;
struct gensetdyn_s
{
stralloc storage ;
- genalloc freelist ; /* array of unsigned int */
- unsigned int esize ;
- unsigned int base ;
- unsigned int fracnum ;
- unsigned int fracden ;
+ genalloc freelist ; /* array of uint32_t */
+ uint32_t esize ;
+ uint32_t base ;
+ uint32_t fracnum ;
+ uint32_t fracden ;
} ;
#define GENSETDYN_ZERO { .storage = STRALLOC_ZERO, .freelist = GENALLOC_ZERO, .esize = 1, .base = 0, .fracnum = 0, .fracden = 1 }
extern gensetdyn const gensetdyn_zero ;
#define GENSETDYN_INIT(type, b, num, den) { .storage = STRALLOC_ZERO, .freelist = GENALLOC_ZERO, .esize = sizeof(type), .base = (b), .fracnum = (num), .fracden = (den) }
-extern void gensetdyn_init (gensetdyn *, unsigned int, unsigned int, unsigned int, unsigned int) ;
+extern void gensetdyn_init (gensetdyn *, uint32_t, uint32_t, uint32_t, uint32_t) ;
-#define gensetdyn_n(g) ((g)->storage.len - genalloc_len(unsigned int, &(g)->freelist))
-extern int gensetdyn_ready (gensetdyn *, unsigned int) ;
+#define gensetdyn_n(g) ((uint32_t)((g)->storage.len - genalloc_len(uint32_t, &(g)->freelist)))
+extern int gensetdyn_ready (gensetdyn *, uint32_t) ;
#define gensetdyn_readyplus(x, n) gensetdyn_ready(x, gensetdyn_n(x) + (n))
extern void gensetdyn_free (gensetdyn *) ;
-extern int gensetdyn_new (gensetdyn *, unsigned int *) ;
-extern int gensetdyn_delete (gensetdyn *, unsigned int) ;
+extern int gensetdyn_new (gensetdyn *, uint32_t *) ;
+extern int gensetdyn_delete (gensetdyn *, uint32_t) ;
#define gensetdyn_p(g, i) ((g)->storage.s + (i) * (g)->esize)
#define GENSETDYN_P(type, g, i) ((type *)gensetdyn_p(g, i))
-extern unsigned int gensetdyn_iter_nocancel (gensetdyn *, unsigned int, iterfunc_t_ref, void *) ;
+extern uint32_t gensetdyn_iter_nocancel (gensetdyn *, uint32_t, iterfunc_t_ref, void *) ;
#define gensetdyn_iter(g, f, stuff) gensetdyn_iter_nocancel(g, gensetdyn_n(g), f, stuff)
extern int gensetdyn_iter_withcancel (gensetdyn *, iterfunc_t_ref, iterfunc_t_ref, void *) ;