Line | Count | Source |
1 | | |
2 | | #include <stdlib.h> |
3 | | #include "wc.h" |
4 | | |
5 | | static int |
6 | | map_cmp(const void *a, const void *b) |
7 | 1.62G | { |
8 | 1.62G | return *(wc_uint16 *)a - ((wc_map *)b)->code; |
9 | 1.62G | } |
10 | | |
11 | | static int |
12 | | map3_cmp(const void *a, const void *b) |
13 | 321k | { |
14 | 321k | return *(wc_uint32 *)a - (((wc_uint32)((wc_map3 *)b)->code << 16) | ((wc_map3 *)b)->code2); |
15 | 321k | } |
16 | | |
17 | | static int |
18 | | map_range_cmp(const void *a, const void *b) |
19 | 33.6M | { |
20 | 33.6M | return (*(wc_uint16 *)a < ((wc_map *)b)->code) ? -1 |
21 | 33.6M | : ((*(wc_uint16 *)a > ((wc_map *)b)->code2) ? 1 : 0); |
22 | 33.6M | } |
23 | | |
24 | | static int |
25 | | map2_range_cmp(const void *a, const void *b) |
26 | 0 | { |
27 | 0 | return (*(wc_uint16 *)a < ((wc_map *)b)->code) ? -1 |
28 | 0 | : ((*(wc_uint16 *)a >= ((wc_map *)b + 1)->code) ? 1 : 0); |
29 | 0 | } |
30 | | |
31 | | static int |
32 | | map3_range_cmp(const void *a, const void *b) |
33 | 263M | { |
34 | 263M | return (*(wc_uint16 *)a < ((wc_map3 *)b)->code) ? -1 |
35 | 263M | : ((*(wc_uint16 *)a > ((wc_map3 *)b)->code2) ? 1 : 0); |
36 | 263M | } |
37 | | |
38 | | wc_map * |
39 | | wc_map_search(wc_uint16 code, wc_map *map, size_t n) |
40 | 155M | { |
41 | 155M | return (wc_map *)bsearch((void *)&code, (void *)map, n, sizeof(wc_map), |
42 | 155M | map_cmp); |
43 | 155M | } |
44 | | |
45 | | wc_map3 * |
46 | | wc_map3_search(wc_uint16 c1, wc_uint16 c2, wc_map3 *map, size_t n) |
47 | 32.3k | { |
48 | 32.3k | wc_uint32 code = ((wc_uint32)c1 << 16) | c2; |
49 | 32.3k | return (wc_map3 *)bsearch((void *)&code, (void *)map, n, sizeof(wc_map3), |
50 | 32.3k | map3_cmp); |
51 | 32.3k | } |
52 | | |
53 | | wc_map * |
54 | | wc_map_range_search(wc_uint16 code, wc_map *map, size_t n) |
55 | 8.60M | { |
56 | 8.60M | return (wc_map *)bsearch((void *)&code, (void *)map, n, sizeof(wc_map), |
57 | 8.60M | map_range_cmp); |
58 | 8.60M | } |
59 | | |
60 | | wc_map * |
61 | | wc_map2_range_search(wc_uint16 code, wc_map *map, size_t n) |
62 | 0 | { |
63 | 0 | return (wc_map *)bsearch((void *)&code, (void *)map, n, sizeof(wc_map), |
64 | 0 | map2_range_cmp); |
65 | 0 | } |
66 | | |
67 | | wc_map3 * |
68 | | wc_map3_range_search(wc_uint16 code, wc_map3 *map, size_t n) |
69 | 36.1M | { |
70 | 36.1M | return (wc_map3 *)bsearch((void *)&code, (void *)map, n, sizeof(wc_map3), |
71 | 36.1M | map3_range_cmp); |
72 | 36.1M | } |