From ebc7316ac3859bc5e2f01c85bee86d6adea45898 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 24 May 2022 21:12:56 +0200 Subject: API change: cbits now uses container pointers args in all member functions, except clone() ... for now. All containers may get same treatment! which will be a rather big API change. This was needed after testing fixed size cbits performance with pass-by-value: was very slow for large bitsets: now faster than std::bitset<>. Also reverted previous cbits_set_value(): much faster because it is branchless. --- examples/bits2.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'examples/bits2.c') diff --git a/examples/bits2.c b/examples/bits2.c index e9202efc..81e28d60 100644 --- a/examples/bits2.c +++ b/examples/bits2.c @@ -9,14 +9,14 @@ int main() { Bits s1 = Bits_from("1110100110111"); - printf("size %" PRIuMAX "\n", Bits_size(s1)); + printf("size %" PRIuMAX "\n", Bits_size(&s1)); char buf[256]; - Bits_to_str(s1, buf, 0, -1); - printf("buf: %s: count=%" PRIuMAX "\n", buf, Bits_count(s1)); + Bits_to_str(&s1, buf, 0, -1); + printf("buf: %s: count=%" PRIuMAX "\n", buf, Bits_count(&s1)); Bits_reset(&s1, 8); - c_autobuf (str, char, Bits_size(s1) + 1) - printf(" s1: %s\n", Bits_to_str(s1, str, 0, -1)); + c_autobuf (str, char, Bits_size(&s1) + 1) + printf(" s1: %s\n", Bits_to_str(&s1, str, 0, -1)); Bits s2 = Bits_clone(s1); @@ -24,19 +24,19 @@ int main() Bits_reset(&s2, 66); Bits_reset(&s2, 67); printf(" s2: "); - c_forrange (i, Bits_size(s2)) - printf("%d", Bits_test(s2, i)); + c_forrange (i, Bits_size(&s2)) + printf("%d", Bits_test(&s2, i)); puts(""); printf("xor: "); - Bits_xor(&s1, s2); - c_forrange (i, Bits_size(s1)) - printf("%d", Bits_test(s1, i)); + Bits_xor(&s1, &s2); + c_forrange (i, Bits_size(&s1)) + printf("%d", Bits_test(&s1, i)); puts(""); printf("all: "); Bits_set_pattern(&s1, 0x3333333333333333); - c_forrange (i, Bits_size(s1)) - printf("%d", Bits_test(s1, i)); + c_forrange (i, Bits_size(&s1)) + printf("%d", Bits_test(&s1, i)); puts(""); } -- cgit v1.2.3