Split code out into separate compilation units (first pass, anyway).

This commit is contained in:
Matthew Bloch
2012-05-17 20:14:22 +01:00
parent aec90e5244
commit 0432fef8f5
11 changed files with 790 additions and 683 deletions

39
bitset.h Normal file
View File

@@ -0,0 +1,39 @@
#ifndef __BITSET_H
#define __BITSET_H
#include <string.h>
static inline char char_with_bit_set(int num) {
return 1<<(num%8);
}
static inline int bit_is_set(char* b, int idx) {
return (b[idx/8] & char_with_bit_set(idx)) != 0;
}
static inline int bit_is_clear(char* b, int idx) {
return !bit_is_set(b, idx);
}
static inline void bit_set(char* b, int idx) {
b[idx/8] &= char_with_bit_set(idx);
}
static inline void bit_clear(char* b, int idx) {
b[idx/8] &= ~char_with_bit_set(idx);
}
static inline void bit_set_range(char* b, int from, int len) {
for (; from%8 != 0 && len > 0; len--)
bit_set(b, from++);
if (len >= 8)
memset(b+(from/8), 255, len/8);
for (; len > 0; len--)
bit_set(b, from++);
}
static inline void bit_clear_range(char* b, int from, int len) {
for (; from%8 != 0 && len > 0; len--)
bit_clear(b, from++);
if (len >= 8)
memset(b+(from/8), 0, len/8);
for (; len > 0; len--)
bit_clear(b, from++);
}
#endif