-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_funs.h
91 lines (82 loc) · 2.38 KB
/
helper_funs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright (C) 2005 M.J. Zaki <[email protected]> Rensselaer Polytechnic Institute
* Written by [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _HELPER_FUNS_H_
#define _HELPER_FUNS_H_
#include <functional>
#include <cstring>
#define HASHNS __gnu_cxx
/**
* \struct eqstr
* \brief function object which defines operator= for const char*
*/
struct eqstr
{
/**
* \fn bool operator() (const char* s1, const char* s2) const
* \brief returns true if s1 and s2 are the same sequence of characters
*/
bool operator()(const char* s1, const char* s2) const {
return strcmp(s1, s2) == 0;
}
}; //end struct eqstr
/**
* \struct eqint
* \brief function object which defines operator= for integer
*/
struct eqint
{
/**
* \fn bool operator() (int i1, int s2) const
* \brief returns true if i1 and i2 are the same integer
*/
bool operator()(int i1, int i2) const {
return i1 == i2;
}
}; //end struct eqint
/**
* \struct less_than
* \brief function object for comparing two patterns for less-than
*/
template<class PAT>
struct less_than
{
bool operator() (const PAT* p1, const PAT* p2) const {
return (*p1 < *p2);
}
};
template <typename PS>
struct PairCmp : std::binary_function<PS, PS, bool>{
bool operator()(const PS& p, const PS& q) const {
return ((p.first < q.first) || (p.first==q.first && p.second < q.second));
}
};
/**
* \struct hash_func
*/
template<class KEY>
struct hash_func
{ };
template <>
struct hash_func<std::string>:HASHNS::hash<const char*> {
size_t operator () (const std::string& x) const {
return this->HASHNS::hash<const char*>::operator () (x.c_str());
}
};
#endif