The ChainCon Software (Release 0.03)
pair.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// A pair of elements.
6 ///
7 /////////////////////////////////////////////////////////////////////////////
8 
9 // Copyright (C) 2009-2016 by Pawel Pilarczyk.
10 //
11 // This file is part of my research software package. This is free software:
12 // you can redistribute it and/or modify it under the terms of the GNU
13 // General Public License as published by the Free Software Foundation,
14 // either version 3 of the License, or (at your option) any later version.
15 //
16 // This software is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this software; see the file "license.txt". If not,
23 // please, see <http://www.gnu.org/licenses/>.
24 
25 // Started on March 24, 2009. Last revision: March 6, 2011.
26 
27 
28 #ifndef _CHAINCON_PAIR_H_
29 #define _CHAINCON_PAIR_H_
30 
31 
32 // include some standard C++ header files
33 #include <istream>
34 #include <ostream>
35 #include <algorithm>
36 #include <vector>
37 
38 // include selected header files from the CHomP library
39 #include "chomp/system/config.h"
40 
41 
42 // --------------------------------------------------
43 // --------------- a pair of elements ---------------
44 // --------------------------------------------------
45 
46 /// A pair of elements of two (possibly different) types.
47 template <class LeftT, class RightT>
48 class tPair
49 {
50 public:
51  /// The default constructor of a pair.
52  tPair () {}
53 
54  /// The constructor of a pair composed of the two given elements.
55  tPair (const LeftT &leftElement, const RightT &rightElement):
56  left (leftElement), right (rightElement) {}
57 
58  /// The first element of the pair.
59  LeftT left;
60 
61  /// The second element of the pair.
62  RightT right;
63 
64 }; /* class tPair */
65 
66 // --------------------------------------------------
67 
68 /// Generates a hashing key no. 1 for a general pair of elements,
69 /// based on hashing keys of the elements.
70 /// This key is to be used in a hashed set.
71 template <class LeftT, class RightT>
72 inline int_t hashkey1 (const tPair<LeftT,RightT> &p)
73 {
74  return hashkey1 (p. left) ^ hashkey1 (p. right);
75 } /* hashkey1 */
76 
77 /// Generates a hashing key no. 2 for a general pair of elements,
78 /// based on hashing keys of the elements.
79 /// This key is to be used in a hashed set.
80 template <class LeftT, class RightT>
81 inline int_t hashkey2 (const tPair<LeftT,RightT> &p)
82 {
83  return hashkey2 (p. left) ^ hashkey2 (p. right);
84 } /* hashkey2 */
85 
86 /// Operator == for checking whether two pairs are equal.
87 template <class LeftT, class RightT>
88 inline bool operator == (const tPair<LeftT,RightT> &p1,
89  const tPair<LeftT,RightT> &p2)
90 {
91  return ((p1. left == p2. left) && (p1. right == p2. right));
92 } /* operator == */
93 
94 
95 #endif // _CHAINCON_PAIR_H_
96 
A pair of elements of two (possibly different) types.
Definition: pair.h:48
RightT right
The second element of the pair.
Definition: pair.h:62
tPair()
The default constructor of a pair.
Definition: pair.h:52
int_t hashkey2(const tPair< LeftT, RightT > &p)
Generates a hashing key no.
Definition: pair.h:81
tPair(const LeftT &leftElement, const RightT &rightElement)
The constructor of a pair composed of the two given elements.
Definition: pair.h:55
int_t hashkey1(const tPair< LeftT, RightT > &p)
Generates a hashing key no.
Definition: pair.h:72
LeftT left
The first element of the pair.
Definition: pair.h:59
bool operator==(const tPair< LeftT, RightT > &p1, const tPair< LeftT, RightT > &p2)
Operator == for checking whether two pairs are equal.
Definition: pair.h:88