Neighborhood.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "MaxHeap.h"
  4. #include "utils.h"
  5. #define Point(i) (&(data[i * nFeatures]))
  6. void nbhSearchBruteForce(SearchParams * params) {
  7. pyWord i, j;
  8. pyReal d;
  9. // Berechne alle Distanzen
  10. for(i = 0; i < nPoints; i ++) {
  11. const pyReal *x = Point(i);
  12. for(j = i + 1; j < nPoints; j ++) {
  13. const pyReal * y = Point(j);
  14. d = distSquared(x, y, nFeatures);
  15. maxHeap_insert(&(params.nbhHeaps.heaps[i]), j, d);
  16. maxHeap_insert(&(params.nbhHeaps.heaps[j]), i, d);
  17. }
  18. }
  19. }
  20. void Neighborhood(const pyWord nbhSize, const pyWord nPoints, const pyWord nFeatures, const pyReal * data, pyWord * neighborhoods) {
  21. SearchParams params = {
  22. .nbhSize = nbhSize,
  23. .nPoints = nPoints,
  24. .nFeatures = nFeatures,
  25. .data = data,
  26. .neighborhoods = neighborhoods
  27. };
  28. if(initNbhHeaps(&params)) {
  29. return;
  30. }
  31. nbhSearchBruteForce(params);
  32. freeNbhHeaps(&params);
  33. }