insertHa.c 976 B

12345678910111213141516171819202122232425262728293031323334
  1. /***********************************************************
  2. *
  3. * insertHa.c (for spread)
  4. * This routine is to insert a new cell into a heap. It is
  5. * a min_heap, the heap order is by the min_cost of cells,
  6. * and the min_cost of the heap root is always the SMALLEST.
  7. *
  8. ************************************************************/
  9. #include "costHa.h"
  10. #include "local_proto.h"
  11. void
  12. insertHa(float new_min_cost, float angle, int row, int col,
  13. struct costHa *heap, long *heap_len)
  14. {
  15. long vacant;
  16. vacant = ++*heap_len;
  17. while (vacant > 1 && new_min_cost < heap[vacant / 2].min_cost) {
  18. heap[vacant].min_cost = heap[vacant / 2].min_cost;
  19. heap[vacant].angle = heap[vacant / 2].angle;
  20. heap[vacant].row = heap[vacant / 2].row;
  21. heap[vacant].col = heap[vacant / 2].col;
  22. vacant = vacant / 2;
  23. }
  24. heap[vacant].min_cost = new_min_cost;
  25. heap[vacant].angle = angle;
  26. heap[vacant].row = row;
  27. heap[vacant].col = col;
  28. return;
  29. }