Skip to content
Myr

stb_ds: move temp_key added by PR into hash_table structure instead of main header struct

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 ef23148 · Browse files · 1 file+4 added−3 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+4 added−3 removed

  • other:+4 added−3 removed

1 file+4 added−3 removed

modified:stb_ds.h+4 added-3 removed
376 unmodified lines
377 Shane Liesegang378 Vinh Truong379 Andreas Molzer380 github:hashitaku381 github:srdjanstipic382*/383384#ifdef STBDS_UNIT_TESTS385#define _CRT_SECURE_NO_WARNINGS
142 unmodified lines
528#define STBDS_OFFSETOF(var,field) ((char *) &(var)->field - (char *) (var))529530#define stbds_header(t) ((stbds_array_header *) (t) - 1)531#define stbds_temp(t) stbds_header(t)->temp531#define stbds_temp_key(t) stbds_header(t)->temp_key532#define stbds_temp_key(t) (*(char **) stbds_header(t)->hash_table)533534#define stbds_arrsetcap(a,n) (stbds_arrgrow(a,0,n))535#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)536#define stbds_arrcap(a) ((a) ? stbds_header(a)->capacity : 0)
70 unmodified lines
607608#define stbds_shputs(t, s) \609 ((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void*) (s).key, sizeof (s).key, STBDS_HM_STRING), \610 (t)[stbds_temp((t)-1)] = (s), \610 (t)[stbds_temp((t)-1)].key = stbds_temp_key((t)-1))611 (t)[stbds_temp((t)-1)].key = stbds_temp_key((t)-1)) // above line overwrites whole structure, so must rewrite key here if it was allocated internally612613#define stbds_pshput(t, p) \614 ((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void*) (p)->key, sizeof (p)->key, STBDS_HM_PTR_TO_STRING), \615 (t)[stbds_temp((t)-1)] = (p))
38 unmodified lines
654 size_t length;655 size_t capacity;656 void * hash_table;657 ptrdiff_t temp;657 char * temp_key;658} stbds_array_header;659660typedef struct stbds_string_block661{
150 unmodified lines
812} stbds_hash_bucket; // in 32-bit, this is one 64-byte cache line; in 64-bit, each array is one 64-byte cache line813814typedef struct815{816 char * temp_key; // this MUST be the first field of the hash table817 size_t slot_count;818 size_t used_count;819 size_t used_count_threshold;820 size_t used_count_shrink_threshold;
1060 unmodified lines