int main(int argc, char **argv) { bitset_size_t pos; bitset_t *bitset = bitset_init(NULL, DATA_SIZE); bitset_set(bitset, 0); bitset_set(bitset, 5); bitset_set(bitset, 38); bitset_set(bitset, 31); bitset_set(bitset, 32); bitset_print(bitset); bitset_unset_all(bitset); bitset_print(bitset); bitset_set_all(bitset); bitset_print(bitset); /* pos = -1; */ /* while ((pos = bitset_find_first_set_since(bitset, pos + 1)) */ /* != bitset_npos) */ /* printf("%d is set\n", pos); */ /* pos = -1; */ /* while ((pos = bitset_find_first_unset_since(bitset, pos + 1)) */ /* != bitset_npos) */ /* printf("%d is unset\n", pos); */ bitset_delete(bitset); return 0; }
int main(int argc, char** argv) { int show_details = 0; printf("\nShow details,run: %s details.\n",argv[0]); if(argc > 1) { if(strcmp("details",argv[1]) == 0) { show_details = 1; } } bitset *s = bitset_init(200); bitset_set_bit(s, 0); bitset_set_bit(s, 1); bitset_set_bit(s, 2); bitset_set_bit(s, 3); bitset_set_bit(s, 4); bitset_set_bit(s, 5); bitset_set_bit(s, 6); bitset_set_bit(s, 7); bitset_set_bit(s, 8); bitset_set_bit(s, 9); bitset_set_bit(s, 10); bitset_print(s); bitset_clear_bit(s, 1); bitset_clear_bit(s, 4); bitset_clear_bit(s, 7); bitset_print(s); size_t pos = bitset_get_first_unused_bit_pos(s); printf("pos : %d\n", pos); bitset_set_bit(s, pos); pos = bitset_get_first_unused_bit_pos(s); printf("pos : %d\n", pos); bitset_free(s); run(1); return (EXIT_SUCCESS); }
int main(int argc, char * argv[]) { struct bitset_t * b = bitset_alloc(65); bitset_set_bit(b, 0); bitset_set_bit(b, 5); bitset_set_bit(b, 3); bitset_set_bit(b, 10); bitset_set_bit(b, 59); bitset_reset_bit(b, 10); fprintf(stdout, "bitset = "); bitset_print(b, stdout); fputs("\n", stdout); return 0; }
/*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); }
// ascii test int main() { // create a bitset capable of representing any ascii char bitset_t set = bitset_alloc(128); char str1[255]; printf("\033[1;34mplease enter characters to set:\033[0m "); fgets(str1, 255, stdin); char* p = str1; while(*p != '\0' && *p != '\n') { bitset_set(set, (int)(*p), 1); ++p; } printf("\n\033[1;34mbitset looks like:\n\033[1;36m"); bitset_print(set); print_bitset_chars(set); printf("\033[1;34mplease enter characters to delete:\033[0m "); fgets(str1, 255, stdin); p = str1; while(*p != '\0' && *p != '\n') { bitset_set(set, (int)(*p), 0); ++p; } printf("\n\033[1;34mbitset looks like:\n\033[1;36m"); bitset_print(set); print_bitset_chars(set); printf("\033[0m\n"); return 0; }
void cndtab_print (struct cndtab *tab, char *head, FILE *stream, int indent) { cndnum_t i; int j; char *comma; fprintf (stream, "Condition table %s\n", head); for (i=0; i<tab->count_cnds; i++) { fprintf (stream, "C%d, lexhash=", i); hash_print (&tab->cnds [i].linehash, stream); fprintf (stream, ", vars_needed="); bitset_print (tab->cnds [i].vars_needed, "V", stream); comma = "\nexpression = "; for (j=0; j<tab->cnds [i].calclen; j++) { if (tab->cnds [i].calc [j] < 0) { fprintf (stream, "%s%c", comma, -tab->cnds [i].calc [j]); } else { fprintf (stream, "%sV%d", comma, tab->cnds [i].calc [j]); } comma = ","; } fprintf (stream, "\n"); } }
int main() { char input1[MAX_SIZE]; char input2[MAX_SIZE]; printf("%s\n", "Enter the first line of input:"); fgets(input1, MAX_SIZE, stdin); printf("%s\n", "Enter the second line of input:"); fgets(input2, MAX_SIZE, stdin); struct bitset * set1; set1 = bitset_new(MAX_SIZE); struct bitset * set2; set2 = bitset_new(MAX_SIZE); // Create bitsets for the result of // union & intersection function calls struct bitset * union_result_set; union_result_set = bitset_new(MAX_SIZE); struct bitset * intersect_result_set; intersect_result_set = bitset_new(MAX_SIZE); // Can't accept the newline bit, but it was being // set each time the fgets call was made and being added // Add all the input from string to set1 for(int i = 0; input1[i] != '\0'; i++){ if(input1[i] != '\n') bitset_add(set1, input1[i]); } // Add all the input from string to set2 for(int i = 0; input2[i] != '\0'; i++){ if(input2[i] != '\n') bitset_add(set2, input2[i]); } bitset_union(union_result_set, set1, set2); bitset_intersect(intersect_result_set, set1, set2); // Some quick testing I did to make sure things worked // Required me to manually enter the desired chars // Test adding, removal and lookup // printf("Lookup for '2' = %d, expected 1\n", bitset_lookup(set1, '2')); // printf("Remove for '2' = %d, expected 1\n", bitset_remove(set1, '2')); // printf("Lookup for '2' = %d, expected 0\n", bitset_lookup(set1, '2')); // // printf("Lookup for '3' = %d, expected 1\n", bitset_lookup(set1, '3')); // printf("Remove for '3' = %d, expected 1\n", bitset_remove(set1, '3')); // printf("Lookup for '3' = %d, expected 0\n", bitset_lookup(set1, '3')); // Test union // printf("Lookup for '1' = %d, expected 1\n", bitset_lookup(union_result_set, '1')); // printf("Lookup for '2' = %d, expected 1\n", bitset_lookup(union_result_set, '2')); // // Test intersection // printf("Lookup for '1' = %d, expected 1\n", bitset_lookup(intersect_result_set, '1')); // printf("Lookup for '2' = %d, expected 1\n", bitset_lookup(intersect_result_set, '2')); // printf("Lookup for '3' = %d, expected 0\n", bitset_lookup(intersect_result_set, '3')); // printf("%s\n", "Set 1:"); // bitset_print(set1); // // printf("%s\n", "Set 2:"); // bitset_print(set2); bitset_print(union_result_set); bitset_print(intersect_result_set); return 0; }