From fff7d7c2ac83984bd2fc7ec3c72dc455c7c72807 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Tue, 5 Jul 2022 21:54:30 +1000 Subject: [PATCH] Add hashvector_create + some polishing --- vector/hashvector.c | 19 ++++++++++++++++++- vector/hashvector.h | 15 ++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/vector/hashvector.c b/vector/hashvector.c index 0f5b31f..c261253 100644 --- a/vector/hashvector.c +++ b/vector/hashvector.c @@ -1,4 +1,5 @@ -#include "hashvector.h" +#include +#include #define SELF hv->type @@ -174,3 +175,19 @@ unsigned long hashvector_hashcode(unsigned char *key,unsigned long n) { return value; } + +hashvector *hashvector_create(int variant,itemkeyfun *type) { + hashvector *hv = (hashvector*) malloc( sizeof( hashvector ) ); + (*hv) = (hashvector) { + .table = (vector) { + .variant = variant, + .size = 0, + .entries = 0 + }, + .fill = 0, + .holes = 0, + .type = type + }; + return hv; +} + diff --git a/vector/hashvector.h b/vector/hashvector.h index d0f9e12..1c3f387 100644 --- a/vector/hashvector.h +++ b/vector/hashvector.h @@ -77,7 +77,7 @@ typedef struct { * * \related hashvector */ -int hashvector_find(hashvector *hv,void *key,void **x); +extern int hashvector_find(hashvector *hv,void *key,void **x); /** * Add the given item into the hashvector, growing the hashvector as @@ -89,7 +89,7 @@ int hashvector_find(hashvector *hv,void *key,void **x); * * \related hashvector */ -int hashvector_add(hashvector *hv,void *item); +extern int hashvector_add(hashvector *hv,void *item); /** * Delete the given item, and shrink the hashvector so that its size @@ -100,7 +100,7 @@ int hashvector_add(hashvector *hv,void *item); * * \related hashvector */ -int hashvector_delete(hashvector *hv,void *item); +extern int hashvector_delete(hashvector *hv,void *item); /** * Copy content items into a vector, which must be empty. The @@ -111,7 +111,7 @@ int hashvector_delete(hashvector *hv,void *item); * * \related hashvector */ -int hashvector_contents(hashvector *hv,vector *pv); +extern int hashvector_contents(hashvector *hv,vector *pv); /** * This is a utility function to compute and return a hashcode for a @@ -119,6 +119,11 @@ int hashvector_contents(hashvector *hv,vector *pv); * * \related hashvector */ -unsigned long hashvector_hashcode(unsigned char *key,unsigned long n); +extern unsigned long hashvector_hashcode(unsigned char *key,unsigned long n); + +/** + * Create a hashvector for of given variant for given itemkeyfun* + */ +extern hashvector *hashvector_create(int variant,itemkeyfun *type); #endif -- 2.39.2