X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fheap.c;h=ddc1e84e6616b226d4699e7ab3b92361146d50d5;hb=199144b0297c3fc76d76c29e561151235e39f0af;hp=8d483352deb5c796578a01241700973c18af159b;hpb=c827059eeafc8cbe41c812b26979543ab287803e;p=ape.git diff --git a/src/heap.c b/src/heap.c index 8d48335..ddc1e84 100644 --- a/src/heap.c +++ b/src/heap.c @@ -1,7 +1,9 @@ -/*#include -#include -#include -#include "main.h"*/ +/* heap.c 2007-09-05 */ + +/* Copyright 2007 Vincent Lefort */ + +/* This file is part of the R-package `ape'. */ +/* See the file ../COPYING for licensing issues. */ #include "me.h" @@ -35,7 +37,7 @@ void swap(int *p, int *q, int i, int j) /*The usual Heapify function, tailored for our use with a heap of scores*/ /*will use array p to keep track of indexes*/ -/*after scoreHeapify is called, the subtree rooted at i +/*after scoreHeapify is called, the subtree rooted at i will be a heap*/ /*p goes from heap to array, q goes from array to heap*/ @@ -55,8 +57,8 @@ void heapify(int *p, int *q, double *HeapArray, int i, int n) if ((right <= n) && (HeapArray[p[right]] < HeapArray[p[smallest]])) smallest = right; if (smallest != i){ - swap(p,q,i, smallest); - /*push smallest up the heap*/ + swap(p,q,i, smallest); + /*push smallest up the heap*/ i = smallest; /*check next level down*/ } else @@ -64,7 +66,7 @@ void heapify(int *p, int *q, double *HeapArray, int i, int n) } while(moreswap); } -/*heap is of indices of elements of v, +/*heap is of indices of elements of v, popHeap takes the index at position i and pushes it out of the heap (by pushing it to the bottom of the heap, where it is not noticed)*/