int main(int argc, char **argv) { bitset *set; set = bitset_new(50); if (set == NULL) return 0; init_array(); printf("A: \n"); print_array(A, 20); printf("B: \n"); print_array(B, 20); int i, j, common[20]; for (i = 0; i < 20; i++) { bitset_set(set, A[i], 1); } j = 0; for (i = 0; i < 20; i++) { if (bitset_get(set, B[i])) { common[j++] = B[i]; } } printf("Common: \n"); print_array(common, j); bitset_free(set); return 0; }
//Calculates the interference for a single set of live variables static void calc_interference(bitset_t live, bitset_t matrix, unsigned reg_index, unsigned num_regs) { unsigned i; for (i = 0; i < num_regs; i++) { if (i == reg_index) continue; if (bitset_get(live, 4 * i + 0) || bitset_get(live, 4 * i + 1) || bitset_get(live, 4 * i + 2) || bitset_get(live, 4 * i + 3)) { bitset_set(matrix, num_regs*reg_index + i, true); bitset_set(matrix, num_regs*i + reg_index, true); } } }
/*ARGSUSED*/ int bitset(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) { bitset_t *bs; bs = bitset_get(addr); if (bs == NULL) return (DCMD_ERR); bitset_print(bs, "label", 80); bitset_free(bs); return (DCMD_OK); }
void print_bitset_chars(bitset_t set) { int i; for(i = 0; i < set->capacity; ++i) { if(bitset_get(set, i)) { printf("%c ", (char)i); } } printf("\n"); }
END_TEST START_TEST(test_bitset_getset) { int i, j; bitset_init(bs, NCOL1); for (i = 0, j = 0; i < NCOL1; i++) { if (i == cols[j]) { bitset_set(bs, i, 1); j++; ck_assert_int_eq(bs->count, j); } else { /* only bits specified are set */ ck_assert_int_eq(bitset_get(bs, i), 0); } } for (j=0; j < 4; j++) { /* set these bits back to 0 */ ck_assert_int_eq(bitset_get(bs, cols[j]), 1); bitset_set(bs, cols[j], 0); ck_assert_int_eq(bitset_get(bs, cols[j]), 0); ck_assert_int_eq(bs->count, 3 - j); } }
void bitset_print(bitset_t set) { int i; for(i = 0; i < set->capacity; ++i) { if(bitset_get(set, i)) { printf("1"); } else { printf("0"); } } printf("\n"); }
static void supernode_from_kmer(hkey_t hkey, dBNodeBuffer *nbuf, uint64_t *visited, const dBGraph *graph, const char **ans, size_t n) { size_t i; char tmpstr[SNODEBUF]; if(!bitset_get(visited, hkey)) { db_node_buf_reset(nbuf); supernode_find(hkey, nbuf, graph); for(i = 0; i < nbuf->len; i++) bitset_set(visited, nbuf->b[i].key); supernode_normalise(nbuf->b, nbuf->len, graph); TASSERT(nbuf->len < SNODEBUF); db_nodes_to_str(nbuf->b, nbuf->len, graph, tmpstr); for(i = 0; i < n && strcmp(tmpstr,ans[i]) != 0; i++); TASSERT2(i < n, "Got: %s", tmpstr); } }
void test_do(test_context_t *test) { bitset_t *set; int i; test_mark(test, "bitset functions"); test_group_start(test, "Setup and sanity check"); { set = bitset_init(SET_SIZE); test_not_null(test, "Sanity check: allocated bitset", set); } test_group_end(test); test_group_start(test, "set / get"); { int set1[6] = { 0, 1, 3, 5, SET_SIZE -1, SET_SIZE - 3 }; int set2[6] = { 2, 4, 6, 10, 11, SET_SIZE - 2 }; /* set1 is TRUE, set2 is false */ for(i = 0; i < 6; i++) bitset_set(set, set1[i], TRUE); for(i = 0; i < 6; i++) bitset_set(set, set2[i], FALSE); /* now check it */ for(i = 0; i < 6; i++) { test_equal(test, "set1 members are TRUE", bitset_get(set, set1[i]), TRUE); test_equal(test, "set2 members are FALSE", bitset_get(set, set2[i]), FALSE); } /* reverse it and try it again */ for(i = 0; i < 6; i++) bitset_set(set, set1[i], FALSE); for(i = 0; i < 6; i++) bitset_set(set, set2[i], TRUE); for(i = 0; i < 6; i++) { test_equal(test, "set1 members are FALSE (2)", bitset_get(set, set1[i]), FALSE); test_equal(test, "set2 members are TRUE (2)", bitset_get(set, set2[i]), TRUE); } } test_group_end(test); test_group_start(test, "set all"); { /* ALL TRUE */ bitset_set_all(set, TRUE); bitset_set(set, 5, FALSE); /* special one to catch stuck-on bugs ? */ for(i = 0; i < SET_SIZE; i++) { if(i != 5) test_equal(test, "set_all (TRUE)", bitset_get(set, i), TRUE); else test_equal(test, "set_all (one is FALSE)", bitset_get(set, i), FALSE); } /* ALL FALSE */ bitset_set_all(set, FALSE); bitset_set(set, 31, TRUE); /* see above */ for(i = 0; i < SET_SIZE; i++) { if(i != 31) test_equal(test, "set_all (FALSE)", bitset_get(set, i), FALSE); else test_equal(test, "set_all (one is TRUE)", bitset_get(set, i), TRUE); } } test_group_end(test); }
static inline uint8_t bitset_get2(struct bitset *bs,uint8_t x,uint8_t y) { return bitset_get(bs,bitset_offset2(x,y)); }