Eneboo - Documentación para desarrolladores
src/hoard/src/heaplayers/experimental/cartesianheap.h
Ir a la documentación de este archivo.
00001 #ifndef _CARTESIANHEAP_H_
00002 #define _CARTESIANHEAP_H_
00003 
00004 //#include "heaplayers.h"
00005 //#include "treap.h"
00006 
00007 // NB: All objects are rounded up to at least the size of a treap node
00008 // (around 24 bytes on a 32-bit architecture).
00009 
00010 template <class SuperHeap>
00011 class CartesianHeap : public SuperHeap {
00012 
00013   // Provide a freelist wrapper for treap nodes.
00014   class MyTreap : public Treap<size_t, void *> {
00015   public:
00016     // class Node : public PerClassHeap<Treap<size_t, void *>::Node, FreelistHeap<SuperHeap> > {};
00017   };
00018 
00019 public:
00020 
00021   ~CartesianHeap (void) {
00022     // FIX ME
00023     // free everything from the treap.
00024   }
00025 
00026   void * malloc (size_t sz) {
00027     // Round sz up.
00028     sz = (sz < sizeof(MyTreap::Node)) ? sizeof(MyTreap::Node) : sz;
00029     MyTreap::Node * n = (MyTreap::Node *) treap.lookupGreater (sz);
00030     if (n != NULL) {
00031       assert (n->getValue() == (void *) n);
00032       void * ptr = n->getValue();
00033       treap.remove (n);
00034       // delete n; // onto a freelist
00035       return ptr;
00036     } else {
00037       return SuperHeap::malloc (sz);
00038     }
00039   }
00040 
00041   void free (void * ptr) {
00042     // MyTreap::Node * n = new MyTreap::Node; // from a freelist
00043     // cout << "n = " << (void *) n << endl;
00044     MyTreap::Node * n = (MyTreap::Node *) ptr;
00045     treap.insert (n, getSize(ptr), ptr, (unsigned int) ptr);
00046   }
00047 
00048   // Removes a pointer from the treap.
00049   void remove (void * ptr) {
00050     treap.remove ((MyTreap::Node *) ptr);
00051   }
00052     
00053 private:
00054 
00055   MyTreap treap;
00056 
00057 };
00058 
00059 #endif // _CARTESIANHEAP_H_
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'