#include #include #include #include "../clock.h" #include "../ternary.h" typedef int data; typedef unsigned index; /* from Rosetta code */ int my_bsearch (data *a, index n, data x) { index i = 0, j = n - 1; while (i <= j) { index k = (i + j) / 2; if (a[k] == x) { return k; } else if (a[k] < x) { i = k + 1; } else { j = k - 1; } } return -1; } int my_bsearch2 (data *a, index n, data x) { index i = 0, j = n - 1; while (i <= j) { index k = (i + j) / 2; if (a[k] == x) { return k; } i = TERNARY32(a[k] < x, k+1, i); j = TERNARY32(a[k] > x, k-1, j); } return -1; } int my_bsearch3 (data *a, index n, data x) { index i = 0, j = n - 1, k; k = (i + j) / 2; while (i <= j) { index kp1 = k+1, km1 = k-1; _Bool lt = a[k] < x, gt = a[k] > x; i = TERNARY32(lt, kp1, i); j = TERNARY32(gt, km1, j); if (a[k] == x) { goto end; } k = (i + j) / 2; } k=-1; end: return k; } void random_ascending_fill(data *a, index n) { unsigned r = 41; data v = 0; for(index i=0; i