heap.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, Maxim Likhachev
00003  * All rights reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  * 
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the University of Pennsylvania nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  * 
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 #ifndef __HEAP_H_
00030 #define __HEAP_H_
00031 
00032 //the maximum size of the heap
00033 #define HEAPSIZE 20000000 
00034 #define HEAPSIZE_INIT 5000
00035 
00036 struct HEAPELEMENT
00037 {
00038   AbstractSearchState *heapstate;
00039   CKey key;
00040 };
00041 typedef struct HEAPELEMENT heapelement;
00042 
00043 class CHeap
00044 {
00045 
00046 //data
00047 public:
00048   int percolates;               //for counting purposes
00049   heapelement* heap;
00050   int currentsize;
00051   int allocated;
00052 
00053 //constructors
00054 public:
00055   CHeap();
00056   ~CHeap();
00057 
00058 //functions
00059 public:
00060 
00061   bool emptyheap(); 
00062   bool fullheap();
00063   bool inheap(AbstractSearchState *AbstractSearchState);
00064   CKey getkeyheap(AbstractSearchState *AbstractSearchState);
00065   void makeemptyheap();
00066   void insertheap(AbstractSearchState *AbstractSearchState, CKey key);
00067   void deleteheap(AbstractSearchState *AbstractSearchState);
00068   void updateheap(AbstractSearchState *AbstractSearchState, CKey NewKey);
00069   AbstractSearchState *getminheap();
00070   AbstractSearchState *getminheap(CKey& ReturnKey);
00071   CKey getminkeyheap();
00072   AbstractSearchState *deleteminheap();
00073   void makeheap();
00074   void insert_unsafe(AbstractSearchState *state, CKey key);
00075   void updateheap_unsafe(AbstractSearchState *AbstractSearchState, CKey NewKey);
00076   void deleteheap_unsafe(AbstractSearchState *AbstractSearchState);
00077 
00078 
00079 private:
00080   void percolatedown(int hole, heapelement tmp);
00081   void percolateup(int hole, heapelement tmp);
00082   void percolateupordown(int hole, heapelement tmp);
00083 
00084   void growheap();
00085   void sizecheck();
00086 
00087 
00088 //operators
00089 public:
00090 
00091 };
00092 
00093 
00094 struct HEAPINTELEMENT
00095 {
00096   AbstractSearchState *heapstate;
00097   int key;
00098 };
00099 typedef struct HEAPINTELEMENT heapintelement;
00100 
00101 
00102 class CIntHeap
00103 {
00104 
00105 //data
00106 public:
00107   int percolates;               //for counting purposes
00108   heapintelement* heap;
00109   int currentsize;
00110   int allocated;
00111 
00112 //constructors
00113 public:
00114   CIntHeap();
00115   CIntHeap(int initial_size);
00116   ~CIntHeap();
00117 
00118 //functions
00119 public:
00120 
00121   bool emptyheap(); 
00122   bool fullheap();
00123   bool inheap(AbstractSearchState *AbstractSearchState);
00124   int getkeyheap(AbstractSearchState *AbstractSearchState);
00125   void makeemptyheap();
00126   void insertheap(AbstractSearchState *AbstractSearchState, int key);
00127   void deleteheap(AbstractSearchState *AbstractSearchState);
00128   void updateheap(AbstractSearchState *AbstractSearchState, int NewKey);
00129   AbstractSearchState *getminheap();
00130   AbstractSearchState *getminheap(int& ReturnKey);
00131   int getminkeyheap();
00132   AbstractSearchState *deleteminheap();
00133   void makeheap();
00134 
00135 private:
00136   void percolatedown(int hole, heapintelement tmp);
00137   void percolateup(int hole, heapintelement tmp);
00138   void percolateupordown(int hole, heapintelement tmp);
00139 
00140   void growheap();
00141   void sizecheck();
00142 
00143 
00144 //operators
00145 public:
00146 
00147 };
00148 
00149 
00150 #endif
00151 
00152 
00153 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


sbpl
Author(s): Maxim Likhachev/maximl@seas.upenn.edu
autogenerated on Fri Jan 18 2013 13:41:53