10 func_point_t
string_to_function(const struct string_function_t
*data
,
11 size_t n
, const char *find
) {
13 size_t mid
= (size_t)-1, first
= 0, last
= n
- 1;
18 while(first
<= last
&& last
!= (size_t)-1) {
19 mid
= (first
+ last
) / 2;
21 compare
= strcmp(find
, data
[mid
].str
);
26 else if(compare
> 0) {
30 return data
[mid
].data
;
37 size_t string_to_index(const struct string_index_t
*str
, size_t n
,
40 size_t mid
= (size_t)-1, first
= 0, last
= n
- 1;
43 if(!find
) return (size_t)-1;
45 while(first
<= last
&& last
!= (size_t)-1) {
46 mid
= (first
+ last
) / 2;
48 compare
= strcmp(find
, str
[mid
].str
);
53 else if(compare
> 0) {
57 return str
[mid
].index
;
64 double degrees_to_radians(double angle
) {
65 return angle
* CONSTANT_PI
/ 180.0;
68 double radians_to_degrees(double angle
) {
69 return angle
* 180.0 / CONSTANT_PI
;
72 /*! Finds the position in which \a find is located in the array \a data, or,
73 if it is not present, the "closest" place. The closest place is the
74 position of the last element that is smaller than \a find. It is used as
75 the place to insert the element \a find.
77 Useful for binary insertion sorts.
79 \param data The array of elements to search for \a find for.
80 \param n The number of elements in \a data.
81 \param find The memory block to search for.
82 \param pos Set to the actual or closest position of \a data within the
84 \param compare The function to call to compare two elements in \a data.
85 Must return a negative number, 0, or a positive number based on the
86 parameters, just like \c strcmp().
87 \return True if \a find is actually present in \a data, false otherwise.
88 Note that if \a find is not present, \a pos will still be set.
90 int binary_insertion_sort(void *data
, size_t n
, void *find
, size_t *pos
,
91 int (*compare
)(void *data
, size_t n
, void *find
)) {
93 size_t mid
= (size_t)-1, first
= 0, last
= n
- 1;
100 while(first
<= last
&& last
!= (size_t)-1) {
101 mid
= (first
+ last
) / 2;
103 c
= (*compare
)(data
, mid
, find
);
127 int set_bit(int original
, int bit
, int set
) {
138 void set_bit_p(int *original
, int bit
, int set
) {
139 *original
= set_bit(*original
, bit
, set
);