#include <stdlib.h>
#include <stdio.h>

#include "Neighborhood.h"
#include "MaxHeap.h"



#ifdef DoTest
void printHeap(const MaxHeap * heap) {
    pyWord p;

    printf("%u / %u\n", (unsigned int)heap->size, (unsigned int)heap->maxItems);
    for(p = 0; p < heap->size; p ++) {
        printf("[%u] %u -> %lf\n", (unsigned int) p, (unsigned int)heap->indices[p], heap->distances[p]);
    }
}


int main(void) {
#define testcases 5
    pyReal distances[testcases];
    pyWord idxs[testcases];
    MaxHeap heap = {
        .distances = distances,
        .indices = idxs,
        .maxItems = testcases,
        .size = 1
    };

    distances[0] = 0.0;
    idxs[0] = 999;

    printHeap(&heap);
    maxHeap_insert(&heap, 6, 6.0);
    maxHeap_insert(&heap, 1, 1.0);
    maxHeap_insert(&heap, 4, 4.0);
    maxHeap_insert(&heap, 3, 3.0);
    maxHeap_insert(&heap, 2, 2.0);
    maxHeap_insert(&heap, 5, 5.0);
    printHeap(&heap);



#define nPoints 9
#define nbhSize 5
    pyWord nbh[nPoints * nbhSize];
    pyReal points[2 * nPoints];
    int x, y, p;
    p = 0;
    for(y = 0; y < 3 ; y ++) {
        for(x = 0; x < 3 ; x ++) {
            points[p] = x;
            points[p + 1] = y;
            printf("%d: (%d,%d)\n", p/2, x, y);
            p += 2;
        }
    }

    Neighborhood(nbhSize, nPoints, 2, points, nbh);
    for(y = 0; y < nPoints; y++) {
        pyWord * p = &nbh[y * nbhSize];
        printf("%d [%d,%d] ", y, y % 3, y / 3);
        for(x = 0; x < nbhSize ; x ++) {
            printf(" (%u|%u,%u)", (unsigned int)p[x], (unsigned int)(p[x] % 3), (unsigned int)(p[x] / 3));
        }
        printf("\n");
    }
}
#endif


