rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit 3218162ed6a43570f9cfb80281018f2f68b5af4e
parent b84c143526658c6bff97daec5dae1f3edc08cf40
Author: vaplv <vaplv@free.fr>
Date:   Tue, 22 Apr 2014 11:10:23 +0200

Refactor some math.h functions

- Rename the min/max macro in RMIN/RMAX
- Transform the is_power_of_2 function in the IS_POWER_OF_2 macro

Diffstat:
Msrc/hash_table.h | 4++--
Msrc/math.h | 11+++--------
Msrc/mem_allocator.c | 2--
3 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/src/hash_table.h b/src/hash_table.h @@ -235,7 +235,7 @@ HTABLE_FUNC__(find_slot__)(const struct HTABLE__* htbl, HTABLE_KEY const* key) const char* used_pairs = NULL; ASSERT(htbl && key); /* The tbl size must be a pow of 2 */ - ASSERT(is_power_of_2(HTABLE_DATA_FUNC__(size_get)(&htbl->table))); + ASSERT(IS_POWER_OF_2(HTABLE_DATA_FUNC__(size_get)(&htbl->table))); /* The tbl is not full */ ASSERT(htbl->table_size_in_use < HTABLE_DATA_FUNC__(size_get)(&htbl->table)); @@ -424,7 +424,7 @@ HTABLE_FUNC__(erase)(struct HTABLE__* htbl, HTABLE_KEY const* key) pairs = HTABLE_DATA_FUNC__(data_get)(&htbl->table); tbl_size = HTABLE_DATA_FUNC__(size_get)(&htbl->table); - ASSERT(is_power_of_2(tbl_size)); + ASSERT(IS_POWER_OF_2(tbl_size)); used_pairs = darray_char_data_get(&htbl->table_slot_is_used); i = HTABLE_FUNC__(find_slot__)(htbl, key); diff --git a/src/math.h b/src/math.h @@ -3,14 +3,9 @@ #include "rsys.h" -#define max(A, B) ((A) > (B) ? (A) : (B)) -#define min(A, B) ((A) < (B) ? (A) : (B)) - -static FINLINE char -is_power_of_2(const size_t i) -{ - return (i & (i-1)) == 0 && i > 0; -} +#define RMAX(A, B) ((A) > (B) ? (A) : (B)) +#define RMIN(A, B) ((A) < (B) ? (A) : (B)) +#define IS_POWER_OF_2(A) (((A) & ((A)-1)) == 0 && (A) > 0) static FINLINE size_t round_up_pow2(const size_t i) diff --git a/src/mem_allocator.c b/src/mem_allocator.c @@ -6,8 +6,6 @@ #include <malloc.h> #include <string.h> -#define IS_POWER_OF_2(i) ((i) > 0 && ((i) & ((i)-1)) == 0) - #ifdef MINGW /* On MINGW the _aligned_msize function is not defined. The size is thus * stored into the memory block header */