source: proiecte/swift/trunk/lib/hoard-371/src/heaplayers/experimental/binheap.h @ 176

Last change on this file since 176 was 176, checked in by (none), 14 years ago
  • imported repo from "guagal"
File size: 637 bytes
Line 
1/* -*- C++ -*- */
2
3#ifndef _BINHEAP_H_
4#define _BINHEAP_H_
5
6#include <stdio.h>
7
8
9template <int Bins[], int NumBins, class Super>
10class BinHeap {
11public:
12 
13  inline void * malloc (size_t sz) {
14    // Find bin.
15    int bin = findBin (sz);
16    void * ptr = myHeaps[bin].malloc (sz);
17    return ptr;
18  }
19 
20  inline void free (void * ptr) {
21    size_t sz = Super::size (ptr);
22    int bin = findBin (sz);
23    myHeaps[bin].free (ptr);
24  }
25
26private:
27
28  inline int findBin (size_t sz) {
29    int i;
30    for (i = 0; i < NumBins; i++) {
31      if (Bins[i] >= sz) {
32        break;
33      }
34    }
35    return i;
36  }
37
38  Super myHeaps[NumBins + 1];
39
40};
41
42#endif
Note: See TracBrowser for help on using the repository browser.