OpenCores
URL https://opencores.org/ocsvn/heap_sorter/heap_sorter/trunk

Subversion Repositories heap_sorter

[/] [heap_sorter/] [trunk/] [HLS_implementation/] [Fig2/] [wz_hsort.cc] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 wzab
#include <stdint.h>
2
#include <stdio.h>
3
#include <string.h>
4
#include "wz_hsort.h"
5
 
6
sort_data sort_mem[SORT_LEN];
7
sort_data heap_sort (sort_data val)
8
{
9
  sort_data res;
10
  sort_data cur = val;
11
  int lev, offs, top, left, right;
12
  cur = sort_mem[1];
13
  if (val.key <= cur.key)
14
    return val;                 //No need to update the heap
15
  else
16
    {
17
      res = cur;
18
      cur = val;
19
      offs = 0;
20
      for (lev = 1; lev <= NM; lev++)
21
        {
22
          top = (1 << (lev - 1)) + offs;
23
          left = (2 << (lev - 1)) + offs;
24
          right = (3 << (lev - 1)) + offs;
25
          if ((lev == NM) ||
26
              ((cur.key <= sort_mem[left].key) &&
27
               (cur.key <= sort_mem[right].key)))
28
            {
29
              sort_mem[top] = cur;
30
              break;
31
            }
32
          else if ((sort_mem[left].key < cur.key) &&
33
                   (sort_mem[left].key <= sort_mem[right].key))
34
            {
35
              sort_mem[top] = sort_mem[left];
36
            }
37
          else if (sort_mem[right].key < cur.key)
38
            {
39
              sort_mem[top] = sort_mem[right];
40
              offs += (1 << (lev - 1));
41
            }
42
          else
43
            {
44
              printf ("impossible!!!\n");
45
            }
46
        }
47
    }
48
  return res;
49
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.