summaryrefslogtreecommitdiffhomepage
path: root/include/stc/cmap.h
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2023-02-01 08:38:45 +0100
committerTyge Lovset <[email protected]>2023-02-01 08:38:45 +0100
commit6ce6ef3307e52db5813d3c8d6a2cba52df06daf8 (patch)
tree25af4be9fcd5e72778715b83ff312e157ca63b59 /include/stc/cmap.h
parentb677a0c3950b8294ba6458e682a885351273ac08 (diff)
downloadSTC-modified-6ce6ef3307e52db5813d3c8d6a2cba52df06daf8.tar.gz
STC-modified-6ce6ef3307e52db5813d3c8d6a2cba52df06daf8.zip
Massive update from unsigned sizes and indices to signed.
Diffstat (limited to 'include/stc/cmap.h')
-rw-r--r--include/stc/cmap.h48
1 files changed, 24 insertions, 24 deletions
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index f9cd6986..f90d9a4a 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -53,7 +53,7 @@ int main(void) {
#include "forward.h"
#include <stdlib.h>
#include <string.h>
-typedef struct { size_t idx; uint8_t hx; } chash_bucket_t;
+typedef struct { intptr_t idx; uint8_t hx; } chash_bucket_t;
#endif // CMAP_H_INCLUDED
#ifndef _i_prefix
@@ -96,13 +96,13 @@ typedef _i_SET_ONLY( i_keyraw )
i_valraw second; } )
_cx_raw;
-STC_API _cx_self _cx_memb(_with_capacity)(size_t cap);
+STC_API _cx_self _cx_memb(_with_capacity)(intptr_t cap);
#if !defined i_no_clone
STC_API _cx_self _cx_memb(_clone)(_cx_self map);
#endif
STC_API void _cx_memb(_drop)(_cx_self* self);
STC_API void _cx_memb(_clear)(_cx_self* self);
-STC_API bool _cx_memb(_reserve)(_cx_self* self, size_t capacity);
+STC_API bool _cx_memb(_reserve)(_cx_self* self, intptr_t capacity);
STC_API chash_bucket_t _cx_memb(_bucket_)(const _cx_self* self, const _cx_rawkey* rkeyptr);
STC_API _cx_result _cx_memb(_insert_entry_)(_cx_self* self, _cx_rawkey rkey);
STC_API void _cx_memb(_erase_entry)(_cx_self* self, _cx_value* val);
@@ -111,10 +111,10 @@ STC_INLINE _cx_self _cx_memb(_init)(void) { return c_LITERAL(_cx_self){0}; }
STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self) { _cx_memb(_reserve)(self, self->size); }
STC_INLINE float _cx_memb(_max_load_factor)(const _cx_self* self) { return (float)(i_max_load_factor); }
STC_INLINE bool _cx_memb(_empty)(const _cx_self* map) { return !map->size; }
-STC_INLINE size_t _cx_memb(_size)(const _cx_self* map) { return map->size; }
-STC_INLINE size_t _cx_memb(_bucket_count)(_cx_self* map) { return map->bucket_count; }
-STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* map)
- { return (size_t)((float)map->bucket_count * (i_max_load_factor)); }
+STC_INLINE intptr_t _cx_memb(_size)(const _cx_self* map) { return map->size; }
+STC_INLINE intptr_t _cx_memb(_bucket_count)(_cx_self* map) { return map->bucket_count; }
+STC_INLINE intptr_t _cx_memb(_capacity)(const _cx_self* map)
+ { return (intptr_t)((float)map->bucket_count * (i_max_load_factor)); }
STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, _cx_rawkey rkey)
{ return self->size && self->_hashx[_cx_memb(_bucket_)(self, &rkey).idx]; }
@@ -195,7 +195,7 @@ _cx_memb(_push)(_cx_self* self, _cx_value _val) {
return _res;
}
-STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, size_t n) {
+STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, intptr_t n) {
while (n--)
#if defined _i_isset && defined i_no_emplace
_cx_memb(_insert)(self, *raw++);
@@ -208,7 +208,7 @@ STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, size_t n) {
#endif
}
-STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, size_t n)
+STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, intptr_t n)
{ _cx_self cx = {0}; _cx_memb(_put_n)(&cx, raw, n); return cx; }
STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) {
@@ -238,7 +238,7 @@ _cx_memb(_advance)(_cx_iter it, size_t n) {
STC_INLINE _cx_iter
_cx_memb(_find)(const _cx_self* self, _cx_rawkey rkey) {
- size_t idx;
+ intptr_t idx;
if (self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx])
return c_LITERAL(_cx_iter){self->table + idx,
self->table + self->bucket_count,
@@ -248,7 +248,7 @@ _cx_memb(_find)(const _cx_self* self, _cx_rawkey rkey) {
STC_INLINE const _cx_value*
_cx_memb(_get)(const _cx_self* self, _cx_rawkey rkey) {
- size_t idx;
+ intptr_t idx;
if (self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx])
return self->table + idx;
return NULL;
@@ -258,12 +258,12 @@ STC_INLINE _cx_value*
_cx_memb(_get_mut)(_cx_self* self, _cx_rawkey rkey)
{ return (_cx_value*)_cx_memb(_get)(self, rkey); }
-STC_INLINE size_t
+STC_INLINE intptr_t
_cx_memb(_erase)(_cx_self* self, _cx_rawkey rkey) {
if (self->size == 0)
return 0;
chash_bucket_t b = _cx_memb(_bucket_)(self, &rkey);
- return self->_hashx[b.idx] ? _cx_memb(_erase_entry)(self, self->table + b.idx), 1U : 0U;
+ return self->_hashx[b.idx] ? _cx_memb(_erase_entry)(self, self->table + b.idx), 1 : 0;
}
STC_INLINE _cx_iter
@@ -278,11 +278,11 @@ _cx_memb(_erase_at)(_cx_self* self, _cx_iter it) {
#if defined(i_implement)
#ifndef CMAP_H_INCLUDED
-STC_INLINE size_t fastrange_1(uint64_t x, uint64_t n)
- { return (size_t)((uint32_t)x*n >> 32); } // n < 2^32
+STC_INLINE intptr_t fastrange_1(uint64_t x, uint64_t n)
+ { return (intptr_t)((uint32_t)x*n >> 32); } // n < 2^32
-STC_INLINE size_t fastrange_2(uint64_t x, uint64_t n)
- { return x & (n - 1); } // n power of 2.
+STC_INLINE intptr_t fastrange_2(uint64_t x, uint64_t n)
+ { return (intptr_t)(x & (n - 1)); } // n power of 2.
STC_INLINE uint64_t next_power_of_2(uint64_t n) {
n--;
@@ -294,7 +294,7 @@ STC_INLINE uint64_t next_power_of_2(uint64_t n) {
#endif // CMAP_H_INCLUDED
STC_DEF _cx_self
-_cx_memb(_with_capacity)(const size_t cap) {
+_cx_memb(_with_capacity)(const intptr_t cap) {
_cx_self h = {0};
_cx_memb(_reserve)(&h, cap);
return h;
@@ -319,7 +319,7 @@ STC_DEF void _cx_memb(_drop)(_cx_self* self) {
STC_DEF void _cx_memb(_clear)(_cx_self* self) {
_cx_memb(_wipe_)(self);
self->size = 0;
- memset(self->_hashx, 0, self->bucket_count);
+ c_memset(self->_hashx, 0, self->bucket_count);
}
#ifndef _i_isset
@@ -355,7 +355,7 @@ STC_DEF chash_bucket_t
_cx_memb(_bucket_)(const _cx_self* self, const _cx_rawkey* rkeyptr) {
const uint64_t _hash = i_hash_functor(self, rkeyptr);
i_size _cap = self->bucket_count;
- chash_bucket_t b = {c_PASTE(fastrange_,_i_expandby)(_hash, _cap), (uint8_t)(_hash | 0x80)};
+ chash_bucket_t b = {c_PASTE(fastrange_,_i_expandby)(_hash, (uint64_t)_cap), (uint8_t)(_hash | 0x80)};
const uint8_t* _hx = self->_hashx;
while (_hx[b.idx]) {
if (_hx[b.idx] == b.hx) {
@@ -390,7 +390,7 @@ STC_DEF _cx_self
_cx_memb(_clone)(_cx_self m) {
if (m.table) {
_cx_value *t = c_ALLOC_N(_cx_value, m.bucket_count), *dst = t, *m_end = m.table + m.bucket_count;
- uint8_t *h = (uint8_t *)memcpy(c_malloc(m.bucket_count + 1), m._hashx, m.bucket_count + 1);
+ uint8_t *h = (uint8_t *)c_memcpy(c_malloc(m.bucket_count + 1), m._hashx, m.bucket_count + 1);
if (!(t && h))
{ c_free(t), c_free(h), t = 0, h = 0, m.bucket_count = 0; }
else
@@ -404,7 +404,7 @@ _cx_memb(_clone)(_cx_self m) {
#endif
STC_DEF bool
-_cx_memb(_reserve)(_cx_self* self, const size_t _newcap) {
+_cx_memb(_reserve)(_cx_self* self, const intptr_t _newcap) {
const i_size _oldbuckets = self->bucket_count;
if (_newcap != self->size && _newcap <= _oldbuckets)
return true;
@@ -424,7 +424,7 @@ _cx_memb(_reserve)(_cx_self* self, const size_t _newcap) {
m._hashx[_nbuckets] = 0xff;
const _cx_value* e = self->table;
const uint8_t* h = self->_hashx;
- for (size_t i = 0; i < _oldbuckets; ++i, ++e) if (*h++) {
+ for (i_size i = 0; i < _oldbuckets; ++i, ++e) if (*h++) {
_cx_rawkey r = i_keyto(_i_keyref(e));
chash_bucket_t b = _cx_memb(_bucket_)(&m, &r);
m.table[b.idx] = *e;
@@ -450,7 +450,7 @@ _cx_memb(_erase_entry)(_cx_self* self, _cx_value* _val) {
if (! _hashx[j])
break;
const _cx_rawkey _raw = i_keyto(_i_keyref(_slot + j));
- k = (i_size)c_PASTE(fastrange_,_i_expandby)(i_hash_functor(self, (&_raw)), _cap);
+ k = (i_size)c_PASTE(fastrange_,_i_expandby)(i_hash_functor(self, (&_raw)), (uint64_t)_cap);
if ((j < i) ^ (k <= i) ^ (k > j)) /* is k outside (i, j]? */
_slot[i] = _slot[j], _hashx[i] = _hashx[j], i = j;
}