stb_ds: fix arrisn, shgetp_null
This commit is contained in:
parent
c9064e3176
commit
781609b7e9
11
stb_ds.h
11
stb_ds.h
@ -547,7 +547,7 @@ extern void * stbds_shmode_func(size_t elemsize, int mode);
|
|||||||
#define stbds_arrdel(a,i) stbds_arrdeln(a,i,1)
|
#define stbds_arrdel(a,i) stbds_arrdeln(a,i,1)
|
||||||
#define stbds_arrdeln(a,i,n) (memmove(&(a)[i], &(a)[(i)+(n)], sizeof *(a) * (stbds_header(a)->length-(n)-(i))), stbds_header(a)->length -= (n))
|
#define stbds_arrdeln(a,i,n) (memmove(&(a)[i], &(a)[(i)+(n)], sizeof *(a) * (stbds_header(a)->length-(n)-(i))), stbds_header(a)->length -= (n))
|
||||||
#define stbds_arrdelswap(a,i) ((a)[i] = stbds_arrlast(a), stbds_header(a)->length -= 1)
|
#define stbds_arrdelswap(a,i) ((a)[i] = stbds_arrlast(a), stbds_header(a)->length -= 1)
|
||||||
#define stbds_arrinsn(a,i,n) (stbds_arraddn((a),(n)), memmove(&(a)[(i)+(n)], &(a)[i], sizeof *(a) * (stbds_header(a)->length-(n)-(i))))
|
#define stbds_arrinsn(a,i,n) ((a)?stbds_temp(a)=(i):0,stbds_arraddn((a),(n)), memmove(&(a)[stbds_temp(a)+(n)], &(a)[stbds_temp(a)], sizeof *(a) * (stbds_header(a)->length-(n)-stbds_temp(a))))
|
||||||
#define stbds_arrins(a,i,v) (stbds_arrinsn((a),(i),1), (a)[i]=(v))
|
#define stbds_arrins(a,i,v) (stbds_arrinsn((a),(i),1), (a)[i]=(v))
|
||||||
|
|
||||||
#define stbds_arrmaybegrow(a,n) ((!(a) || stbds_header(a)->length + (n) > stbds_header(a)->capacity) \
|
#define stbds_arrmaybegrow(a,n) ((!(a) || stbds_header(a)->length + (n) > stbds_header(a)->capacity) \
|
||||||
@ -595,7 +595,7 @@ extern void * stbds_shmode_func(size_t elemsize, int mode);
|
|||||||
#define stbds_hmget_ts(t, k, temp) (stbds_hmgetp_ts(t,k,temp)->value)
|
#define stbds_hmget_ts(t, k, temp) (stbds_hmgetp_ts(t,k,temp)->value)
|
||||||
#define stbds_hmlen(t) ((t) ? (ptrdiff_t) stbds_header((t)-1)->length-1 : 0)
|
#define stbds_hmlen(t) ((t) ? (ptrdiff_t) stbds_header((t)-1)->length-1 : 0)
|
||||||
#define stbds_hmlenu(t) ((t) ? stbds_header((t)-1)->length-1 : 0)
|
#define stbds_hmlenu(t) ((t) ? stbds_header((t)-1)->length-1 : 0)
|
||||||
#define stbds_hmgetp_null(t,k) (stbds_hmgeti(t,k) == -1 ? NULL : &(t)[stbds_temp(t)-1])
|
#define stbds_hmgetp_null(t,k) (stbds_hmgeti(t,k) == -1 ? NULL : &(t)[stbds_temp((t)-1)])
|
||||||
|
|
||||||
#define stbds_shput(t, k, v) \
|
#define stbds_shput(t, k, v) \
|
||||||
((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void*) (k), sizeof (t)->key, STBDS_HM_STRING), \
|
((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void*) (k), sizeof (t)->key, STBDS_HM_STRING), \
|
||||||
@ -646,7 +646,7 @@ extern void * stbds_shmode_func(size_t elemsize, int mode);
|
|||||||
|
|
||||||
#define stbds_shgets(t, k) (*stbds_shgetp(t,k))
|
#define stbds_shgets(t, k) (*stbds_shgetp(t,k))
|
||||||
#define stbds_shget(t, k) (stbds_shgetp(t,k)->value)
|
#define stbds_shget(t, k) (stbds_shgetp(t,k)->value)
|
||||||
#define stbds_shgetp_null(t,k) (stbds_shgeti(t,k) == -1 ? NULL : &(t)[stbds_temp(t)-1])
|
#define stbds_shgetp_null(t,k) (stbds_shgeti(t,k) == -1 ? NULL : &(t)[stbds_temp((t)-1)])
|
||||||
#define stbds_shlen stbds_hmlen
|
#define stbds_shlen stbds_hmlen
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -756,8 +756,10 @@ size_t stbds_rehash_items;
|
|||||||
|
|
||||||
void *stbds_arrgrowf(void *a, size_t elemsize, size_t addlen, size_t min_cap)
|
void *stbds_arrgrowf(void *a, size_t elemsize, size_t addlen, size_t min_cap)
|
||||||
{
|
{
|
||||||
|
stbds_array_header temp={0}; // force debugging
|
||||||
void *b;
|
void *b;
|
||||||
size_t min_len = stbds_arrlen(a) + addlen;
|
size_t min_len = stbds_arrlen(a) + addlen;
|
||||||
|
(void) sizeof(temp);
|
||||||
|
|
||||||
// compute the minimum capacity needed
|
// compute the minimum capacity needed
|
||||||
if (min_len > min_cap)
|
if (min_len > min_cap)
|
||||||
@ -781,6 +783,7 @@ void *stbds_arrgrowf(void *a, size_t elemsize, size_t addlen, size_t min_cap)
|
|||||||
if (a == NULL) {
|
if (a == NULL) {
|
||||||
stbds_header(b)->length = 0;
|
stbds_header(b)->length = 0;
|
||||||
stbds_header(b)->hash_table = 0;
|
stbds_header(b)->hash_table = 0;
|
||||||
|
stbds_header(b)->temp = 0;
|
||||||
} else {
|
} else {
|
||||||
STBDS_STATS(++stbds_array_grow);
|
STBDS_STATS(++stbds_array_grow);
|
||||||
}
|
}
|
||||||
@ -1359,7 +1362,6 @@ void *stbds_hmput_key(void *a, size_t elemsize, void *key, size_t keysize, int m
|
|||||||
{
|
{
|
||||||
size_t hash = mode >= STBDS_HM_STRING ? stbds_hash_string((char*)key,table->seed) : stbds_hash_bytes(key, keysize,table->seed);
|
size_t hash = mode >= STBDS_HM_STRING ? stbds_hash_string((char*)key,table->seed) : stbds_hash_bytes(key, keysize,table->seed);
|
||||||
size_t step = STBDS_BUCKET_LENGTH;
|
size_t step = STBDS_BUCKET_LENGTH;
|
||||||
size_t limit,i;
|
|
||||||
size_t pos;
|
size_t pos;
|
||||||
ptrdiff_t tombstone = -1;
|
ptrdiff_t tombstone = -1;
|
||||||
stbds_hash_bucket *bucket;
|
stbds_hash_bucket *bucket;
|
||||||
@ -1370,6 +1372,7 @@ void *stbds_hmput_key(void *a, size_t elemsize, void *key, size_t keysize, int m
|
|||||||
pos = stbds_probe_position(hash, table->slot_count, table->slot_count_log2);
|
pos = stbds_probe_position(hash, table->slot_count, table->slot_count_log2);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
size_t limit, i;
|
||||||
STBDS_STATS(++stbds_hash_probes);
|
STBDS_STATS(++stbds_hash_probes);
|
||||||
bucket = &table->storage[pos >> STBDS_BUCKET_SHIFT];
|
bucket = &table->storage[pos >> STBDS_BUCKET_SHIFT];
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ LINK32=link.exe
|
|||||||
# PROP Ignore_Export_Lib 0
|
# PROP Ignore_Export_Lib 0
|
||||||
# PROP Target_Dir ""
|
# PROP Target_Dir ""
|
||||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
# ADD CPP /nologo /MTd /W3 /GX /Zi /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "TT_TEST" /FR /FD /GZ /c
|
# ADD CPP /nologo /MTd /W3 /GX /Zi /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "DS_TEST" /FR /FD /GZ /c
|
||||||
# SUBTRACT CPP /YX
|
# SUBTRACT CPP /YX
|
||||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||||
|
@ -64,7 +64,10 @@ void churn(int a, int b, int count)
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
char *temp=NULL;
|
||||||
stbds_unit_tests();
|
stbds_unit_tests();
|
||||||
|
arrins(temp, 0, 'a');
|
||||||
|
arrins(temp, arrlen(temp), 'b');
|
||||||
churn(0,100,1);
|
churn(0,100,1);
|
||||||
churn(3,7,50000);
|
churn(3,7,50000);
|
||||||
churn(3,15,50000);
|
churn(3,15,50000);
|
||||||
|
Loading…
Reference in New Issue
Block a user