1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
=encoding UTF-8
=head1 NAME
BH_Algo - General algorithms
=head1 SYNTAX
#include <BH/Algo.h>
int data[4] = {5, 2, 3, 1};
int value, i;
value = 4;
BH_Partition(&value, data, 4, sizeof(int), intEqual);
BH_Sort(data, 4, sizeof(int), intEqual);
BH_HeapMake(data, 4, sizeof(int), intEqual);
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Algo library provides a set of algorithms for working with data:
=over
=item *
Value swapping (L</BH_Swap>)
=item *
Array partitioning (L</BH_Partition>)
=item *
Sorting (L</BH_Sort>)
=item *
Heap operations (L</BH_HeapMake>, L</BH_HeapRemove>, L</BH_HeapInsert>,
L</BH_HeapReplace>)
=back
These algorithms allow you to efficiently perform various operations on arrays
and other data structures.
=head1 API CALLS
=head2 BH_Swap
void BH_Swap(void *dest,
void *src,
size_t size);
Swaps the values between the variables I<dest> and I<src> of the specified size
I<size>.
=head2 BH_Partition
void *BH_Partition(void *pivot,
void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
Partitions the array of elements I<array> (with the number of elements I<size>
and the size of the element I<element>) into two groups relative to the pivot
element I<pivot>.
The I<equal> parameter takes a pointer to a function that compares two elements.
The I<pivot> parameter can refer to an element of the array being partitioned.
The function returns a pointer to the first element of the array that belongs to
the second group.
=head2 BH_Sort
void BH_Sort(void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
Sorts the array of elements I<array> (with the number of elements I<size> and
the size of the element I<element>).
The I<equal> parameter takes a pointer to a function that compares two elements.
=head2 BH_HeapMake
void BH_HeapMake(void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
Creates a heap in the array I<array> (with the number of elements I<size> and
the size of the element I<element>).
The I<equal> parameter takes a pointer to a function that compares two elements.
=head2 BH_HeapRemove
void BH_HeapRemove(void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
Extracts the top element of the heap in the array I<array> (with the number of
elements I<size> and the size of the element I<element>).
The I<equal> parameter takes a pointer to a function that compares two elements.
=head2 BH_HeapInsert
void BH_HeapInsert(void *value,
void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
Adds the element I<value> to the heap in the array I<array> (with the number of
elements I<size> and the size of the element I<element>).
If I<value> is NULL, it is assumed that the new value is at the end of the
array.
The I<equal> parameter takes a pointer to a function that compares two elements.
=head2 BH_HeapReplace
void BH_HeapReplace(void *value,
void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
Extracts the top element of the heap in the array I<array> (with the number of
elements I<size> and the size of the element I<element>) and adds the element
I<value> to it.
If I<value> is NULL, it is assumed that the new value is at the end of the
array.
The I<equal> parameter takes a pointer to a function that compares two elements.
=head1 SEE ALSO
L<BH>
|