key.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 __KEY_H_
00030 #define __KEY_H_
00031 
00032 #define KEY_SIZE 2
00033 
00034 #define INFINITECOST 1000000000
00035 
00036 class CKey
00037 {
00038 //data
00039 public: 
00040         long int key[KEY_SIZE];
00041 
00042 //constructors
00043 public:
00044         CKey(){
00045 
00046 #if KEY_SIZE == 1
00047                 key[0] = 0;
00048 #elif KEY_SIZE == 2
00049                 key[0] = 0; key[1] = 0;
00050 #else
00051                 for(int i = 0; i < KEY_SIZE; i++)
00052                 {       
00053                         key[i] = 0;
00054                 }
00055 #endif
00056         };
00057         ~CKey(){};
00058 
00059 //functions
00060 public:
00061         void SetKeytoInfinity()
00062         {
00063                 for(int i = 0; i < KEY_SIZE; i++)
00064                 {       
00065                         key[i] = INFINITECOST;
00066                 }
00067         };
00068         void SetKeytoZero()
00069         {
00070                 for(int i = 0; i < KEY_SIZE; i++)
00071                 {       
00072                         key[i] = 0;
00073                 }
00074         };
00075         
00076 
00077 
00078 //operators
00079 public:
00080 
00081         void operator = (CKey RHSKey)
00082         {
00083                 //iterate through the keys
00084                 //the 0ht is the most important key
00085 
00086 #if KEY_SIZE == 1
00087                 key[0] = RHSKey.key[0];
00088 #elif KEY_SIZE == 2
00089                 key[0] = RHSKey.key[0]; key[1] = RHSKey.key[1];
00090 #else
00091                 for(int i = 0; i < KEY_SIZE; i++)
00092                         key[i] = RHSKey.key[i];
00093 #endif
00094 
00095         };
00096 
00097         CKey operator - (const CKey& RHSKey) const
00098         {
00099                 CKey RetKey;
00100 
00101                 //iterate through the keys
00102                 //the 0ht is the most important key
00103                 for(int i = 0; i < KEY_SIZE; i++)
00104                         RetKey.key[i] = key[i] - RHSKey.key[i];
00105 
00106                 return RetKey;
00107         };
00108 
00109 
00110         bool operator > (CKey& RHSKey)
00111         {
00112           //iterate through the keys
00113           //the 0ht is the most important key
00114 
00115 #if KEY_SIZE == 1
00116                 return (key[0] > RHSKey.key[0]);
00117 #elif KEY_SIZE == 2
00118                 return (key[0] > RHSKey.key[0] ||  (key[0] == RHSKey.key[0] && key[1] > RHSKey.key[1]));
00119 #else
00120           for(int i = 0; i < KEY_SIZE; i++)
00121             {
00122               //compare the current key
00123               if(key[i] > RHSKey.key[i])
00124                         return true;
00125               else if(key[i] < RHSKey.key[i])
00126                         return false;
00127             }     
00128           //all are equal
00129           return false;
00130 #endif
00131 
00132         };
00133 
00134         bool operator == (CKey& RHSKey)
00135         {
00136           //iterate through the keys
00137           //the 0ht is the most important key
00138 
00139 #if KEY_SIZE == 1
00140                 return (key[0] == RHSKey.key[0]);
00141 #elif KEY_SIZE == 2
00142                 return (key[0] == RHSKey.key[0] &&  key[1] == RHSKey.key[1]);
00143 #else
00144 
00145           for(int i = 0; i < KEY_SIZE; i++)
00146             {
00147               //compare the current key
00148               if(key[i] != RHSKey.key[i])
00149                         return false;
00150             }
00151           
00152           //all are equal
00153           return true;
00154 #endif
00155 
00156         };
00157 
00158         bool operator != (CKey& RHSKey)
00159         {
00160           return !(*this == RHSKey);
00161         };
00162 
00163         bool operator < (CKey& RHSKey)
00164         {       
00165           //iterate through the keys
00166           //the 0ht is the most important key
00167 
00168 #if KEY_SIZE == 1
00169                 return (key[0] < RHSKey.key[0]);
00170 #elif KEY_SIZE == 2
00171                 return (key[0] < RHSKey.key[0] ||  (key[0] == RHSKey.key[0] && key[1] < RHSKey.key[1]));
00172 #else
00173           for(int i = 0; i < KEY_SIZE; i++)
00174             {
00175               //compare the current key
00176               if(key[i] < RHSKey.key[i])
00177                         return true;
00178               else if(key[i] > RHSKey.key[i])
00179                         return false;
00180             }     
00181           //all are equal
00182           return false; 
00183 #endif
00184 
00185         };
00186 
00187         bool operator >= (CKey& RHSKey)
00188         {
00189           return !(*this < RHSKey);
00190         };
00191 
00192         bool operator <= (CKey& RHSKey)
00193         {
00194           return !(*this > RHSKey);
00195         };
00196         
00197         long int operator [] (int i)
00198         {
00199                 return key[i];
00200         };
00201 
00202 };
00203 
00204 
00205 
00206 #endif
 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