rcx

library of miscellaneous bits of C code
git clone git://git.rr3.xyz/rcx
Log | Files | Refs | README | LICENSE

commit f1318007de1b919bf8e76c254e1d489b6b84eedf
parent 91039c0cb7e583d5946eeb64134e96678dd3e023
Author: Robert Russell <robertrussell.72001@gmail.com>
Date:   Tue, 26 Sep 2023 10:36:49 -0700

Update set

See the previous commits.

Diffstat:
Dinc/set/declare.h | 10----------
Dinc/set/define.h | 10----------
Ainc/set/impl/clean.h | 11+++++++++++
Dinc/set/impl/declare.h | 54------------------------------------------------------
Ainc/set/impl/decls.h | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Rinc/set/impl/macro.h -> inc/set/impl/macros.h | 0
Minc/set/impl/table.h | 2++
Ainc/set/impl/types.h | 3+++
Dinc/set/impl/unmacro.h | 7-------
Ainc/set/main.h | 16++++++++++++++++
Ainc/set/priv-hdr.h | 3+++
Ainc/set/priv-src.h | 4++++
Ainc/set/pub-hdr.h | 3+++
Ainc/set/pub-src.h | 2++
Minc/set/static.h | 15+++++----------
15 files changed, 99 insertions(+), 91 deletions(-)

diff --git a/inc/set/declare.h b/inc/set/declare.h @@ -1,10 +0,0 @@ -#include <stdbool.h> - -#include "../alloc.h" -#include "../def.h" -#include "../rand.h" - -#include "impl/macro.h" -#include "impl/table.h" -#include "impl/declare.h" -#include "impl/unmacro.h" diff --git a/inc/set/define.h b/inc/set/define.h @@ -1,10 +0,0 @@ -#include <stdbool.h> - -#include "../alloc.h" -#include "../def.h" -#include "../rand.h" - -#include "impl/macro.h" -#include "impl/table.h" -#include "impl/declare.h" -#include "impl/unmacro.h" diff --git a/inc/set/impl/clean.h b/inc/set/impl/clean.h @@ -0,0 +1,11 @@ +#undef SET_METHOD +#undef SET_FREE +#undef SET_ALLOCZ +#undef SET_HASH +#undef SET_EQ +#undef SET_T +#undef SET_NAME +#undef SET_STATIC +#undef SET_DEFS +#undef SET_DECLS +#undef SET_TYPES diff --git a/inc/set/impl/declare.h b/inc/set/impl/declare.h @@ -1,54 +0,0 @@ -typedef struct { - RTable table; -} SET_NAME; - -#define SET_SPEC &(RSetTableSpec){ \ - .ksize = sizeof(SET_T), \ - .eq = (RTableEqFunc)(SET_EQ), \ - .hash = (RTableHashFunc)(SET_HASH), \ - .allocz = (RTableAlloczFunc)(SET_ALLOCZ), \ - .free = (RTableFreeFunc)(SET_FREE), \ - } - -static inline UNUSED int -SET_METHOD(init)(SET_NAME *s, usize hint) { - return r_set_table_init(&s->table, hint, SET_SPEC); -} - -static inline UNUSED void -SET_METHOD(free)(SET_NAME *s) { - r_set_table_free(&s->table, SET_SPEC); -} - -static inline UNUSED usize -SET_METHOD(len)(SET_NAME *s) { - return r_set_table_len(&s->table, SET_SPEC); -} - -static inline UNUSED bool -SET_METHOD(has)(SET_NAME *s, SET_T k) { - u64 h = SET_HASH(&k, s->table.seed, sizeof(SET_T)); - void *vp; - return r_set_table_acc(&s->table, &vp, &k, h, SET_SPEC) > 0; -} - -static inline UNUSED int -SET_METHOD(put)(SET_NAME *s, SET_T k) { - u64 h = SET_HASH(&k, s->table.seed, sizeof(SET_T)); - void *vp; - return r_set_table_ins(&s->table, &vp, &k, h, SET_SPEC); -} - -static inline UNUSED bool -SET_METHOD(del)(SET_NAME *s, SET_T k) { - u64 h = SET_HASH(&k, s->table.seed, sizeof(SET_T)); - void *vp; - return r_set_table_del(&s->table, &vp, &k, h, SET_SPEC) > 0; -} - -static inline UNUSED void -SET_METHOD(clr)(SET_NAME *s) { - r_set_table_clr(&s->table, SET_SPEC); -} - -#undef SET_SPEC diff --git a/inc/set/impl/decls.h b/inc/set/impl/decls.h @@ -0,0 +1,50 @@ +#define SET_SPEC &(RSetTableSpec){ \ + .ksize = sizeof(SET_T), \ + .eq = (RTableEqFunc)(SET_EQ), \ + .hash = (RTableHashFunc)(SET_HASH), \ + .allocz = (RTableAlloczFunc)(SET_ALLOCZ), \ + .free = (RTableFreeFunc)(SET_FREE), \ + } + +static inline UNUSED int +SET_METHOD(init)(SET_NAME *s, usize hint) { + return r_set_table_init(&s->table, hint, SET_SPEC); +} + +static inline UNUSED void +SET_METHOD(free)(SET_NAME *s) { + r_set_table_free(&s->table, SET_SPEC); +} + +static inline UNUSED usize +SET_METHOD(len)(SET_NAME *s) { + return r_set_table_len(&s->table, SET_SPEC); +} + +static inline UNUSED bool +SET_METHOD(has)(SET_NAME *s, SET_T k) { + u64 h = SET_HASH(&k, s->table.seed, sizeof(SET_T)); + void *vp; + return r_set_table_acc(&s->table, &vp, &k, h, SET_SPEC) > 0; +} + +static inline UNUSED int +SET_METHOD(put)(SET_NAME *s, SET_T k) { + u64 h = SET_HASH(&k, s->table.seed, sizeof(SET_T)); + void *vp; + return r_set_table_ins(&s->table, &vp, &k, h, SET_SPEC); +} + +static inline UNUSED bool +SET_METHOD(del)(SET_NAME *s, SET_T k) { + u64 h = SET_HASH(&k, s->table.seed, sizeof(SET_T)); + void *vp; + return r_set_table_del(&s->table, &vp, &k, h, SET_SPEC) > 0; +} + +static inline UNUSED void +SET_METHOD(clr)(SET_NAME *s) { + r_set_table_clr(&s->table, SET_SPEC); +} + +#undef SET_SPEC diff --git a/inc/set/impl/macro.h b/inc/set/impl/macros.h diff --git a/inc/set/impl/table.h b/inc/set/impl/table.h @@ -1,3 +1,5 @@ +#pragma once + #define TABLE_VSIZE 0 #define TABLE_SPEC_NAME RSetTableSpec #define TABLE_METHOD(name) r_set_table_##name diff --git a/inc/set/impl/types.h b/inc/set/impl/types.h @@ -0,0 +1,3 @@ +typedef struct { + RTable table; +} SET_NAME; diff --git a/inc/set/impl/unmacro.h b/inc/set/impl/unmacro.h @@ -1,7 +0,0 @@ -#undef SET_METHOD -#undef SET_FREE -#undef SET_ALLOCZ -#undef SET_HASH -#undef SET_EQ -#undef SET_T -#undef SET_NAME diff --git a/inc/set/main.h b/inc/set/main.h @@ -0,0 +1,16 @@ +#if defined(SET_DECLS) || defined(SET_DEFS) +#include <stdbool.h> +#include "../alloc.h" +#include "../def.h" +#include "../rand.h" +#endif + +#include "impl/macros.h" +#include "impl/table.h" +#ifdef SET_TYPES +#include "impl/types.h" +#endif +#if defined(SET_DECLS) || defined(SET_DEFS) +#include "impl/decls.h" +#endif +#include "impl/clean.h" diff --git a/inc/set/priv-hdr.h b/inc/set/priv-hdr.h @@ -0,0 +1,3 @@ +#define SET_TYPES +#define SET_STATIC +#include "main.h" diff --git a/inc/set/priv-src.h b/inc/set/priv-src.h @@ -0,0 +1,4 @@ +#define SET_DECLS +#define SET_DEFS +#define SET_STATIC +#include "main.h" diff --git a/inc/set/pub-hdr.h b/inc/set/pub-hdr.h @@ -0,0 +1,3 @@ +#define SET_TYPES +#define SET_DECLS +#include "main.h" diff --git a/inc/set/pub-src.h b/inc/set/pub-src.h @@ -0,0 +1,2 @@ +#define SET_DEFS +#include "main.h" diff --git a/inc/set/static.h b/inc/set/static.h @@ -1,10 +1,5 @@ -#include <stdbool.h> - -#include "../alloc.h" -#include "../def.h" -#include "../rand.h" - -#include "impl/macro.h" -#include "impl/table.h" -#include "impl/declare.h" -#include "impl/unmacro.h" +#define SET_TYPES +#define SET_DECLS +#define SET_DEFS +#define SET_STATIC +#include "main.h"