medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 32583202329b1d8972035584e5973b794faa56f6
parent 3b786fb1d3d07fc3b58f67b0662b842a10a1bebd
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Tue Sep  6 18:08:29 -0700

Add slots_required intrinsic

Diffstat:
hashtable.h | 7+++----
intrinsics.h | 4++++
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/hashtable.h b/hashtable.h @@ -99,11 +99,10 @@ private: * states is a bitfield with 2 bits per slot. the 2 bits are used to * hold one of 3 possible states: EMPTY, OCCUPIED and DELETED * - * we want to round 2 * N up to the next multiple of 8, then divide by - * 8 to get the number of bytes required. the form below is simplified - * so it doesn't overflow + * we want to round 2 * N up to the next multiple of 8, which is the + * same as rounding N up to the next multiple of 4 but avoids overflow */ - u8 states[ N / 4 + int( N % 4 != 0 ) ]; + u8 states[ slots_required( N, 4 ) ]; u64 keys[ N ]; u64 values[ N ]; }; diff --git a/intrinsics.h b/intrinsics.h @@ -83,6 +83,10 @@ T clamp11( T x ) { return clamp( x, T( -1 ), T( 1 ) ); } +inline constexpr size_t slots_required( size_t data_size, size_t slot_size ) { + return data_size / slot_size + ( data_size % slot_size != 0 ); +} + #include "platform_backtrace.h" #if defined( assert )