Skip to content

Commit 3111c56

Browse files
committed
Auto-format all code to consistent style
This was done automatically using the clang-format config added in the previous commit.
1 parent 07af4ae commit 3111c56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+389
-447
lines changed

src/arraylist.c

+11-14
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ int arraylist_insert(ArrayList *arraylist, unsigned int index,
108108

109109
/* Move the contents of the array forward from the index
110110
* onwards */
111-
memmove(&arraylist->data[index + 1],
112-
&arraylist->data[index],
111+
memmove(&arraylist->data[index + 1], &arraylist->data[index],
113112
(arraylist->length - index) * sizeof(ArrayListValue));
114113

115114
/* Insert the new entry at the index */
@@ -138,10 +137,9 @@ void arraylist_remove_range(ArrayList *arraylist, unsigned int index,
138137
}
139138

140139
/* Move back the entries following the range to be removed */
141-
memmove(&arraylist->data[index],
142-
&arraylist->data[index + length],
143-
(arraylist->length - (index + length))
144-
* sizeof(ArrayListValue));
140+
memmove(&arraylist->data[index], &arraylist->data[index + length],
141+
(arraylist->length - (index + length)) *
142+
sizeof(ArrayListValue));
145143

146144
/* Decrease the counter */
147145
arraylist->length -= length;
@@ -152,15 +150,15 @@ void arraylist_remove(ArrayList *arraylist, unsigned int index)
152150
arraylist_remove_range(arraylist, index, 1);
153151
}
154152

155-
int arraylist_index_of(ArrayList *arraylist,
156-
ArrayListEqualFunc callback,
153+
int arraylist_index_of(ArrayList *arraylist, ArrayListEqualFunc callback,
157154
ArrayListValue data)
158155
{
159156
unsigned int i;
160157

161-
for (i=0; i<arraylist->length; ++i) {
162-
if (callback(arraylist->data[i], data) != 0)
158+
for (i = 0; i < arraylist->length; ++i) {
159+
if (callback(arraylist->data[i], data) != 0) {
163160
return (int) i;
161+
}
164162
}
165163

166164
return -1;
@@ -188,7 +186,7 @@ static void arraylist_sort_internal(ArrayListValue *list_data,
188186
}
189187

190188
/* Take the last item as the pivot. */
191-
pivot = list_data[list_length-1];
189+
pivot = list_data[list_length - 1];
192190

193191
/* Divide the list into two lists:
194192
*
@@ -202,7 +200,7 @@ static void arraylist_sort_internal(ArrayListValue *list_data,
202200
*/
203201
list1_length = 0;
204202

205-
for (i=0; i<list_length-1; ++i) {
203+
for (i = 0; i < list_length - 1; ++i) {
206204

207205
if (compare_func(list_data[i], pivot) < 0) {
208206

@@ -230,7 +228,7 @@ static void arraylist_sort_internal(ArrayListValue *list_data,
230228
* or equal to the pivot.
231229
* Move the pivot into place, by swapping it with the item
232230
* immediately following the end of list 1. */
233-
list_data[list_length-1] = list_data[list1_length];
231+
list_data[list_length - 1] = list_data[list1_length];
234232
list_data[list1_length] = pivot;
235233

236234
/* Recursively sort the sublists. */
@@ -246,4 +244,3 @@ void arraylist_sort(ArrayList *arraylist, ArrayListCompareFunc compare_func)
246244
arraylist_sort_internal(arraylist->data, arraylist->length,
247245
compare_func);
248246
}
249-

src/arraylist.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ struct _ArrayList {
7676
*
7777
* @return Non-zero if the values are equal, zero if they are not equal.
7878
*/
79-
typedef int (*ArrayListEqualFunc)(ArrayListValue value1,
80-
ArrayListValue value2);
79+
typedef int (*ArrayListEqualFunc)(ArrayListValue value1, ArrayListValue value2);
8180

8281
/**
8382
* Compare two values in an arraylist. Used by @ref arraylist_sort
@@ -178,8 +177,7 @@ int arraylist_insert(ArrayList *arraylist, unsigned int index,
178177
* @param data The value to search for.
179178
* @return The index of the value if found, or -1 if not found.
180179
*/
181-
int arraylist_index_of(ArrayList *arraylist,
182-
ArrayListEqualFunc callback,
180+
int arraylist_index_of(ArrayList *arraylist, ArrayListEqualFunc callback,
183181
ArrayListValue data);
184182

185183
/**

src/avl-tree.c

+19-19
Original file line numberDiff line numberDiff line change
@@ -171,20 +171,20 @@ static AVLTreeNode *avl_tree_rotate(AVLTree *tree, AVLTreeNode *node,
171171

172172
/* The child of this node will take its place:
173173
for a left rotation, it is the right child, and vice versa. */
174-
new_root = node->children[1-direction];
174+
new_root = node->children[1 - direction];
175175

176176
/* Make new_root the root, update parent pointers. */
177177
avl_tree_node_replace(tree, node, new_root);
178178

179179
/* Rearrange pointers */
180-
node->children[1-direction] = new_root->children[direction];
180+
node->children[1 - direction] = new_root->children[direction];
181181
new_root->children[direction] = node;
182182

183183
/* Update parent references */
184184
node->parent = new_root;
185185

186-
if (node->children[1-direction] != NULL) {
187-
node->children[1-direction]->parent = node;
186+
if (node->children[1 - direction] != NULL) {
187+
node->children[1 - direction]->parent = node;
188188
}
189189

190190
/* Update heights of the affected nodes */
@@ -194,7 +194,6 @@ static AVLTreeNode *avl_tree_rotate(AVLTree *tree, AVLTreeNode *node,
194194
return new_root;
195195
}
196196

197-
198197
/* Balance a particular tree node.
199198
*
200199
* Returns the root node of the new subtree which is replacing the
@@ -212,16 +211,18 @@ static AVLTreeNode *avl_tree_node_balance(AVLTree *tree, AVLTreeNode *node)
212211
/* Check the heights of the child trees. If there is an unbalance
213212
* (difference between left and right > 2), then rotate nodes
214213
* around to fix it */
215-
diff = avl_tree_subtree_height(right_subtree)
216-
- avl_tree_subtree_height(left_subtree);
214+
diff = avl_tree_subtree_height(right_subtree) -
215+
avl_tree_subtree_height(left_subtree);
217216

218217
if (diff >= 2) {
219218

220219
/* Biased toward the right side too much. */
221220
child = right_subtree;
222221

223-
if (avl_tree_subtree_height(child->children[AVL_TREE_NODE_RIGHT])
224-
< avl_tree_subtree_height(child->children[AVL_TREE_NODE_LEFT])) {
222+
if (avl_tree_subtree_height(
223+
child->children[AVL_TREE_NODE_RIGHT]) <
224+
avl_tree_subtree_height(
225+
child->children[AVL_TREE_NODE_LEFT])) {
225226

226227
/* If the right child is biased toward the left
227228
* side, it must be rotated right first (double
@@ -239,14 +240,15 @@ static AVLTreeNode *avl_tree_node_balance(AVLTree *tree, AVLTreeNode *node)
239240
/* Biased toward the left side too much. */
240241
child = node->children[AVL_TREE_NODE_LEFT];
241242

242-
if (avl_tree_subtree_height(child->children[AVL_TREE_NODE_LEFT])
243-
< avl_tree_subtree_height(child->children[AVL_TREE_NODE_RIGHT])) {
243+
if (avl_tree_subtree_height(
244+
child->children[AVL_TREE_NODE_LEFT]) <
245+
avl_tree_subtree_height(
246+
child->children[AVL_TREE_NODE_RIGHT])) {
244247

245248
/* If the left child is biased toward the right
246249
* side, it must be rotated right left (double
247250
* rotation) */
248-
avl_tree_rotate(tree, left_subtree,
249-
AVL_TREE_NODE_LEFT);
251+
avl_tree_rotate(tree, left_subtree, AVL_TREE_NODE_LEFT);
250252
}
251253

252254
/* Perform a right rotation. After this, the left child will
@@ -357,8 +359,8 @@ static AVLTreeNode *avl_tree_node_get_replacement(AVLTree *tree,
357359
/* Search down the tree, back towards the center. */
358360
result = node->children[side];
359361

360-
while (result->children[1-side] != NULL) {
361-
result = result->children[1-side];
362+
while (result->children[1 - side] != NULL) {
363+
result = result->children[1 - side];
362364
}
363365

364366
/* Unlink the result node, and hook in its remaining child
@@ -406,7 +408,7 @@ void avl_tree_remove_node(AVLTree *tree, AVLTreeNode *node)
406408
}
407409

408410
/* Copy references in the node into the swap node */
409-
for (i=0; i<2; ++i) {
411+
for (i = 0; i < 2; ++i) {
410412
swap_node->children[i] = node->children[i];
411413

412414
if (swap_node->children[i] != NULL) {
@@ -527,8 +529,7 @@ unsigned int avl_tree_num_entries(AVLTree *tree)
527529
}
528530

529531
static void avl_tree_to_array_add_subtree(AVLTreeNode *subtree,
530-
AVLTreeValue *array,
531-
int *index)
532+
AVLTreeValue *array, int *index)
532533
{
533534
if (subtree == NULL) {
534535
return;
@@ -566,4 +567,3 @@ AVLTreeValue *avl_tree_to_array(AVLTree *tree)
566567

567568
return array;
568569
}
569-

src/avl-tree.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ void avl_tree_free(AVLTree *tree);
137137
* key and value, or NULL if it was not possible
138138
* to allocate the new memory.
139139
*/
140-
AVLTreeNode *avl_tree_insert(AVLTree *tree, AVLTreeKey key,
141-
AVLTreeValue value);
140+
AVLTreeNode *avl_tree_insert(AVLTree *tree, AVLTreeKey key, AVLTreeValue value);
142141

143142
/**
144143
* Remove a node from a tree.

src/binary-heap.c

+9-13
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ int binary_heap_insert(BinaryHeap *heap, BinaryHeapValue value)
9090

9191
/* Double the table size */
9292
new_size = heap->alloced_size * 2;
93-
new_values = realloc(heap->values,
94-
sizeof(BinaryHeapValue) * new_size);
93+
new_values =
94+
realloc(heap->values, sizeof(BinaryHeapValue) * new_size);
9595

9696
if (new_values == NULL) {
9797
return 0;
@@ -163,25 +163,22 @@ BinaryHeapValue binary_heap_pop(BinaryHeap *heap)
163163
child1 = index * 2 + 1;
164164
child2 = index * 2 + 2;
165165

166-
if (child1 < heap->num_values
167-
&& binary_heap_cmp(heap,
168-
new_value,
169-
heap->values[child1]) > 0) {
166+
if (child1 < heap->num_values &&
167+
binary_heap_cmp(heap, new_value, heap->values[child1]) >
168+
0) {
170169

171170
/* Left child is less than the node. We need to swap
172171
* with one of the children, whichever is less. */
173-
if (child2 < heap->num_values
174-
&& binary_heap_cmp(heap,
175-
heap->values[child1],
172+
if (child2 < heap->num_values &&
173+
binary_heap_cmp(heap, heap->values[child1],
176174
heap->values[child2]) > 0) {
177175
next_index = child2;
178176
} else {
179177
next_index = child1;
180178
}
181179

182-
} else if (child2 < heap->num_values
183-
&& binary_heap_cmp(heap,
184-
new_value,
180+
} else if (child2 < heap->num_values &&
181+
binary_heap_cmp(heap, new_value,
185182
heap->values[child2]) > 0) {
186183

187184
/* Right child is less than the node. Swap with the
@@ -210,4 +207,3 @@ unsigned int binary_heap_num_entries(BinaryHeap *heap)
210207
{
211208
return heap->num_values;
212209
}
213-

src/binomial-heap.c

+14-21
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1818
1919
*/
2020

21+
#include <limits.h>
2122
#include <stdlib.h>
2223
#include <string.h>
23-
#include <limits.h>
2424

2525
#include "binomial-heap.h"
2626

@@ -31,25 +31,22 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3131

3232
typedef struct _BinomialTree BinomialTree;
3333

34-
struct _BinomialTree
35-
{
34+
struct _BinomialTree {
3635
BinomialHeapValue value;
3736
unsigned short order;
3837
unsigned short refcount;
3938
BinomialTree **subtrees;
4039
};
4140

42-
struct _BinomialHeap
43-
{
41+
struct _BinomialHeap {
4442
BinomialHeapType heap_type;
4543
BinomialHeapCompareFunc compare_func;
4644
unsigned int num_values;
4745
BinomialTree **roots;
4846
unsigned int roots_length;
4947
};
5048

51-
static int binomial_heap_cmp(BinomialHeap *heap,
52-
BinomialHeapValue data1,
49+
static int binomial_heap_cmp(BinomialHeap *heap, BinomialHeapValue data1,
5350
BinomialHeapValue data2)
5451
{
5552
if (heap->heap_type == BINOMIAL_HEAP_TYPE_MIN) {
@@ -81,7 +78,7 @@ static void binomial_tree_unref(BinomialTree *tree)
8178
* and free. */
8279
if (tree->refcount == 0) {
8380

84-
for (i=0; i<tree->order; ++i) {
81+
for (i = 0; i < tree->order; ++i) {
8582
binomial_tree_unref(tree->subtrees[i]);
8683
}
8784

@@ -135,7 +132,7 @@ static BinomialTree *binomial_tree_merge(BinomialHeap *heap,
135132
new_tree->subtrees[new_tree->order - 1] = tree2;
136133

137134
/* Add a reference to each of the subtrees we have referenced */
138-
for (i=0; i<new_tree->order; ++i) {
135+
for (i = 0; i < new_tree->order; ++i) {
139136
binomial_tree_ref(new_tree->subtrees[i]);
140137
}
141138

@@ -150,7 +147,7 @@ static void binomial_heap_merge_undo(BinomialTree **new_roots,
150147
{
151148
unsigned int i;
152149

153-
for (i=0; i<=count; ++i) {
150+
for (i = 0; i <= count; ++i) {
154151
binomial_tree_unref(new_roots[i]);
155152
}
156153

@@ -190,7 +187,7 @@ static int binomial_heap_merge(BinomialHeap *heap, BinomialHeap *other)
190187
new_roots_length = 0;
191188
carry = NULL;
192189

193-
for (i=0; i<max; ++i) {
190+
for (i = 0; i < max; ++i) {
194191

195192
/* Build up 'vals' as a list of all the values we must
196193
* merge at this step. */
@@ -235,9 +232,7 @@ static int binomial_heap_merge(BinomialHeap *heap, BinomialHeap *other)
235232

236233
/* Merge the first two values and carry to the
237234
* next iteration */
238-
new_carry = binomial_tree_merge(heap,
239-
vals[0],
240-
vals[1]);
235+
new_carry = binomial_tree_merge(heap, vals[0], vals[1]);
241236

242237
if (new_carry == NULL) {
243238

@@ -269,7 +264,7 @@ static int binomial_heap_merge(BinomialHeap *heap, BinomialHeap *other)
269264

270265
/* Unreference all values in the old 'roots' array, freeing unused
271266
* BinomialTree structures as necessary. */
272-
for (i=0; i<heap->roots_length; ++i) {
267+
for (i = 0; i < heap->roots_length; ++i) {
273268
if (heap->roots[i] != NULL) {
274269
binomial_tree_unref(heap->roots[i]);
275270
}
@@ -309,7 +304,7 @@ void binomial_heap_free(BinomialHeap *heap)
309304

310305
/* Unreference all trees in the heap. This should free
311306
* back all subtrees. */
312-
for (i=0; i<heap->roots_length; ++i) {
307+
for (i = 0; i < heap->roots_length; ++i) {
313308
binomial_tree_unref(heap->roots[i]);
314309
}
315310

@@ -374,15 +369,14 @@ BinomialHeapValue binomial_heap_pop(BinomialHeap *heap)
374369
/* Find the tree with the lowest root value */
375370
least_index = UINT_MAX;
376371

377-
for (i=0; i<heap->roots_length; ++i) {
372+
for (i = 0; i < heap->roots_length; ++i) {
378373

379374
if (heap->roots[i] == NULL) {
380375
continue;
381376
}
382377

383-
if (least_index == UINT_MAX
384-
|| binomial_heap_cmp(heap,
385-
heap->roots[i]->value,
378+
if (least_index == UINT_MAX ||
379+
binomial_heap_cmp(heap, heap->roots[i]->value,
386380
heap->roots[least_index]->value) < 0) {
387381
least_index = i;
388382
}
@@ -425,4 +419,3 @@ unsigned int binomial_heap_num_entries(BinomialHeap *heap)
425419
{
426420
return heap->num_values;
427421
}
428-

0 commit comments

Comments
 (0)