Skip to content
Snippets Groups Projects
Commit f3011f82 authored by Sven M. Hallberg's avatar Sven M. Hallberg
Browse files

allocate 256 bits, not 256 bytes, for a charset

parent c770fbab
No related branches found
No related tags found
No related merge requests found
...@@ -155,20 +155,20 @@ static inline void h_sarray_clear(HSArray *arr) { ...@@ -155,20 +155,20 @@ static inline void h_sarray_clear(HSArray *arr) {
typedef unsigned int *HCharset; typedef unsigned int *HCharset;
static inline HCharset new_charset(HAllocator* mm__) { static inline HCharset new_charset(HAllocator* mm__) {
HCharset cs = h_new(unsigned int, 256 / sizeof(unsigned int)); HCharset cs = h_new(unsigned int, 256 / (sizeof(unsigned int) * 8));
memset(cs, 0, 256); memset(cs, 0, 32); // 32 bytes = 256 bits
return cs; return cs;
} }
static inline int charset_isset(HCharset cs, uint8_t pos) { static inline int charset_isset(HCharset cs, uint8_t pos) {
return !!(cs[pos / sizeof(*cs)] & (1 << (pos % sizeof(*cs)))); return !!(cs[pos / (sizeof(*cs)*8)] & (1 << (pos % (sizeof(*cs)*8))));
} }
static inline void charset_set(HCharset cs, uint8_t pos, int val) { static inline void charset_set(HCharset cs, uint8_t pos, int val) {
cs[pos / sizeof(*cs)] = cs[pos / (sizeof(*cs)*8)] =
val val
? cs[pos / sizeof(*cs)] | (1 << (pos % sizeof(*cs))) ? cs[pos / (sizeof(*cs)*8)] | (1 << (pos % (sizeof(*cs)*8)))
: cs[pos / sizeof(*cs)] & ~(1 << (pos % sizeof(*cs))); : cs[pos / (sizeof(*cs)*8)] & ~(1 << (pos % (sizeof(*cs)*8)));
} }
typedef unsigned int HHashValue; typedef unsigned int HHashValue;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment