summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--docs/cbits_api.md2
-rw-r--r--include/stc/cbits.h11
2 files changed, 7 insertions, 6 deletions
diff --git a/docs/cbits_api.md b/docs/cbits_api.md
index 84878e30..269db9b3 100644
--- a/docs/cbits_api.md
+++ b/docs/cbits_api.md
@@ -40,7 +40,7 @@ bool cbits_test(const cbits* self, size_t i);
bool cbits_at(const cbits* self, size_t i); // same as cbits_test()
bool cbits_subset_of(const cbits* self, const cbits* other); // is set a subset of other?
bool cbits_disjoint(const cbits* self, const cbits* other); // no common bits
-char* cbits_to_str(const cbits* self, char* str, size_t start, intptr_t stop);
+char* cbits_to_str(const cbits* self, char* str, size_t start, size_t stop);
void cbits_set(cbits* self, size_t i);
void cbits_reset(cbits* self, size_t i);
diff --git a/include/stc/cbits.h b/include/stc/cbits.h
index fcb5808d..10a703e9 100644
--- a/include/stc/cbits.h
+++ b/include/stc/cbits.h
@@ -84,11 +84,12 @@ STC_INLINE size_t _cbits_count(const uint64_t* set, const size_t sz) {
}
STC_INLINE char* _cbits_to_str(const uint64_t* set, const size_t sz,
- char* out, size_t start, intptr_t stop) {
- if (stop < 0)
- stop = sz;
+ char* out, size_t start, size_t stop) {
+ if (stop > sz) stop = sz;
+ assert(start <= stop);
+
memset(out, '0', stop - start);
- for (intptr_t i = start; i < stop; ++i)
+ for (size_t i = start; i < stop; ++i)
if ((set[i>>6] & _cbits_bit(i)) != 0)
out[i - start] = '1';
out[stop - start] = '\0';
@@ -288,7 +289,7 @@ STC_INLINE void _i_memb(_xor)(i_type *self, const i_type* other) {
STC_INLINE size_t _i_memb(_count)(const i_type* self)
{ return _cbits_count(self->data64, _i_memb(_size)(self)); }
-STC_INLINE char* _i_memb(_to_str)(const i_type* self, char* out, size_t start, intptr_t stop)
+STC_INLINE char* _i_memb(_to_str)(const i_type* self, char* out, size_t start, size_t stop)
{ return _cbits_to_str(self->data64, _i_memb(_size)(self), out, start, stop); }
STC_INLINE bool _i_memb(_subset_of)(const i_type* self, const i_type* other) {