summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.clang-tidy1
-rw-r--r--src/btree.c98
-rw-r--r--src/bump_allocator.c6
-rw-r--r--src/digest.c82
-rw-r--r--src/hash.c28
-rw-r--r--src/ring.c10
6 files changed, 112 insertions, 113 deletions
diff --git a/src/.clang-tidy b/src/.clang-tidy
index 8c165a5..98a0bc8 100644
--- a/src/.clang-tidy
+++ b/src/.clang-tidy
@@ -4,7 +4,6 @@
Checks: >
*,
-*-magic-numbers,
- -*-uppercase-literal-suffix,
-altera-*,
-bugprone-easily-swappable-parameters,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
diff --git a/src/btree.c b/src/btree.c
index 9bb0904..f0060c3 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -17,12 +17,12 @@ typedef uint16_t ZixShort;
#endif
#ifndef ZIX_BTREE_PAGE_SIZE
-# define ZIX_BTREE_PAGE_SIZE 4096u
+# define ZIX_BTREE_PAGE_SIZE 4096U
#endif
-#define ZIX_BTREE_NODE_SPACE (ZIX_BTREE_PAGE_SIZE - 2u * sizeof(ZixShort))
-#define ZIX_BTREE_LEAF_VALS ((ZIX_BTREE_NODE_SPACE / sizeof(void*)) - 1u)
-#define ZIX_BTREE_INODE_VALS (ZIX_BTREE_LEAF_VALS / 2u)
+#define ZIX_BTREE_NODE_SPACE (ZIX_BTREE_PAGE_SIZE - 2U * sizeof(ZixShort))
+#define ZIX_BTREE_LEAF_VALS ((ZIX_BTREE_NODE_SPACE / sizeof(void*)) - 1U)
+#define ZIX_BTREE_INODE_VALS (ZIX_BTREE_LEAF_VALS / 2U)
struct ZixBTreeImpl {
ZixAllocator* allocator;
@@ -43,28 +43,28 @@ struct ZixBTreeNodeImpl {
struct {
void* vals[ZIX_BTREE_INODE_VALS];
- ZixBTreeNode* children[ZIX_BTREE_INODE_VALS + 1u];
+ ZixBTreeNode* children[ZIX_BTREE_INODE_VALS + 1U];
} inode;
} data;
};
-#if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112l) || \
+#if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
(defined(__cplusplus) && __cplusplus >= 201103L))
static_assert(sizeof(ZixBTree) <= ZIX_BTREE_PAGE_SIZE, "");
static_assert(sizeof(ZixBTreeNode) <= ZIX_BTREE_PAGE_SIZE, "");
static_assert(sizeof(ZixBTreeNode) >=
- ZIX_BTREE_PAGE_SIZE - 2u * sizeof(ZixBTreeNode*),
+ ZIX_BTREE_PAGE_SIZE - 2U * sizeof(ZixBTreeNode*),
"");
#endif
static ZixBTreeNode*
zix_btree_node_new(ZixAllocator* const allocator, const bool leaf)
{
-#if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112l) || \
+#if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
(defined(__cplusplus) && __cplusplus >= 201103L))
assert(sizeof(ZixBTreeNode) <= ZIX_BTREE_PAGE_SIZE);
assert(sizeof(ZixBTreeNode) >=
- ZIX_BTREE_PAGE_SIZE - 2u * sizeof(ZixBTreeNode*));
+ ZIX_BTREE_PAGE_SIZE - 2U * sizeof(ZixBTreeNode*));
#endif
ZixBTreeNode* const node = (ZixBTreeNode*)zix_aligned_alloc(
@@ -72,7 +72,7 @@ zix_btree_node_new(ZixAllocator* const allocator, const bool leaf)
if (node) {
node->is_leaf = leaf;
- node->n_vals = 0u;
+ node->n_vals = 0U;
}
return node;
@@ -92,7 +92,7 @@ zix_btree_new(ZixAllocator* const allocator,
const ZixComparator cmp,
const void* const cmp_data)
{
-#if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112l) || \
+#if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
(defined(__cplusplus) && __cplusplus >= 201103L))
assert(sizeof(ZixBTree) <= ZIX_BTREE_PAGE_SIZE);
#endif
@@ -126,7 +126,7 @@ zix_btree_free_children(ZixBTree* const t,
const void* const destroy_user_data)
{
if (!n->is_leaf) {
- for (ZixShort i = 0; i < n->n_vals + 1u; ++i) {
+ for (ZixShort i = 0; i < n->n_vals + 1U; ++i) {
zix_btree_free_children(
t, zix_btree_child(n, i), destroy, destroy_user_data);
zix_aligned_free(t->allocator, zix_btree_child(n, i));
@@ -135,11 +135,11 @@ zix_btree_free_children(ZixBTree* const t,
if (destroy) {
if (n->is_leaf) {
- for (ZixShort i = 0u; i < n->n_vals; ++i) {
+ for (ZixShort i = 0U; i < n->n_vals; ++i) {
destroy(n->data.leaf.vals[i], destroy_user_data);
}
} else {
- for (ZixShort i = 0u; i < n->n_vals; ++i) {
+ for (ZixShort i = 0U; i < n->n_vals; ++i) {
destroy(n->data.inode.vals[i], destroy_user_data);
}
}
@@ -167,7 +167,7 @@ zix_btree_clear(ZixBTree* const t,
memset(t->root, 0, sizeof(ZixBTreeNode));
t->root->is_leaf = true;
- t->size = 0u;
+ t->size = 0U;
}
size_t
@@ -186,7 +186,7 @@ zix_btree_max_vals(const ZixBTreeNode* const node)
static ZixShort
zix_btree_min_vals(const ZixBTreeNode* const node)
{
- return (ZixShort)(((zix_btree_max_vals(node) + 1u) / 2u) - 1u);
+ return (ZixShort)(((zix_btree_max_vals(node) + 1U) / 2U) - 1U);
}
/// Shift pointers in `array` of length `n` right starting at `i`
@@ -269,12 +269,12 @@ zix_btree_node_is_sorted_with_respect_to(const ZixComparator compare,
const unsigned n_values,
const void* const key)
{
- if (n_values <= 1u) {
+ if (n_values <= 1U) {
return true;
}
int cmp = compare(values[0], key, compare_user_data);
- for (unsigned i = 1u; i < n_values; ++i) {
+ for (unsigned i = 1U; i < n_values; ++i) {
const int next_cmp = compare(values[i], key, compare_user_data);
if ((cmp >= 0 && next_cmp < 0) || (cmp > 0 && next_cmp <= 0)) {
return false;
@@ -295,11 +295,11 @@ zix_btree_find_value(const ZixComparator compare,
const void* const key,
bool* const equal)
{
- unsigned first = 0u;
+ unsigned first = 0U;
unsigned count = n_values;
- while (count > 0u) {
- const unsigned half = count >> 1u;
+ while (count > 0U) {
+ const unsigned half = count >> 1U;
const unsigned i = first + half;
void* const value = values[i];
const int cmp = compare(value, key, compare_user_data);
@@ -310,8 +310,8 @@ zix_btree_find_value(const ZixComparator compare,
}
if (cmp < 0) {
- first += half + 1u;
- count -= half + 1u;
+ first += half + 1U;
+ count -= half + 1U;
} else {
count = half;
}
@@ -335,11 +335,11 @@ zix_btree_find_pattern(const ZixComparator compare_key,
compare_key, compare_key_user_data, values, n_values, key));
#endif
- unsigned first = 0u;
+ unsigned first = 0U;
unsigned count = n_values;
- while (count > 0u) {
- const unsigned half = count >> 1u;
+ while (count > 0U) {
+ const unsigned half = count >> 1U;
const unsigned i = first + half;
void* const value = values[i];
const int cmp = compare_key(value, key, compare_key_user_data);
@@ -351,8 +351,8 @@ zix_btree_find_pattern(const ZixComparator compare_key,
} else if (cmp < 0) {
// Search right half
- first += half + 1u;
- count -= half + 1u;
+ first += half + 1U;
+ count -= half + 1U;
} else {
// Search left half
@@ -362,8 +362,8 @@ zix_btree_find_pattern(const ZixComparator compare_key,
assert(!*equal ||
(compare_key(values[first], key, compare_key_user_data) == 0 &&
- (first == 0u ||
- (compare_key(values[first - 1u], key, compare_key_user_data) < 0))));
+ (first == 0U ||
+ (compare_key(values[first - 1U], key, compare_key_user_data) < 0))));
return first;
}
@@ -510,9 +510,9 @@ zix_btree_iter_push(ZixBTreeIter* const ti,
static void
zix_btree_iter_pop(ZixBTreeIter* const ti)
{
- assert(ti->level > 0u);
+ assert(ti->level > 0U);
ti->nodes[ti->level] = NULL;
- ti->indexes[ti->level] = 0u;
+ ti->indexes[ti->level] = 0U;
--ti->level;
}
@@ -659,7 +659,7 @@ zix_btree_remove_max(ZixBTree* const t, ZixBTreeNode* n)
while (!n->is_leaf) {
ZixBTreeNode* const* const children = n->data.inode.children;
- const unsigned y = n->n_vals - 1u;
+ const unsigned y = n->n_vals - 1U;
const unsigned z = n->n_vals;
n = zix_btree_can_remove_from(children[z]) ? children[z]
@@ -680,11 +680,11 @@ zix_btree_fatten_child(ZixBTree* const t, ZixBTreeIter* const iter)
assert(!n->is_leaf);
ZixBTreeNode* const* const children = n->data.inode.children;
- if (i > 0 && zix_btree_can_remove_from(children[i - 1u])) {
+ if (i > 0 && zix_btree_can_remove_from(children[i - 1U])) {
return zix_btree_rotate_right(n, i); // Steal a key from left sibling
}
- if (i < n->n_vals && zix_btree_can_remove_from(children[i + 1u])) {
+ if (i < n->n_vals && zix_btree_can_remove_from(children[i + 1U])) {
return zix_btree_rotate_left(n, i); // Steal a key from right sibling
}
@@ -692,7 +692,7 @@ zix_btree_fatten_child(ZixBTree* const t, ZixBTreeIter* const iter)
if (i == n->n_vals) {
--iter->indexes[iter->level];
- return zix_btree_merge(t, n, i - 1u); // Merge last two children
+ return zix_btree_merge(t, n, i - 1U); // Merge last two children
}
return zix_btree_merge(t, n, i); // Merge left and right siblings
@@ -722,7 +722,7 @@ zix_btree_replace_value(ZixBTree* const t,
: (rhs->n_vals > lhs->n_vals) ? zix_btree_remove_min(t, rhs)
// Children are balanced, use index parity as a low-bias tie breaker
- : (i & 1u) ? zix_btree_remove_max(t, lhs)
+ : (i & 1U) ? zix_btree_remove_max(t, lhs)
: zix_btree_remove_min(t, rhs);
return ZIX_STATUS_SUCCESS;
@@ -748,9 +748,9 @@ zix_btree_remove(ZixBTree* const t,
minimum. This ensures that there is always room to remove, without
having to merge nodes again on a traversal back up. */
- if (!n->is_leaf && n->n_vals == 1u &&
- !zix_btree_can_remove_from(n->data.inode.children[0u]) &&
- !zix_btree_can_remove_from(n->data.inode.children[1u])) {
+ if (!n->is_leaf && n->n_vals == 1U &&
+ !zix_btree_can_remove_from(n->data.inode.children[0U]) &&
+ !zix_btree_can_remove_from(n->data.inode.children[1U])) {
// Root has only two children, both minimal, merge them into a new root
n = zix_btree_merge(t, n, 0);
}
@@ -798,10 +798,10 @@ zix_btree_remove(ZixBTree* const t,
*out = zix_btree_aerase(n->data.leaf.vals, --n->n_vals, i);
// Update next iterator
- if (n->n_vals == 0u) {
+ if (n->n_vals == 0U) {
// Removed the last element in the tree
assert(n == t->root);
- assert(t->size == 1u);
+ assert(t->size == 1U);
*ti = zix_btree_end_iter;
} else if (i == n->n_vals) {
// Removed the largest element in this leaf, increment to the next
@@ -865,7 +865,7 @@ zix_btree_lower_bound(const ZixBTree* const t,
*ti = zix_btree_end_iter;
ZixBTreeNode* n = t->root; // Current node
- uint16_t found_level = 0u; // Lowest level a match was found at
+ uint16_t found_level = 0U; // Lowest level a match was found at
bool found = false; // True if a match was ever found
// Search down until we reach a leaf
@@ -936,13 +936,13 @@ zix_btree_begin(const ZixBTree* const t)
ZixBTreeIter iter = zix_btree_end_iter;
- if (t->size > 0u) {
+ if (t->size > 0U) {
ZixBTreeNode* n = t->root;
- zix_btree_iter_set_frame(&iter, n, 0u);
+ zix_btree_iter_set_frame(&iter, n, 0U);
while (!n->is_leaf) {
n = zix_btree_child(n, 0);
- zix_btree_iter_push(&iter, n, 0u);
+ zix_btree_iter_push(&iter, n, 0U);
}
}
@@ -960,7 +960,7 @@ zix_btree_end(const ZixBTree* const t)
bool
zix_btree_iter_equals(const ZixBTreeIter lhs, const ZixBTreeIter rhs)
{
- const size_t indexes_size = (lhs.level + 1u) * sizeof(uint16_t);
+ const size_t indexes_size = (lhs.level + 1U) * sizeof(uint16_t);
return (lhs.level == rhs.level) && (lhs.nodes[0] == rhs.nodes[0]) &&
(!lhs.nodes[0] || !memcmp(lhs.indexes, rhs.indexes, indexes_size));
@@ -993,11 +993,11 @@ zix_btree_iter_increment(ZixBTreeIter* const i)
const ZixBTreeNode* const node = i->nodes[i->level];
ZixBTreeNode* const child = node->data.inode.children[index];
- zix_btree_iter_push(i, child, 0u);
+ zix_btree_iter_push(i, child, 0U);
// Move down and left until we hit a leaf
while (!i->nodes[i->level]->is_leaf) {
- zix_btree_iter_push(i, i->nodes[i->level]->data.inode.children[0], 0u);
+ zix_btree_iter_push(i, i->nodes[i->level]->data.inode.children[0], 0U);
}
}
diff --git a/src/bump_allocator.c b/src/bump_allocator.c
index d6d1c41..eedd3e9 100644
--- a/src/bump_allocator.c
+++ b/src/bump_allocator.c
@@ -16,9 +16,9 @@ static size_t
round_up_multiple(const size_t number, const size_t factor)
{
assert(factor); // Factor must be non-zero
- assert((factor & (factor - 1)) == 0u); // Factor must be a power of two
+ assert((factor & (factor - 1)) == 0U); // Factor must be a power of two
- return (number + factor - 1u) & ~(factor - 1u);
+ return (number + factor - 1U) & ~(factor - 1U);
}
ZIX_MALLOC_FUNC
@@ -100,7 +100,7 @@ zix_bump_aligned_alloc(ZixAllocator* const allocator,
const size_t old_top = state->top;
assert(alignment >= min_alignment);
- assert(size % alignment == 0u);
+ assert(size % alignment == 0U);
/* First, calculate how much we need to offset the top to achieve this
alignment. Note that it's not the offset that needs to be aligned (since
diff --git a/src/digest.c b/src/digest.c
index 133f5c0..3af9e8c 100644
--- a/src/digest.c
+++ b/src/digest.c
@@ -23,16 +23,16 @@
static inline uint64_t
mix64(uint64_t h)
{
- h ^= h >> 23u;
- h *= 0x2127599BF4325C37ull;
- h ^= h >> 47u;
+ h ^= h >> 23U;
+ h *= 0x2127599BF4325C37ULL;
+ h ^= h >> 47U;
return h;
}
uint64_t
zix_digest64(const uint64_t seed, const void* const key, const size_t len)
{
- static const uint64_t m = 0x880355F21E6D1965ull;
+ static const uint64_t m = 0x880355F21E6D1965ULL;
// Process as many 64-bit blocks as possible
const size_t n_blocks = len / sizeof(uint64_t);
@@ -40,7 +40,7 @@ zix_digest64(const uint64_t seed, const void* const key, const size_t len)
const uint8_t* const blocks_end = data + (n_blocks * sizeof(uint64_t));
uint64_t h = seed ^ (len * m);
for (; data != blocks_end; data += sizeof(uint64_t)) {
- uint64_t k = 0u;
+ uint64_t k = 0U;
memcpy(&k, data, sizeof(uint64_t));
h ^= mix64(k);
@@ -49,25 +49,25 @@ zix_digest64(const uint64_t seed, const void* const key, const size_t len)
// Process any trailing bytes
const uint8_t* const tail = blocks_end;
- uint64_t v = 0u;
- switch (len & 7u) {
+ uint64_t v = 0U;
+ switch (len & 7U) {
case 7:
- v |= (uint64_t)tail[6] << 48u;
+ v |= (uint64_t)tail[6] << 48U;
FALLTHROUGH();
case 6:
- v |= (uint64_t)tail[5] << 40u;
+ v |= (uint64_t)tail[5] << 40U;
FALLTHROUGH();
case 5:
- v |= (uint64_t)tail[4] << 32u;
+ v |= (uint64_t)tail[4] << 32U;
FALLTHROUGH();
case 4:
- v |= (uint64_t)tail[3] << 24u;
+ v |= (uint64_t)tail[3] << 24U;
FALLTHROUGH();
case 3:
- v |= (uint64_t)tail[2] << 16u;
+ v |= (uint64_t)tail[2] << 16U;
FALLTHROUGH();
case 2:
- v |= (uint64_t)tail[1] << 8u;
+ v |= (uint64_t)tail[1] << 8U;
FALLTHROUGH();
case 1:
v |= (uint64_t)tail[0];
@@ -82,16 +82,16 @@ zix_digest64(const uint64_t seed, const void* const key, const size_t len)
uint64_t
zix_digest64_aligned(const uint64_t seed, const void* const key, size_t len)
{
- static const uint64_t m = 0x880355F21E6D1965ull;
+ static const uint64_t m = 0x880355F21E6D1965ULL;
- assert((uintptr_t)key % sizeof(uint64_t) == 0u);
- assert(len % sizeof(uint64_t) == 0u);
+ assert((uintptr_t)key % sizeof(uint64_t) == 0U);
+ assert(len % sizeof(uint64_t) == 0U);
const uint64_t* const blocks = (const uint64_t*)key;
const size_t n_blocks = len / sizeof(uint64_t);
uint64_t h = seed ^ (len * m);
- for (size_t i = 0u; i < n_blocks; ++i) {
+ for (size_t i = 0U; i < n_blocks; ++i) {
h ^= mix64(blocks[i]);
h *= m;
}
@@ -119,19 +119,19 @@ rotl32(const uint32_t val, const uint32_t bits)
static inline uint32_t
mix32(uint32_t h)
{
- h ^= h >> 16u;
- h *= 0x85EBCA6Bu;
- h ^= h >> 13u;
- h *= 0xC2B2AE35u;
- h ^= h >> 16u;
+ h ^= h >> 16U;
+ h *= 0x85EBCA6BU;
+ h ^= h >> 13U;
+ h *= 0xC2B2AE35U;
+ h ^= h >> 16U;
return h;
}
uint32_t
zix_digest32(const uint32_t seed, const void* const key, const size_t len)
{
- static const uint32_t c1 = 0xCC9E2D51u;
- static const uint32_t c2 = 0x1B873593u;
+ static const uint32_t c1 = 0xCC9E2D51U;
+ static const uint32_t c2 = 0x1B873593U;
// Process as many 32-bit blocks as possible
const size_t n_blocks = len / sizeof(uint32_t);
@@ -139,7 +139,7 @@ zix_digest32(const uint32_t seed, const void* const key, const size_t len)
const uint8_t* const blocks_end = data + (n_blocks * sizeof(uint32_t));
uint32_t h = seed;
for (; data != blocks_end; data += sizeof(uint32_t)) {
- uint32_t k = 0u;
+ uint32_t k = 0U;
memcpy(&k, data, sizeof(uint32_t));
k *= c1;
@@ -148,23 +148,23 @@ zix_digest32(const uint32_t seed, const void* const key, const size_t len)
h ^= k;
h = rotl32(h, 13);
- h = h * 5u + 0xE6546B64u;
+ h = h * 5U + 0xE6546B64U;
}
// Process any trailing bytes
- uint32_t k = 0u;
- switch (len & 3u) {
- case 3u:
- k ^= (uint32_t)data[2u] << 16u;
+ uint32_t k = 0U;
+ switch (len & 3U) {
+ case 3U:
+ k ^= (uint32_t)data[2U] << 16U;
FALLTHROUGH();
- case 2u:
- k ^= (uint32_t)data[1u] << 8u;
+ case 2U:
+ k ^= (uint32_t)data[1U] << 8U;
FALLTHROUGH();
- case 1u:
- k ^= (uint32_t)data[0u];
+ case 1U:
+ k ^= (uint32_t)data[0U];
k *= c1;
- k = rotl32(k, 15u);
+ k = rotl32(k, 15U);
k *= c2;
h ^= k;
}
@@ -177,16 +177,16 @@ zix_digest32_aligned(const uint32_t seed,
const void* const key,
const size_t len)
{
- static const uint32_t c1 = 0xCC9E2D51u;
- static const uint32_t c2 = 0x1B873593u;
+ static const uint32_t c1 = 0xCC9E2D51U;
+ static const uint32_t c2 = 0x1B873593U;
- assert((uintptr_t)key % sizeof(uint32_t) == 0u);
- assert(len % sizeof(uint32_t) == 0u);
+ assert((uintptr_t)key % sizeof(uint32_t) == 0U);
+ assert(len % sizeof(uint32_t) == 0U);
const uint32_t* const blocks = (const uint32_t*)key;
const size_t n_blocks = len / sizeof(uint32_t);
uint32_t h = seed;
- for (size_t i = 0u; i < n_blocks; ++i) {
+ for (size_t i = 0U; i < n_blocks; ++i) {
uint32_t k = blocks[i];
k *= c1;
@@ -195,7 +195,7 @@ zix_digest32_aligned(const uint32_t seed,
h ^= k;
h = rotl32(h, 13);
- h = h * 5u + 0xE6546B64u;
+ h = h * 5U + 0xE6546B64U;
}
return mix32(h ^ (uint32_t)len);
diff --git a/src/hash.c b/src/hash.c
index f0f2fe9..750156f 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -22,8 +22,8 @@ struct ZixHashImpl {
ZixHashEntry* entries; ///< Pointer to dynamically allocated table
};
-static const size_t min_n_entries = 4u;
-static const size_t tombstone = 0xDEADu;
+static const size_t min_n_entries = 4U;
+static const size_t tombstone = 0xDEADU;
ZixHash*
zix_hash_new(ZixAllocator* const allocator,
@@ -44,9 +44,9 @@ zix_hash_new(ZixAllocator* const allocator,
hash->key_func = key_func;
hash->hash_func = hash_func;
hash->equal_func = equal_func;
- hash->count = 0u;
+ hash->count = 0U;
hash->n_entries = min_n_entries;
- hash->mask = hash->n_entries - 1u;
+ hash->mask = hash->n_entries - 1U;
hash->entries =
(ZixHashEntry*)zix_calloc(allocator, hash->n_entries, sizeof(ZixHashEntry));
@@ -72,7 +72,7 @@ ZixHashIter
zix_hash_begin(const ZixHash* const hash)
{
assert(hash);
- return hash->entries[0u].value ? 0u : zix_hash_next(hash, 0u);
+ return hash->entries[0U].value ? 0U : zix_hash_next(hash, 0U);
}
ZixHashIter
@@ -137,7 +137,7 @@ is_match(const ZixHash* const hash,
static inline size_t
next_index(const ZixHash* const hash, const size_t i)
{
- return (i == hash->mask) ? 0u : (i + 1u);
+ return (i == hash->mask) ? 0U : (i + 1U);
}
static inline ZixHashIter
@@ -174,11 +174,11 @@ rehash(ZixHash* const hash, const size_t old_n_entries)
hash->entries = new_entries;
// Reinsert every element into the new array
- for (size_t i = 0u; i < old_n_entries; ++i) {
+ for (size_t i = 0U; i < old_n_entries; ++i) {
ZixHashEntry* const entry = &old_entries[i];
if (entry->value) {
- assert(hash->mask == hash->n_entries - 1u);
+ assert(hash->mask == hash->n_entries - 1U);
const size_t new_h = fold_hash(entry->hash, hash->mask);
const size_t new_i = find_entry(hash, entry->value, new_h, entry->hash);
@@ -196,8 +196,8 @@ grow(ZixHash* const hash)
const size_t old_n_entries = hash->n_entries;
const size_t old_mask = hash->mask;
- hash->n_entries <<= 1u;
- hash->mask = hash->n_entries - 1u;
+ hash->n_entries <<= 1U;
+ hash->mask = hash->n_entries - 1U;
const ZixStatus st = rehash(hash, old_n_entries);
if (st) {
@@ -214,8 +214,8 @@ shrink(ZixHash* const hash)
if (hash->n_entries > min_n_entries) {
const size_t old_n_entries = hash->n_entries;
- hash->n_entries >>= 1u;
- hash->mask = hash->n_entries - 1u;
+ hash->n_entries >>= 1U;
+ hash->mask = hash->n_entries - 1U;
return rehash(hash, old_n_entries);
}
@@ -327,7 +327,7 @@ zix_hash_insert_at(ZixHash* const hash,
entry->value = record;
// Update size and rehash if we exceeded the maximum load
- const size_t max_load = hash->n_entries / 2u + hash->n_entries / 8u;
+ const size_t max_load = hash->n_entries / 2U + hash->n_entries / 8U;
const size_t new_count = hash->count + 1;
if (new_count >= max_load) {
const ZixStatus st = grow(hash);
@@ -368,7 +368,7 @@ zix_hash_erase(ZixHash* const hash,
// Decrease element count and rehash if necessary
--hash->count;
- if (hash->count < hash->n_entries / 4u) {
+ if (hash->count < hash->n_entries / 4U) {
return shrink(hash);
}
diff --git a/src/ring.c b/src/ring.c
index d5b942b..4998112 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -46,11 +46,11 @@ next_power_of_two(uint32_t size)
{
// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
size--;
- size |= size >> 1u;
- size |= size >> 2u;
- size |= size >> 4u;
- size |= size >> 8u;
- size |= size >> 16u;
+ size |= size >> 1U;
+ size |= size >> 2U;
+ size |= size >> 4U;
+ size |= size >> 8U;
+ size |= size >> 16U;
size++;
return size;
}