Changed _Bool to bool

This commit is contained in:
tedbullock 2007-09-25 02:02:45 +00:00
parent c5e7d8b6c3
commit 9368c8cbd4
2 changed files with 17 additions and 19 deletions

View File

@ -31,7 +31,6 @@
#include "config.h" #include "config.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#include <generic_types.h> #include <generic_types.h>
@ -40,12 +39,12 @@
struct Heap { struct Heap {
u_long array_size; u_long array_size;
u_long num_elements; u_long num_elements;
_Bool (*compare)(Any_Type, Any_Type); bool (*compare) (Any_Type, Any_Type);
Any_Type storage[]; /* c99 Flexible Array Member */ Any_Type storage[]; /* c99 Flexible Array Member */
}; };
struct Heap * struct Heap *
create_heap(u_long size, _Bool (*compare_callback) (Any_Type, Any_Type)) create_heap(u_long size, bool(*compare_callback) (Any_Type, Any_Type))
{ {
struct Heap *h; struct Heap *h;
@ -66,13 +65,13 @@ create_heap(u_long size, _Bool (*compare_callback) (Any_Type, Any_Type))
return h; return h;
} }
_Bool bool
is_heap_empty(struct Heap * h) is_heap_empty(struct Heap * h)
{ {
return h->num_elements == 0; return h->num_elements == 0;
} }
_Bool bool
is_heap_full(struct Heap * h) is_heap_full(struct Heap * h)
{ {
return h->array_size == h->num_elements; return h->array_size == h->num_elements;
@ -92,7 +91,7 @@ free_heap(struct Heap *h)
} }
#define PARENT(i) (i/2) #define PARENT(i) (i/2)
_Bool bool
insert(Any_Type a, struct Heap *h) insert(Any_Type a, struct Heap *h)
{ {
u_long i, parent; u_long i, parent;
@ -134,15 +133,15 @@ percolate(struct Heap *h, u_long hole)
} }
Any_Type Any_Type
remove_min(struct Heap * h) remove_min(struct Heap *h)
{ {
if(is_heap_empty(h)) if (is_heap_empty(h))
return (Any_Type) 0; return (Any_Type) 0;
else { else {
Any_Type min = h->storage[1]; Any_Type min = h->storage[1];
h->storage[1] = h->storage[h->num_elements--]; h->storage[1] = h->storage[h->num_elements--];
percolate(h, 1); percolate(h, 1);
return min; return min;
} }
} }
@ -150,7 +149,7 @@ remove_min(struct Heap * h)
Any_Type Any_Type
poll_min(struct Heap * h) poll_min(struct Heap * h)
{ {
if(is_heap_empty(h)) if (is_heap_empty(h))
return (Any_Type) 0; return (Any_Type) 0;
else else
return h->storage[1]; return h->storage[1];
@ -159,8 +158,7 @@ poll_min(struct Heap * h)
void void
heap_for_each(struct Heap *h, void (*action) (Any_Type)) heap_for_each(struct Heap *h, void (*action) (Any_Type))
{ {
for(u_long i = 1; i <= h->num_elements; i++) for (u_long i = 1; i <= h->num_elements; i++) {
{ (*action) (h->storage[i]);
(*action)(h->storage[i]);
} }
} }

View File

@ -33,18 +33,18 @@
struct Heap; struct Heap;
typedef _Bool (*heap_compare) (Any_Type, Any_Type); typedef bool(*heap_compare) (Any_Type, Any_Type);
typedef void (*heap_for_each_action) (Any_Type); typedef void (*heap_for_each_action) (Any_Type);
struct Heap *create_heap(u_long, heap_compare); struct Heap *create_heap(u_long, heap_compare);
_Bool is_heap_empty(struct Heap *); bool is_heap_empty(struct Heap *);
_Bool is_heap_full(struct Heap *); bool is_heap_full(struct Heap *);
u_long num_heap_elements(struct Heap *); u_long num_heap_elements(struct Heap *);
void free_heap(struct Heap *); void free_heap(struct Heap *);
_Bool insert(Any_Type, struct Heap *); bool insert(Any_Type, struct Heap *);
Any_Type remove_min(struct Heap *); Any_Type remove_min(struct Heap *);
Any_Type poll_min(struct Heap *); Any_Type poll_min(struct Heap *);
void heap_for_each(struct Heap *, heap_for_each_action); void heap_for_each(struct Heap *, heap_for_each_action);