Skip to content
Myr

Merge branch 'master' of https://github.com/srdjanstipic/stb into working

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 · parents 580fc1a, 1e400e2 · Browse files · 1 file+37 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

1 file+37 added−5 removed

  • other:+37 added−5 removed

1 file+37 added−5 removed

modified:stb_ds.h+37 added-5 removed
526 unmodified lines
527#define STBDS_OFFSETOF(var,field) ((char *) &(var)->field - (char *) (var))528529#define stbds_header(t) ((stbds_array_header *) (t) - 1)530#define stbds_temp(t) stbds_header(t)->temp531#define stbds_temp_key(t) stbds_header(t)->temp_key532533#define stbds_arrsetcap(a,n) (stbds_arrgrow(a,0,n))534#define stbds_arrsetlen(a,n) ((stbds_arrcap(a) < (size_t) (n) ? stbds_arrsetcap((a),(size_t)(n)),0 : 0), (a) ? stbds_header(a)->length = (size_t) (n) : 0)535#define stbds_arrcap(a) ((a) ? stbds_header(a)->capacity : 0)
69 unmodified lines
605 (t)[stbds_temp((t)-1)].value = (v), stbds_temp((t)-1))606607#define stbds_shputs(t, s) \608 ((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void*) (s).key, sizeof (s).key, STBDS_HM_STRING), \608 (t)[stbds_temp((t)-1)] = (s))609 (t)[stbds_temp((t)-1)] = (s), \610 (t)[stbds_temp((t)-1)].key = stbds_temp_key((t)-1))611612#define stbds_pshput(t, p) \613 ((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void*) (p)->key, sizeof (p)->key, STBDS_HM_PTR_TO_STRING), \614 (t)[stbds_temp((t)-1)] = (p))
38 unmodified lines
653 size_t length;654 size_t capacity;655 void * hash_table;656 ptrdiff_t temp;657 char * temp_key;658} stbds_array_header;659660typedef struct stbds_string_block661{
769 unmodified lines
1431 bucket->index[pos & STBDS_BUCKET_MASK] = i-1;1432 stbds_temp(a) = i-1;14331434 switch (table->string.mode) {1432 case STBDS_SH_STRDUP: *(char **) ((char *) a + elemsize*i) = stbds_strdup((char*) key); break;1433 case STBDS_SH_ARENA: *(char **) ((char *) a + elemsize*i) = stbds_stralloc(&table->string, (char*)key); break;1434 case STBDS_SH_DEFAULT: *(char **) ((char *) a + elemsize*i) = (char *) key; break;1435 case STBDS_SH_STRDUP: stbds_temp_key(a) = *(char **) ((char *) a + elemsize*i) = stbds_strdup((char*) key); break;1436 case STBDS_SH_ARENA: stbds_temp_key(a) = *(char **) ((char *) a + elemsize*i) = stbds_stralloc(&table->string, (char*)key); break;1437 case STBDS_SH_DEFAULT: stbds_temp_key(a) = *(char **) ((char *) a + elemsize*i) = (char *) key; break;1438 default: memcpy((char *) a + elemsize*i, key, keysize); break;1439 }1440 }1441 return STBDS_ARR_TO_HASH(a,elemsize);
196 unmodified lines
1638 const int testsize = 100000;1639 const int testsize2 = testsize/20;1640 int *arr=NULL;1641 struct { int key; int value; } *intmap = NULL;1639 struct { char *key; int value; } *strmap = NULL;1642 struct { char *key; int value; } *strmap = NULL, s;1643 struct { stbds_struct key; int value; } *map = NULL;1644 stbds_struct *map2 = NULL;1645 stbds_struct2 *map3 = NULL;1646 stbds_string_arena sa = { 0 };
74 unmodified lines
1721 for (i=0; i < testsize; ++i)1722 stralloc(&sa, strkey(i));1723 strreset(&sa);17241725 {1726 s.key = "a", s.value = 1;1727 shputs(strmap, s);1728 STBDS_ASSERT(*strmap[0].key == 'a');1729 STBDS_ASSERT(strmap[0].key == s.key);1730 STBDS_ASSERT(strmap[0].value == s.value);1731 shfree(strmap);1732 }17331734 {1735 s.key = "a", s.value = 1;1736 sh_new_strdup(strmap);1737 shputs(strmap, s);1738 STBDS_ASSERT(*strmap[0].key == 'a');1739 STBDS_ASSERT(strmap[0].key != s.key);1740 STBDS_ASSERT(strmap[0].value == s.value);1741 shfree(strmap);1742 }17431744 {1745 s.key = "a", s.value = 1;1746 sh_new_arena(strmap);1747 shputs(strmap, s);1748 STBDS_ASSERT(*strmap[0].key == 'a');1749 STBDS_ASSERT(strmap[0].key != s.key);1750 STBDS_ASSERT(strmap[0].value == s.value);1751 shfree(strmap);1752 }17531754 for (j=0; j < 2; ++j) {1755 STBDS_ASSERT(shgeti(strmap,"foo") == -1);1756 if (j == 0)1757 sh_new_strdup(strmap);
122 unmodified lines