err_status_t rdb_check(const rdb_t *rdb, uint32_t index) { /* if the index appears after (or at very end of) the window, its good */ if (index > rdb->window_start + rdb_bits_in_bitmask) return err_status_ok; /* if the index appears before the window, its bad */ if (index < rdb->window_start) return err_status_fail; /* otherwise, the index appears within the window, so check the bitmask */ if (v128_get_bit(&rdb->bitmask, (index - rdb->window_start)) == 1) return err_status_fail; /* otherwise, the index is okay */ return err_status_ok; }
int main (void) { /* * this program includes various and sundry tests for fundamental * datatypes. it's a grab-bag of throwaway code, retained only in * case of future problems */ int i, j; v128_t x; char *r = "The Moving Finger writes; and, having writ,\n" "Moves on: nor all thy Piety nor Wit\n" "Shall lure it back to cancel half a Line,\n" "Nor all thy Tears wash out a Word of it."; char *s = "incomplet"; print_string(r); print_string(s); byte_order(); test_hex_string_funcs(); for (j=0; j < 128; j++) { v128_set_to_zero(&x); /* x.v32[0] = (1 << j); */ v128_set_bit(&x, j); printf("%s\n", v128_bit_string(&x)); v128_clear_bit(&x, j); printf("%s\n", v128_bit_string(&x)); } printf("----------------------------------------------\n"); v128_set_to_zero(&x); for (i=0; i < 128; i++) { v128_set_bit(&x, i); } printf("%s\n", v128_bit_string(&x)); printf("----------------------------------------------\n"); v128_set_to_zero(&x); v128_set_bit(&x, 0); for (i=0; i < 128; i++) { printf("%s\n", v128_bit_string(&x)); v128_right_shift(&x, 1); } printf("----------------------------------------------\n"); v128_set_to_zero(&x); v128_set_bit(&x, 127); for (i=0; i < 128; i++) { printf("%s\n", v128_bit_string(&x)); v128_left_shift(&x, 1); } printf("----------------------------------------------\n"); for (i=0; i < 128; i++) { v128_set_to_zero(&x); v128_set_bit(&x, 127); v128_left_shift(&x, i); printf("%s\n", v128_bit_string(&x)); } printf("----------------------------------------------\n"); v128_set_to_zero(&x); for (i=0; i < 128; i+=2) { v128_set_bit(&x, i); } printf("bit_string: { %s }\n", v128_bit_string(&x)); printf("get_bit: { "); for (i=0; i < 128; i++) { if (v128_get_bit(&x, i) == 1) printf("1"); else printf("0"); } printf(" } \n"); test_bswap(); return 0; }