From 1d530c65782b499bb75afff76f1214edfe30ec21 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Mon, 18 Jul 2022 16:00:26 +1000 Subject: [PATCH] major reorganisation --- Doxyfile | 4 +- htable/Makefile | 18 +++---- {vector => logic}/AndQuery.c | 0 {vector => logic}/AndQuery.h | 0 {vector => logic}/AssignQuery.c | 0 {vector => logic}/AssignQuery.h | 0 {vector => logic}/Binding.c | 0 {vector => logic}/Binding.h | 0 {vector => logic}/BindingTable.c | 0 {vector => logic}/BindingTable.h | 0 logic/Makefile | 13 +++++ {vector => logic}/NotQuery.c | 0 {vector => logic}/NotQuery.h | 0 {vector => logic}/OrQuery.c | 0 {vector => logic}/OrQuery.h | 0 {vector => logic}/Query.c | 0 {vector => logic}/Query.h | 0 {vector => logic}/QueryCallbacks.h | 0 {vector => logic}/Relation.c | 0 {vector => logic}/Relation.h | 0 {vector => logic}/RelationQuery.c | 0 {vector => logic}/RelationQuery.h | 0 {vector => logic}/Tuple.c | 0 {vector => logic}/Tuple.h | 0 {vector => logic}/TupleSchema.c | 0 {vector => logic}/TupleSchema.h | 2 +- socket-sniff/Makefile | 8 ++- socket-sniff/socket-sniff.c | 87 +++++++++++++++++------------- tests/Makefile | 6 ++- tests/example-relation.c | 2 +- typing/ItemKeyFun.c | 67 +++++++++++++++++++++++ {vector => typing}/ItemKeyFun.h | 39 +++++++++++--- typing/Makefile | 8 +++ {vector => typing}/integeritem.c | 0 {vector => typing}/integeritem.h | 0 {vector => typing}/stringitem.c | 0 {vector => typing}/stringitem.h | 0 vector/HashVector.c | 16 +++--- vector/Makefile | 31 +---------- vector/mainpage.dox | 46 ---------------- 40 files changed, 201 insertions(+), 146 deletions(-) rename {vector => logic}/AndQuery.c (100%) rename {vector => logic}/AndQuery.h (100%) rename {vector => logic}/AssignQuery.c (100%) rename {vector => logic}/AssignQuery.h (100%) rename {vector => logic}/Binding.c (100%) rename {vector => logic}/Binding.h (100%) rename {vector => logic}/BindingTable.c (100%) rename {vector => logic}/BindingTable.h (100%) create mode 100644 logic/Makefile rename {vector => logic}/NotQuery.c (100%) rename {vector => logic}/NotQuery.h (100%) rename {vector => logic}/OrQuery.c (100%) rename {vector => logic}/OrQuery.h (100%) rename {vector => logic}/Query.c (100%) rename {vector => logic}/Query.h (100%) rename {vector => logic}/QueryCallbacks.h (100%) rename {vector => logic}/Relation.c (100%) rename {vector => logic}/Relation.h (100%) rename {vector => logic}/RelationQuery.c (100%) rename {vector => logic}/RelationQuery.h (100%) rename {vector => logic}/Tuple.c (100%) rename {vector => logic}/Tuple.h (100%) rename {vector => logic}/TupleSchema.c (100%) rename {vector => logic}/TupleSchema.h (96%) create mode 100644 typing/ItemKeyFun.c rename {vector => typing}/ItemKeyFun.h (63%) create mode 100644 typing/Makefile rename {vector => typing}/integeritem.c (100%) rename {vector => typing}/integeritem.h (100%) rename {vector => typing}/stringitem.c (100%) rename {vector => typing}/stringitem.h (100%) delete mode 100644 vector/mainpage.dox diff --git a/Doxyfile b/Doxyfile index a32e453..d4690db 100644 --- a/Doxyfile +++ b/Doxyfile @@ -58,7 +58,7 @@ PROJECT_LOGO = # entered, it will be relative to the location where doxygen was started. If # left blank the current directory will be used. -OUTPUT_DIRECTORY = /home/ralph/src/borta/misc/docs +OUTPUT_DIRECTORY = /home/ralph/src/borta/rrqmisc/docs # If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- # directories (in 2 levels) under the output directory of each output format and @@ -864,7 +864,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = /home/ralph/src/borta/misc/vector +INPUT = /home/ralph/src/borta/rrqmisc/vector # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/htable/Makefile b/htable/Makefile index 4d0ed95..e8bd7e1 100644 --- a/htable/Makefile +++ b/htable/Makefile @@ -1,18 +1,14 @@ -default: libhtable.a +LIBRARY = librrqhtable.a +LIBOBJS = htable.o -.INTERMEDIATE: htable.o -htable.o: CFLAGS = -Wall -g -htable.o: htable.c +default: $(LIBRARY) example-htable +CLEANRM += $(LIBRARY) -libhtable.a: htable.o - $(AR) r $@ $^ -CLEANRM += libhtable.a +include ../common.mk .INTERMEDIATE: example-htable.o example-htable: CFLAGS = -Wall -g -example-htable: LDLIBS = libhtable.a -example-htable: example-htable.o libhtable.a +example-htable: example-htable.o $(LIBRARY) + CLEANRM += example-htable -clean: - rm -f $(CLEANRM) diff --git a/vector/AndQuery.c b/logic/AndQuery.c similarity index 100% rename from vector/AndQuery.c rename to logic/AndQuery.c diff --git a/vector/AndQuery.h b/logic/AndQuery.h similarity index 100% rename from vector/AndQuery.h rename to logic/AndQuery.h diff --git a/vector/AssignQuery.c b/logic/AssignQuery.c similarity index 100% rename from vector/AssignQuery.c rename to logic/AssignQuery.c diff --git a/vector/AssignQuery.h b/logic/AssignQuery.h similarity index 100% rename from vector/AssignQuery.h rename to logic/AssignQuery.h diff --git a/vector/Binding.c b/logic/Binding.c similarity index 100% rename from vector/Binding.c rename to logic/Binding.c diff --git a/vector/Binding.h b/logic/Binding.h similarity index 100% rename from vector/Binding.h rename to logic/Binding.h diff --git a/vector/BindingTable.c b/logic/BindingTable.c similarity index 100% rename from vector/BindingTable.c rename to logic/BindingTable.c diff --git a/vector/BindingTable.h b/logic/BindingTable.h similarity index 100% rename from vector/BindingTable.h rename to logic/BindingTable.h diff --git a/logic/Makefile b/logic/Makefile new file mode 100644 index 0000000..e18ef6c --- /dev/null +++ b/logic/Makefile @@ -0,0 +1,13 @@ +LIBRARY = librrqlogic.a +LIBOBJS += Tuple.o TupleSchema.o Relation.o +LIBOBJS += Binding.o BindingTable.o +LIBOBJS += Query.o +LIBOBJS += AssignQuery.o RelationQuery.o +LIBOBJS += NotQuery.o AndQuery.o OrQuery.o +#LIBOBJS += View.o + +default: $(LIBRARY) + +all: default + +include ../common.mk diff --git a/vector/NotQuery.c b/logic/NotQuery.c similarity index 100% rename from vector/NotQuery.c rename to logic/NotQuery.c diff --git a/vector/NotQuery.h b/logic/NotQuery.h similarity index 100% rename from vector/NotQuery.h rename to logic/NotQuery.h diff --git a/vector/OrQuery.c b/logic/OrQuery.c similarity index 100% rename from vector/OrQuery.c rename to logic/OrQuery.c diff --git a/vector/OrQuery.h b/logic/OrQuery.h similarity index 100% rename from vector/OrQuery.h rename to logic/OrQuery.h diff --git a/vector/Query.c b/logic/Query.c similarity index 100% rename from vector/Query.c rename to logic/Query.c diff --git a/vector/Query.h b/logic/Query.h similarity index 100% rename from vector/Query.h rename to logic/Query.h diff --git a/vector/QueryCallbacks.h b/logic/QueryCallbacks.h similarity index 100% rename from vector/QueryCallbacks.h rename to logic/QueryCallbacks.h diff --git a/vector/Relation.c b/logic/Relation.c similarity index 100% rename from vector/Relation.c rename to logic/Relation.c diff --git a/vector/Relation.h b/logic/Relation.h similarity index 100% rename from vector/Relation.h rename to logic/Relation.h diff --git a/vector/RelationQuery.c b/logic/RelationQuery.c similarity index 100% rename from vector/RelationQuery.c rename to logic/RelationQuery.c diff --git a/vector/RelationQuery.h b/logic/RelationQuery.h similarity index 100% rename from vector/RelationQuery.h rename to logic/RelationQuery.h diff --git a/vector/Tuple.c b/logic/Tuple.c similarity index 100% rename from vector/Tuple.c rename to logic/Tuple.c diff --git a/vector/Tuple.h b/logic/Tuple.h similarity index 100% rename from vector/Tuple.h rename to logic/Tuple.h diff --git a/vector/TupleSchema.c b/logic/TupleSchema.c similarity index 100% rename from vector/TupleSchema.c rename to logic/TupleSchema.c diff --git a/vector/TupleSchema.h b/logic/TupleSchema.h similarity index 96% rename from vector/TupleSchema.h rename to logic/TupleSchema.h index 7bfb67d..664ddad 100644 --- a/vector/TupleSchema.h +++ b/logic/TupleSchema.h @@ -78,7 +78,7 @@ extern int TupleSchema_match(TupleSchema *def,Tuple *query,Tuple *item); * \related TupleSchema */ #define TUPLESCHEMA(...) \ - TupleSchema_create( NUMARGS( __VA_ARGS__ ), TUPLE( __VA_ARGS__ ) ) + TupleSchema_create( TUPLE( __VA_ARGS__ ) ) #endif diff --git a/socket-sniff/Makefile b/socket-sniff/Makefile index d9d783f..e86108f 100644 --- a/socket-sniff/Makefile +++ b/socket-sniff/Makefile @@ -1,7 +1,11 @@ default: socket-sniff -CFLAGS = -Wall -I../vector -g -fmax-errors=1 -LDLIBS = -L../vector -lvector +RRQLIBS = typing vector +INCDIRS = $(addprefix -I../,$(RRQLIBS)) + +CFLAGS = -Wall $(INCDIRS) +CFLAGS += -g -fmax-errors=1 +LDLIBS = -L../vector -lvector -lm .INTERMEDIATE: socket-sniff.o diff --git a/socket-sniff/socket-sniff.c b/socket-sniff/socket-sniff.c index 545c9f7..4bcc8a2 100644 --- a/socket-sniff/socket-sniff.c +++ b/socket-sniff/socket-sniff.c @@ -12,7 +12,8 @@ #include #include -#include +#include +#include // Seconds between outputs static int DELAY = 5; @@ -47,29 +48,41 @@ static void die(char *m) { exit( 1 ); } -// Return pointer to the key for an item -static void *Countp_itemkey(void *item) { +// Returns the hashcode for a key +static unsigned long Countp_hashcode(void *this,void *key) { + return HashVector_hashcode( key, IPBUFMAX ); +} + +// Return pointer a key for an item (could be temporary allocation) +static void *Countp_itemkey(void *this,void *item) { return ((Count*) item)->ip; } // Return 1 if the item has the key, or 0 otherwise. -static int Countp_haskey(void *item,void *key) { - return memcmp( key, Countp_itemkey( item ), IPBUFMAX ) == 0; +static int Countp_haskey(void *this,void *item,void *key) { + return memcmp( key, Countp_itemkey( this, item ), IPBUFMAX ) == 0; } -// Returns the hashcode for a key -static unsigned long Countp_hashcode(void *key) { - return hashvector_hashcode( key, IPBUFMAX ); +#if 0 +// Releasing a key does nothing +static void Countp_releasekey(void *this,void *item) { } +#endif -// The hashvector of seen IP -static hashvector TBL = { - .table = { VECTOR_SLOTS, 0 }, +static ItemKeyFun Countp_itemkeyfun = { + .hashcode = Countp_hashcode, + .haskey = Countp_haskey, + .itemkey = Countp_itemkey, + //.releasekey = Countp_releasekey, + //.tostring = Countp_tostring +}; + +// The HashVector of seen IP +static HashVector TBL = { + .table = { Nibble_index_levels, 16, 0 }, .fill = 0, .holes = 0, - .keyhashcode = Countp_hashcode, - .itemkey = Countp_itemkey, - .haskey = Countp_haskey + .type = &Countp_itemkeyfun, }; // The Count records in time order @@ -84,28 +97,28 @@ static char buffer[ IPBUFMAX ]; /*============================================================ * Reading ignore lines. */ +#if 0 // Return pointer to the key for an item -static void *charp_itemkey(void *item) { +static void *charp_itemkey(void *this,void *item) { return item; } // Return 1 if the item has the key, or 0 otherwise. -static int charp_haskey(void *item,void *key) { +static int charp_haskey(void *this,void *item,void *key) { return strcmp( key, item ) == 0; } // Returns the hashcode for a key -static unsigned long charp_hashcode(void *key) { - return hashvector_hashcode( key, strlen( (const char *) key ) ); +static unsigned long charp_hashcode(void *this,void *key) { + return HashVector_hashcode( key, strlen( (const char *) key ) ); } +#endif -static hashvector IGN = { +static HashVector IGN = { .table = { 256, 0 }, .fill = 0, .holes = 0, - .keyhashcode = charp_hashcode, - .itemkey = charp_itemkey, - .haskey = charp_haskey + .type = &stringitem }; static void read_ignore_file(char *filename) { @@ -144,7 +157,7 @@ static void read_ignore_file(char *filename) { char *ip = calloc( 1, p - cur + 1 ); memcpy( ip, cur, p - cur ); cur = p + 1; - hashvector_add( &IGN, ip ); + HashVector_add( &IGN, ip ); } } @@ -166,7 +179,7 @@ static int Countp_compare(const void *ax, const void *bx) { return a->last - b->last; } -static int Countp_fade_and_print(unsigned long index,void *x,void *d) { +static int Countp_fade_and_print(VectorIndex index,void *x,void *d) { if ( x ) { Count *item = (Count *) x; item->last = item->accum; @@ -182,7 +195,7 @@ static int Countp_fade_and_print(unsigned long index,void *x,void *d) { return 0; } -static int Countp_reclaim(vector *pv,unsigned long ix,void *item,void *data) { +static int Countp_reclaim(Vector *pv,unsigned long ix,void *item,void *data) { return 0; } @@ -190,21 +203,21 @@ static int Countp_reclaim(vector *pv,unsigned long ix,void *item,void *data) { // ip points to [ IPBUFMAX ] of ip address in text static void add_show_table(char *ip,size_t length) { static time_t show = 0; - Count *item; - int i = hashvector_find( &TBL, ip, (void**) &item ); + Count *item = HashVector_find( &TBL, ip ); struct timeval now; if ( gettimeofday( &now, 0 ) ) { perror( "gettimeofday" ); exit( 1 ); } - if ( i == 0 ) { + if ( item == 0 ) { item = (Count *) calloc( 1, sizeof( Count ) ); memcpy( item->ip, ip, strlen( ip ) ); - hashvector_add( &TBL, item ); - item->ignore = hashvector_find( &IGN, ip, 0 ); + HashVector_add( &TBL, item ); + item->ignore = (HashVector_find( &IGN, ip ) != 0); + int i; for ( i = strlen( ip )-1; i > 1; i-- ) { if ( ip[i] == '.' || ip[i] == ':' ) { - item->ignore |= hashvector_find( &IGN, ip, 0 ); + item->ignore |= (HashVector_find( &IGN, ip ) != 0); } ip[i] = 0; } @@ -243,7 +256,7 @@ static void add_show_table(char *ip,size_t length) { trail.head->prev = 0; } fprintf( stdout, "drop %s\n", old->ip ); - hashvector_delete( &TBL, old ); + HashVector_delete( &TBL, old ); free( old ); } if ( now.tv_sec < show ) { @@ -253,11 +266,11 @@ static void add_show_table(char *ip,size_t length) { show = now.tv_sec; } show += DELAY; // Time for next output - vector ordered = { 0, 0 }; - hashvector_contents( &TBL, &ordered ); - vector_qsort( &ordered, Countp_compare ); - vector_iterate( &ordered, Countp_fade_and_print, 0 ); - vector_resize( &ordered, 0, Countp_reclaim, 0 ); + Vector ordered = { Nibble_index_levels, 0, 0 }; + HashVector_contents( &TBL, Nibble_index_levels, &ordered ); + Vector_qsort( &ordered, Countp_compare ); + Vector_iterate( &ordered, 0, Countp_fade_and_print, 0 ); + Vector_resize( &ordered, 0, Countp_reclaim, 0 ); fprintf( stdout, "==%ld/%ld/%ld\n", TBL.fill, TBL.holes, TBL.table.size ); } diff --git a/tests/Makefile b/tests/Makefile index 6da4dd7..ab5fcc2 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -4,7 +4,11 @@ BIN = ${SRC:.c=} default: ${BIN} -CFLAGS = -Wall -I../vector -g -fmax-errors=1 +RRQLIBS = typing vector logic +INCDIRS = $(addprefix -I../,$(RRQLIBS)) + +CFLAGS = -Wall $(INCDIRS) +CFLAGS += -g -fmax-errors=1 LDLIBS = -L../vector -lvector -lm .INTERMEDIATE: ${OBJ} diff --git a/tests/example-relation.c b/tests/example-relation.c index 73b0dc0..a70714c 100644 --- a/tests/example-relation.c +++ b/tests/example-relation.c @@ -53,7 +53,7 @@ typedef union { int main(int argc,char **argv) { Relation *rltn2 = Relation_create( TupleSchema_create( - 2, Tuple_create( 2, (void*) &stringitem, (void*) &stringitem ) ) ); + Tuple_create( 2, (void*) &stringitem, (void*) &stringitem ) ) ); Relation_add_constraint( rltn2, 0, 1 ); add_Relation( rltn2, "benton", "holly" ); add_Relation( rltn2, "benton", "molly"); diff --git a/typing/ItemKeyFun.c b/typing/ItemKeyFun.c new file mode 100644 index 0000000..81e4b9a --- /dev/null +++ b/typing/ItemKeyFun.c @@ -0,0 +1,67 @@ +/** + * Trampoline functions for the ItemKeyFun callbacks. + */ + +#include +#include + +/** + * \brief Trampoline function for the ItemKeyFun.hashcode callback. + * + * The default is to use the pointer itself. + */ +unsigned long ItemKeyFun_hashcode(void *this,void *key) { + ItemKeyFun *type = (ItemKeyFun*) this; + assert( type ); + return type->hashcode? type->hashcode( type, key ) : (unsigned long) key; +} + +/** + * \brief Trampoline function for the ItemKeyFun.itemkey callback. + */ +void *ItemKeyFun_itemkey(void *this,void *item) { + ItemKeyFun *type = (ItemKeyFun*) this; + assert( type ); + return type->itemkey? type->itemkey( type, item ) : item; +} + +/** + * \brief Trampoline function for the ItemKeyFun.haskey callback. + */ +int ItemKeyFun_haskey(void *this,void *item,void *key) { + ItemKeyFun *type = (ItemKeyFun*) this; + assert( type ); + if ( type->haskey ) { + return type->haskey( this, item, key ); + } + void *ikey = ItemKeyFun_itemkey( this, item ); + int n = ikey == key; + ItemKeyFun_releasekey( this, ikey ); + return n; +} + +/** + * \brief Trampoline function for the ItemKeyFun.releasekey callback. + */ +void ItemKeyFun_releasekey(void *this,void *key) { + ItemKeyFun *type = (ItemKeyFun*) this; + assert( type ); + if ( type->releasekey ) { + type->releasekey( type, key ); + } +} + +/** + * \brief Trampoline function for the ItemKeyFun.tostring callback. + */ +int ItemKeyFun_tostring(void *this,void *item,char *buffer,int limit) { + ItemKeyFun *type = (ItemKeyFun*) this; + assert( type ); + if ( type->tostring ) { + return type->tostring( type, item, buffer, limit ); + } + void *key = ItemKeyFun_itemkey( this, item ); + int n = snprintf( buffer, limit, "{%p/%p@%p}", type, key, item ); + ItemKeyFun_releasekey( this, key ); + return n; +} diff --git a/vector/ItemKeyFun.h b/typing/ItemKeyFun.h similarity index 63% rename from vector/ItemKeyFun.h rename to typing/ItemKeyFun.h index 93c0200..8a83f9b 100644 --- a/vector/ItemKeyFun.h +++ b/typing/ItemKeyFun.h @@ -17,7 +17,6 @@ */ typedef struct { -#define SELF void *this /** * This callback function should return the hashcode of a key. The * hashcode is used for indexing into the backing Vector for @@ -27,13 +26,13 @@ typedef struct { * hashcode, in which case the Vector placement is made at the * first empty or hole slot following the hashcode index. */ - unsigned long (*hashcode)(SELF,void *key); + unsigned long (*hashcode)(void *this,void *key); /** * This callback function should determine whether an item has a * given key or not. */ - int (*haskey)(SELF,void *item,void *key); + int (*haskey)(void *this,void *item,void *key); /** * This callback function should return a (possibly temporary) key @@ -42,21 +41,47 @@ typedef struct { * callbacks recognize. It is merely understood as a value in an * identity domain. */ - void *(*itemkey)(SELF,void *item); + void *(*itemkey)(void *this,void *item); /** * This callback function should handle a key obtained from the * itemkey callback function, e.g., reclaim temporary allocation. */ - void (*releasekey)(SELF,void *key); + void (*releasekey)(void *this,void *key); /** * This callback function writes a representation of an item into * a character buffer. */ - int (*tostring)(SELF,void *item,char *buffer,int limit); + int (*tostring)(void *this,void *item,char *buffer,int limit); -#undef SELF } ItemKeyFun; +/** + * \brief Trampoline function for the ItemKeyFun.hashcode callback. + * + * The default is to use the pointer itself. + */ +extern unsigned long ItemKeyFun_hashcode(void *this,void *key); + +/** + * \brief Trampoline function for the ItemKeyFun.haskey callback. + */ +extern int ItemKeyFun_haskey(void *this,void *item,void *key); + +/** + * \brief Trampoline function for the ItemKeyFun.itemkey callback. + */ +extern void *ItemKeyFun_itemkey(void *this,void *item); + +/** + * \brief Trampoline function for the ItemKeyFun.releasekey callback. + */ +extern void ItemKeyFun_releasekey(void *this,void *key); + +/** + * \brief Trampoline function for the ItemKeyFun.tostring callback. + */ +extern int ItemKeyFun_tostring(void *this,void *item,char *buffer,int limit); + #endif diff --git a/typing/Makefile b/typing/Makefile new file mode 100644 index 0000000..91272e5 --- /dev/null +++ b/typing/Makefile @@ -0,0 +1,8 @@ +LIBRARY = librrqtyping.a +LIBOBJS += ItemKeyFun.o integeritem.o stringitem.o + +default: $(LIBRARY) + +all: default + +include ../common.mk diff --git a/vector/integeritem.c b/typing/integeritem.c similarity index 100% rename from vector/integeritem.c rename to typing/integeritem.c diff --git a/vector/integeritem.h b/typing/integeritem.h similarity index 100% rename from vector/integeritem.h rename to typing/integeritem.h diff --git a/vector/stringitem.c b/typing/stringitem.c similarity index 100% rename from vector/stringitem.c rename to typing/stringitem.c diff --git a/vector/stringitem.h b/typing/stringitem.h similarity index 100% rename from vector/stringitem.h rename to typing/stringitem.h diff --git a/vector/HashVector.c b/vector/HashVector.c index ec0e0b4..a07a916 100644 --- a/vector/HashVector.c +++ b/vector/HashVector.c @@ -1,8 +1,6 @@ #include #include -#define SELF hv->type - // Find the slot for the keyed element, and return pointer to it, or // to the first of holes encountered while considering collisions. // Returns a pointer to the place for the item, or 0 in case of OOM or @@ -14,9 +12,9 @@ static void **HashVector_find_slot( { if ( itemkey ) { // Get actual key from keying item - key = hv->type->itemkey( SELF, key ); + key = ItemKeyFun_itemkey( hv->type, key ); } - unsigned long index = hv->type->hashcode( SELF, key ) % hv->table.size; + unsigned long index = ItemKeyFun_hashcode( hv->type, key ) % hv->table.size; *i = index; void **hole = 0; void **p = 0; @@ -24,13 +22,13 @@ static void **HashVector_find_slot( p = Vector_entry( &hv->table, (*i) ); if ( p == 0 ) { if ( itemkey ) { - hv->type->releasekey( SELF, key ); + ItemKeyFun_releasekey( hv->type, key ); } return 0; // This basically means OOM, and is a failure condition. } if ( (*p) == 0 ) { if ( itemkey ) { - hv->type->releasekey( SELF, key ); + ItemKeyFun_releasekey( hv->type, key ); } return ( hole )? hole : p; // Not found; it's place is here. } @@ -38,9 +36,9 @@ static void **HashVector_find_slot( if ( hole == 0 ) { hole = p; // Remember the first hole } - } else if ( hv->type->haskey( SELF, (*p), key ) ) { + } else if ( ItemKeyFun_haskey( hv->type, (*p), key ) ) { if ( itemkey ) { - hv->type->releasekey( SELF, key ); + ItemKeyFun_releasekey( hv->type, key ); } return p; // Found } @@ -49,7 +47,7 @@ static void **HashVector_find_slot( } if ( (*i) == index ) { if ( itemkey ) { - hv->type->releasekey( SELF, key ); + ItemKeyFun_releasekey( hv->type, key ); } return 0; // Overfull HashVector! } diff --git a/vector/Makefile b/vector/Makefile index a3feec4..ea8e8de 100644 --- a/vector/Makefile +++ b/vector/Makefile @@ -1,34 +1,7 @@ -LIBRARY = libvector.a +LIBRARY = librrqvector.a LIBOBJS = Vector.o HashVector.o -LIBOBJS += Tuple.o TupleSchema.o integeritem.o stringitem.o Binding.o -LIBOBJS += BindingTable.o Relation.o Query.o -LIBOBJS += AssignQuery.o RelationQuery.o -LIBOBJS += NotQuery.o AndQuery.o OrQuery.o -#LIBOBJS += View.o default: $(LIBRARY) - -all: default - -CFLAGS = -Wall -g -fmax-errors=1 -I. -LDLIBS = -lm - -%.h: - echo "#ifndef ${@:.h=_H}" > $@ - echo "#define ${@:.h=_H}" >> $@ - echo "#endif" >> $@ - -define STDCC -.INTERMEDIATE: $1.o -CLEANRM += $1.o -$1.o: $1.c | $1.h -endef - -$(foreach OBJ,$(LIBOBJS:.o=),$(eval $(call STDCC,$(OBJ)))) - CLEANRM += $(LIBRARY) -$(LIBRARY): $(LIBOBJS) - $(AR) r $@ $^ -clean: - rm -f $(CLEANRM) +include ../common.mk diff --git a/vector/mainpage.dox b/vector/mainpage.dox deleted file mode 100644 index 2a4c45e..0000000 --- a/vector/mainpage.dox +++ /dev/null @@ -1,46 +0,0 @@ -/** \mainpage rrq C hacks: Vectors And Such - -This software is an implementation platform for vector based -representations. - -- \ref itemkeyfun is an implementation of an abstracted type notion - that is focussed on what the \ref hashvector needs in terms of - callbacks for its separation between the hash management - functionality and the contained items. This name is choosen so as to - avoid some connotations common to the term "type". - -- \ref array and \ref vector are two implementations of an abstract - array notion using an indexing tree of 16 and 256 pointers - respectively. The indexing tree is balanced into levels matching to - the needs of the vector size. When the size of a vector is changed - then indexing levels are added or removed as needed. However - indexing pages are allocated on a needs basis. The level 0 indexing - pages hold the actual data as void* pointers - -- \ref hasharray and \ref hashvector are two implementations of an - abstract hashtable using \ref array and \ref vector as backing store - respectively. It also uses the \ref itemkeyfn type abstraction of - items being compunded as pairs of key and payload. This separates - the hashing code from the type abstraction. - -\subsubsection s0 itemkeyfun actualizations - -- \ref integeritem is an plain actualization of an itemkeyfun record - for integer items other than 0 and 1, i.e. where the void* slots of - a tuple are reinterpreted as 64-bit integers rather than "item - pointers". - -\note Note that a hashvector cannot directly contain integer items - since 0 and 1 are treated as indicating unused and holed slots. - -- stringitem is a plain actualization of an itemkeyfun record for - null-terminated character strings. - -- tupleschema is a specialization of the itemkeyfun type scheme - intended for tuple items that are arrays of items that are further - type via itemkeyfun records. A tupleschema actualization includes - the applicable arity and an array of pointers to itemkeyfun - actualizations that declare the itemkeyfun types of the parts - (columns). - -*/ -- 2.39.2