stb_ds: fix arrisn, shgetp_null
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sean Barrett · committed by Sean Barrett · parent c9064e3 · Browse files · 3 files·+11 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+11 added−5 removed
- tests:+4 added−1 removed
- other:+7 added−4 removed
Provenance
- Commit
781609b- Tree
dad752e- Author
Sean Barrett <seanb@radgametools.com>- Committer
Sean Barrett <seanb@radgametools.com>- Parent
c9064e3
3 files changed+11 added−5 removed
modified:tests/stb.dsp+1 added-1 removed
64 unmodified lines65 # PROP Intermediate_Dir "Debug\stb"66 # PROP Ignore_Export_Lib 067 # PROP Target_Dir ""68 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c69-# ADD CPP /nologo /MTd /W3 /GX /Zi /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "TT_TEST" /FR /FD /GZ /c69+# ADD CPP /nologo /MTd /W3 /GX /Zi /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "DS_TEST" /FR /FD /GZ /c70 # SUBTRACT CPP /YX71 # ADD BASE RSC /l 0x409 /d "_DEBUG"72 # ADD RSC /l 0x409 /d "_DEBUG"73 BSC32=bscmake.exe179 unmodified linesmodified:tests/test_ds.c+3 added
62 unmodified lines63 #ifdef DS_TEST64 #include <stdio.h>65 int main(int argc, char **argv)66 {67+ char *temp=NULL;68 stbds_unit_tests();69+ arrins(temp, 0, 'a');70+ arrins(temp, arrlen(temp), 'b');71 churn(0,100,1);72 churn(3,7,50000);73 churn(3,15,50000);74 churn(16, 48, 25000);960 unmodified linesmodified:stb_ds.h+7 added-4 removed
545 unmodified lines546 #define stbds_arrfree(a) ((void) ((a) ? STBDS_FREE(NULL,stbds_header(a)) : (void)0), (a)=NULL)547 #define stbds_arrdel(a,i) stbds_arrdeln(a,i,1)548 #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))549 #define stbds_arrdelswap(a,i) ((a)[i] = stbds_arrlast(a), stbds_header(a)->length -= 1)550-#define stbds_arrinsn(a,i,n) (stbds_arraddn((a),(n)), memmove(&(a)[(i)+(n)], &(a)[i], sizeof *(a) * (stbds_header(a)->length-(n)-(i))))550+#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))))551 #define stbds_arrins(a,i,v) (stbds_arrinsn((a),(i),1), (a)[i]=(v))552 553 #define stbds_arrmaybegrow(a,n) ((!(a) || stbds_header(a)->length + (n) > stbds_header(a)->capacity) \554 ? (stbds_arrgrow(a,n,0),0) : 0)39 unmodified lines594 #define stbds_hmget(t, k) (stbds_hmgetp(t,k)->value)595 #define stbds_hmget_ts(t, k, temp) (stbds_hmgetp_ts(t,k,temp)->value)596 #define stbds_hmlen(t) ((t) ? (ptrdiff_t) stbds_header((t)-1)->length-1 : 0)597 #define stbds_hmlenu(t) ((t) ? stbds_header((t)-1)->length-1 : 0)598-#define stbds_hmgetp_null(t,k) (stbds_hmgeti(t,k) == -1 ? NULL : &(t)[stbds_temp(t)-1])598+#define stbds_hmgetp_null(t,k) (stbds_hmgeti(t,k) == -1 ? NULL : &(t)[stbds_temp((t)-1)])599 600 #define stbds_shput(t, k, v) \601 ((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void*) (k), sizeof (t)->key, STBDS_HM_STRING), \602 (t)[stbds_temp((t)-1)].value = (v))42 unmodified lines645 #define stbds_shlenu stbds_hmlenu646 647 #define stbds_shgets(t, k) (*stbds_shgetp(t,k))648 #define stbds_shget(t, k) (stbds_shgetp(t,k)->value)649-#define stbds_shgetp_null(t,k) (stbds_shgeti(t,k) == -1 ? NULL : &(t)[stbds_temp(t)-1])649+#define stbds_shgetp_null(t,k) (stbds_shgeti(t,k) == -1 ? NULL : &(t)[stbds_temp((t)-1)])650 #define stbds_shlen stbds_hmlen651 652 typedef struct653 {101 unmodified lines755 //int num_prev;756 757 void *stbds_arrgrowf(void *a, size_t elemsize, size_t addlen, size_t min_cap)758 {759+ stbds_array_header temp={0}; // force debugging760 void *b;761 size_t min_len = stbds_arrlen(a) + addlen;762+ (void) sizeof(temp);763 764 // compute the minimum capacity needed765 if (min_len > min_cap)766 min_cap = min_len;15 unmodified lines782 b = (char *) b + sizeof(stbds_array_header);783 if (a == NULL) {784 stbds_header(b)->length = 0;785 stbds_header(b)->hash_table = 0;786+ stbds_header(b)->temp = 0;787 } else {788 STBDS_STATS(++stbds_array_grow);789 }790 stbds_header(b)->capacity = min_cap;570 unmodified lines1361 // we iterate hash table explicitly because we want to track if we saw a tombstone1362 {1363 size_t hash = mode >= STBDS_HM_STRING ? stbds_hash_string((char*)key,table->seed) : stbds_hash_bytes(key, keysize,table->seed);1364 size_t step = STBDS_BUCKET_LENGTH;1362- size_t limit,i;1365 size_t pos;1366 ptrdiff_t tombstone = -1;1367 stbds_hash_bucket *bucket;1368 2 unmodified lines1371 1372 pos = stbds_probe_position(hash, table->slot_count, table->slot_count_log2);1373 1374 for (;;) {1375+ size_t limit, i;1376 STBDS_STATS(++stbds_hash_probes);1377 bucket = &table->storage[pos >> STBDS_BUCKET_SHIFT];1378 1379 // start searching from pos to end of bucket504 unmodified lines