diff options
author | Vicent Marti <tanoku@gmail.com> | 2011-09-19 03:34:49 +0300 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2011-09-19 03:34:49 +0300 |
commit | 87d9869fc30951cec632e0d6a3d1dd47756d2886 (patch) | |
tree | ad39ac1e487e2d5baa64d7fa979122541f6b8bcb /src/pqueue.c | |
parent | bb742ede3d54564ff900fb7246e7b1ff01482b2c (diff) | |
download | libgit2-87d9869fc30951cec632e0d6a3d1dd47756d2886.tar.gz |
Tabify everything
There were quite a few places were spaces were being used instead of
tabs. Try to catch them all. This should hopefully not break anything.
Except for `git blame`. Oh well.
Diffstat (limited to 'src/pqueue.c')
-rw-r--r-- | src/pqueue.c | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/src/pqueue.c b/src/pqueue.c index a244ed739..b5ddab835 100644 --- a/src/pqueue.c +++ b/src/pqueue.c @@ -8,29 +8,29 @@ #include "common.h" #include "pqueue.h" -#define left(i) ((i) << 1) -#define right(i) (((i) << 1) + 1) +#define left(i) ((i) << 1) +#define right(i) (((i) << 1) + 1) #define parent(i) ((i) >> 1) int git_pqueue_init(git_pqueue *q, size_t n, git_pqueue_cmp cmppri) { assert(q); - /* Need to allocate n+1 elements since element 0 isn't used. */ - if ((q->d = malloc((n + 1) * sizeof(void *))) == NULL) + /* Need to allocate n+1 elements since element 0 isn't used. */ + if ((q->d = malloc((n + 1) * sizeof(void *))) == NULL) return GIT_ENOMEM; - q->size = 1; - q->avail = q->step = (n + 1); /* see comment above about n+1 */ - q->cmppri = cmppri; + q->size = 1; + q->avail = q->step = (n + 1); /* see comment above about n+1 */ + q->cmppri = cmppri; - return GIT_SUCCESS; + return GIT_SUCCESS; } void git_pqueue_free(git_pqueue *q) { - free(q->d); + free(q->d); q->d = NULL; } @@ -41,101 +41,101 @@ void git_pqueue_clear(git_pqueue *q) size_t git_pqueue_size(git_pqueue *q) { - /* queue element 0 exists but doesn't count since it isn't used. */ - return (q->size - 1); + /* queue element 0 exists but doesn't count since it isn't used. */ + return (q->size - 1); } static void bubble_up(git_pqueue *q, size_t i) { - size_t parent_node; - void *moving_node = q->d[i]; + size_t parent_node; + void *moving_node = q->d[i]; - for (parent_node = parent(i); - ((i > 1) && q->cmppri(q->d[parent_node], moving_node)); - i = parent_node, parent_node = parent(i)) { - q->d[i] = q->d[parent_node]; - } + for (parent_node = parent(i); + ((i > 1) && q->cmppri(q->d[parent_node], moving_node)); + i = parent_node, parent_node = parent(i)) { + q->d[i] = q->d[parent_node]; + } - q->d[i] = moving_node; + q->d[i] = moving_node; } static size_t maxchild(git_pqueue *q, size_t i) { - size_t child_node = left(i); + size_t child_node = left(i); - if (child_node >= q->size) - return 0; + if (child_node >= q->size) + return 0; - if ((child_node + 1) < q->size && - q->cmppri(q->d[child_node], q->d[child_node + 1])) - child_node++; /* use right child instead of left */ + if ((child_node + 1) < q->size && + q->cmppri(q->d[child_node], q->d[child_node + 1])) + child_node++; /* use right child instead of left */ - return child_node; + return child_node; } static void percolate_down(git_pqueue *q, size_t i) { - size_t child_node; - void *moving_node = q->d[i]; + size_t child_node; + void *moving_node = q->d[i]; - while ((child_node = maxchild(q, i)) != 0 && - q->cmppri(moving_node, q->d[child_node])) { - q->d[i] = q->d[child_node]; - i = child_node; - } + while ((child_node = maxchild(q, i)) != 0 && + q->cmppri(moving_node, q->d[child_node])) { + q->d[i] = q->d[child_node]; + i = child_node; + } - q->d[i] = moving_node; + q->d[i] = moving_node; } int git_pqueue_insert(git_pqueue *q, void *d) { - void *tmp; - size_t i; - size_t newsize; + void *tmp; + size_t i; + size_t newsize; - if (!q) return 1; + if (!q) return 1; - /* allocate more memory if necessary */ - if (q->size >= q->avail) { - newsize = q->size + q->step; - if ((tmp = realloc(q->d, sizeof(void *) * newsize)) == NULL) - return GIT_ENOMEM; + /* allocate more memory if necessary */ + if (q->size >= q->avail) { + newsize = q->size + q->step; + if ((tmp = realloc(q->d, sizeof(void *) * newsize)) == NULL) + return GIT_ENOMEM; - q->d = tmp; - q->avail = newsize; - } + q->d = tmp; + q->avail = newsize; + } - /* insert item */ - i = q->size++; - q->d[i] = d; - bubble_up(q, i); + /* insert item */ + i = q->size++; + q->d[i] = d; + bubble_up(q, i); - return GIT_SUCCESS; + return GIT_SUCCESS; } void *git_pqueue_pop(git_pqueue *q) { - void *head; + void *head; - if (!q || q->size == 1) - return NULL; + if (!q || q->size == 1) + return NULL; - head = q->d[1]; - q->d[1] = q->d[--q->size]; - percolate_down(q, 1); + head = q->d[1]; + q->d[1] = q->d[--q->size]; + percolate_down(q, 1); - return head; + return head; } void *git_pqueue_peek(git_pqueue *q) { - if (!q || q->size == 1) - return NULL; - return q->d[1]; + if (!q || q->size == 1) + return NULL; + return q->d[1]; } |