Predator  [unstable] git snapshot
symcmp.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009-2010 Kamil Dudka <kdudka@redhat.com>
3  *
4  * This file is part of predator.
5  *
6  * predator is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * any later version.
10  *
11  * predator is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with predator. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef H_GUARD_SYM_CMP_H
21 #define H_GUARD_SYM_CMP_H
22 
23 /**
24  * @file symcmp.hh
25  * various algorithms for comparison of symbolic (sub-)heaps
26  */
27 
28 #include "symheap.hh"
29 #include <map>
30 #include <vector>
31 
32 /// either intra-heap or inter-heap value mapping
33 typedef TValMap TValMapBidir[2];
34 
35 /// @todo some dox
36 bool areEqual(
37  const SymHeap &sh1,
38  const SymHeap &sh2);
39 
40 inline bool checkNonPosValues(int a, int b)
41 {
42  if (0 < a && 0 < b)
43  // we'll need to properly compare positive values
44  return true;
45 
46  // non-positive values always have to match, bail out otherwise
47  return (a == b);
48 }
49 
50 template <typename TMap>
51 bool mapBidir(
52  TMap bMap[2],
53  const typename TMap::key_type v1,
54  const typename TMap::key_type v2)
55 {
56  // left-to-right check
57  TMap &ltr = bMap[/* ltr */ 0];
58  const typename TMap::iterator iter1 = ltr.find(v1);
59  if (iter1 != ltr.end())
60  // substitution already defined, check if it applies seamlessly
61  return iter1->second == v2;
62 
63  // right-to-left check
64  TMap &rtl = bMap[/* rtl */ 1];
65  const typename TMap::iterator iter2 = rtl.find(v2);
66  if (iter2 != rtl.end())
67  // substitution already defined, check if it applies seamlessly
68  return iter2->second == v1;
69 
70  // not found --> define a new substitution
71  ltr[v1] = v2;
72  rtl[v2] = v1;
73  return true;
74 }
75 
76 #endif /* H_GUARD_SYM_CMP_H */