• Main Page
  • Classes
  • Files
  • File List
  • File Members

chaincon/pair.h

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 ///
00003 /// \file
00004 ///
00005 /// A pair of elements.
00006 ///
00007 /////////////////////////////////////////////////////////////////////////////
00008 
00009 // Copyright (C) 2009-2011 by Pawel Pilarczyk.
00010 //
00011 // This file is part of my research software package. This is free software:
00012 // you can redistribute it and/or modify it under the terms of the GNU
00013 // General Public License as published by the Free Software Foundation,
00014 // either version 3 of the License, or (at your option) any later version.
00015 //
00016 // This software is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU General Public License
00022 // along with this software; see the file "license.txt". If not,
00023 // please, see <http://www.gnu.org/licenses/>.
00024 
00025 // Started on March 24, 2009. Last revision: March 6, 2011.
00026 
00027 
00028 #ifndef _CHAINCON_PAIR_H_
00029 #define _CHAINCON_PAIR_H_
00030 
00031 
00032 // include some standard C++ header files
00033 #include <istream>
00034 #include <ostream>
00035 #include <algorithm>
00036 #include <vector>
00037 
00038 // include selected header files from the CHomP library
00039 #include "chomp/system/config.h"
00040 
00041 
00042 // --------------------------------------------------
00043 // --------------- a pair of elements ---------------
00044 // --------------------------------------------------
00045 
00046 /// A pair of elements of two (possibly different) types.
00047 template <class LeftT, class RightT>
00048 class tPair
00049 {
00050 public:
00051         /// The default constructor of a pair.
00052         tPair () {}
00053 
00054         /// The constructor of a pair composed of the two given elements.
00055         tPair (const LeftT &leftElement, const RightT &rightElement):
00056                 left (leftElement), right (rightElement) {}
00057 
00058         /// The first element of the pair.
00059         LeftT left;
00060 
00061         /// The second element of the pair.
00062         RightT right;
00063 
00064 }; /* class tPair */
00065 
00066 // --------------------------------------------------
00067 
00068 /// Generates a hashing key no. 1 for a general pair of elements,
00069 /// based on hashing keys of the elements.
00070 /// This key is to be used in a hashed set.
00071 template <class LeftT, class RightT>
00072 inline int_t hashkey1 (const tPair<LeftT,RightT> &p)
00073 {
00074         return hashkey1 (p. left) ^ hashkey1 (p. right);
00075 } /* hashkey1 */
00076 
00077 /// Generates a hashing key no. 2 for a general pair of elements,
00078 /// based on hashing keys of the elements.
00079 /// This key is to be used in a hashed set.
00080 template <class LeftT, class RightT>
00081 inline int_t hashkey2 (const tPair<LeftT,RightT> &p)
00082 {
00083         return hashkey2 (p. left) ^ hashkey2 (p. right);
00084 } /* hashkey2 */
00085 
00086 /// Operator == for checking whether two pairs are equal.
00087 template <class LeftT, class RightT>
00088 inline bool operator == (const tPair<LeftT,RightT> &p1,
00089         const tPair<LeftT,RightT> &p2)
00090 {
00091         return ((p1. left == p2. left) && (p1. right == p2. right));
00092 } /* operator == */
00093 
00094 
00095 #endif // _CHAINCON_PAIR_H_
00096 

Generated on Tue Apr 5 2011 00:06:32 for Chain Contraction Software by  doxygen 1.7.2