summaryrefslogtreecommitdiffhomepage
path: root/stc
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-11-30 14:00:19 +0100
committerTyge Løvset <[email protected]>2020-11-30 14:00:19 +0100
commitc7253fa4c12adf0639c1ed3a0cd2b2ea28ee194f (patch)
tree4cc8d5647d47523d5c31f7335f147d77f3443358 /stc
parent6f9fb4c47f5cae5548aecf283e2a1ec8e1cff109 (diff)
downloadSTC-modified-c7253fa4c12adf0639c1ed3a0cd2b2ea28ee194f.tar.gz
STC-modified-c7253fa4c12adf0639c1ed3a0cd2b2ea28ee194f.zip
Added clist docs, updated cbitset.h and docs.
Diffstat (limited to 'stc')
-rw-r--r--stc/cbitset.h26
1 files changed, 21 insertions, 5 deletions
diff --git a/stc/cbitset.h b/stc/cbitset.h
index 946f9545..715eddb4 100644
--- a/stc/cbitset.h
+++ b/stc/cbitset.h
@@ -45,7 +45,9 @@ int main() {
cbitset_del(&bset);
}
*/
-#include "cstr.h"
+#include <stdlib.h>
+#include <string.h>
+#include "ccommon.h"
typedef struct cbitset { uint64_t* _arr; size_t size; } cbitset_t;
@@ -64,6 +66,23 @@ STC_INLINE size_t cbitset_size(cbitset_t set) {return set.size;}
STC_INLINE cbitset_t cbitset_init() {
cbitset_t bs = {NULL, 0}; return bs;
}
+STC_INLINE void cbitset_del(cbitset_t* self) {
+ c_free(self->_arr);
+}
+
+STC_DEF cbitset_t* cbitset_take(cbitset_t* self, cbitset_t other) {
+ if (self->_arr != other._arr) cbitset_del(self), *self = other;
+ return self;
+}
+STC_DEF cbitset_t* cbitset_assign(cbitset_t* self, cbitset_t other) {
+ if (self->_arr != other._arr) cbitset_del(self), *self = cbitset_clone(other);
+ return self;
+}
+STC_INLINE cbitset_t cbitset_move(cbitset_t* self) {
+ cbitset_t tmp = *self; self->_arr = NULL, self->size = 0;
+ return tmp;
+}
+
STC_INLINE void cbitset_set(cbitset_t *self, size_t i) {
self->_arr[i >> 6] |= 1ull << (i & 63);
}
@@ -90,9 +109,6 @@ STC_INLINE void cbitset_flip_all(cbitset_t *self) {
size_t n = (self->size + 63) >> 6;
for (size_t i=0; i<n; ++i) self->_arr[i] ^= ~0ull;
}
-STC_INLINE void cbitset_del(cbitset_t* self) {
- c_free(self->_arr);
-}
/* Intersection */
STC_INLINE void cbitset_intersect_with(cbitset_t *self, cbitset_t other) {
@@ -192,7 +208,7 @@ STC_DEF cbitset_t cbitset_from_str(const char* str) {
}
STC_DEF char* cbitset_to_str(cbitset_t set, char* out, size_t start, intptr_t stop) {
size_t end = stop < 0 ? set.size : stop;
- for (size_t i=start; i<end; ++i) out[i] = (cbitset_test(set, i)) ? '1' : '0';
+ for (size_t i=start; i<end; ++i) out[i] = cbitset_test(set, i) ? '1' : '0';
out[end] = '\0'; return out;
}
STC_DEF cbitset_t cbitset_clone(cbitset_t other) {