UnCoVer (Using Coverability for Verification)
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Mapping.h
1 /***************************************************************************
2  * Copyright (C) 2005 by SZS *
3  * Copyright (C) 2014 by Jan Stückrath <jan.stueckrath@uni-due.de> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA *
19  ***************************************************************************/
20 
21 #ifndef DATA_STRUCTURESMATCH_H
22 #define DATA_STRUCTURESMATCH_H
23 
24 #include "../basic_types/globals.h"
25 #include "../basic_types/IDPartition.h"
26 
27 namespace uncover {
28  namespace graphs {
29 
36  class Mapping
37  {
38 
39  public:
40 
44  typedef unordered_map<IDType,IDType>::iterator iterator;
45 
49  typedef unordered_map<IDType,IDType>::const_iterator const_iterator;
50 
55  typedef unordered_map<IDType, unordered_set<IDType>> Inversion;
56 
60  Mapping();
61 
65  ~Mapping();
66 
72  bool delSrc(IDType const& source);
73 
80  size_t delSrc(unordered_set<IDType> const& sources);
81 
87  size_t delTar(IDType const& target);
88 
94  size_t delTar(unordered_set<IDType> const& targets);
95 
101  bool hasSrc(IDType const& source) const;
102 
108  bool hasTar(IDType const& target) const;
109 
115  IDType const& getTar(IDType const& source) const;
116 
123  void concat(Mapping const& map);
124 
132  IDType& operator[](IDType const& src);
133 
139  unordered_set<IDType> getInverseMatch(IDType const& tar) const;
140 
148 
155  void getInverseMatch(Mapping::Inversion& invmatch) const;
156 
161  bool isInjective() const;
162 
168  Mapping::iterator begin() noexcept;
169 
175  Mapping::const_iterator begin() const noexcept;
176 
182  Mapping::const_iterator cbegin() const noexcept;
183 
189  Mapping::iterator end() noexcept;
190 
196  Mapping::const_iterator end() const noexcept;
197 
203  Mapping::const_iterator cend() const noexcept;
204 
208  void clear();
209 
216  friend std::ostream& operator<<(std::ostream& ost, Mapping const& map);
217 
224  friend bool operator==(const Mapping& m1, const Mapping& m2 );
225 
226  private:
227 
231  unordered_map<IDType, IDType> match;
232 
233  };
234 
238  typedef shared_ptr<Mapping> Mapping_sp;
239 
243  typedef shared_ptr<Mapping const> Mapping_csp;
244 
245  }
246 }
247 
248 #endif
void clear()
Removes all pairs stores in this Mapping.
Definition: Mapping.cpp:186
IDType & operator[](IDType const &src)
Returns the ID to which the given ID is mapped.
Definition: Mapping.cpp:169
Mapping::iterator begin() noexcept
Returns an iterator to the first element of this Mapping.
Definition: Mapping.cpp:145
Mapping()
Generates a new empty Mapping object.
Definition: Mapping.cpp:29
This is the data structure representing a morphism mapping from a graph to another graph...
Definition: Mapping.h:36
bool hasSrc(IDType const &source) const
Returns whether the given ID is mapped to some ID by this Mapping.
Definition: Mapping.cpp:111
Mapping::const_iterator cend() const noexcept
Returns a const_iterator pointing beyond the last element of this Mapping.
Definition: Mapping.cpp:165
unordered_map< IDType, IDType >::const_iterator const_iterator
A const_iterator for enumerating all (IDType,IDType)-pairs stores in this Mapping.
Definition: Mapping.h:49
shared_ptr< Mapping const > Mapping_csp
Alias for a shared pointer to a constant Mapping object.
Definition: Mapping.h:243
IDType const & getTar(IDType const &source) const
Returns the ID to which the given ID is mapped.
Definition: Mapping.cpp:56
size_t delTar(IDType const &target)
Removes all mappings to the target ID.
Definition: Mapping.cpp:73
bool delSrc(IDType const &source)
Removes the mapping for the given ID, if it exists.
Definition: Mapping.cpp:60
unordered_map< IDType, IDType >::iterator iterator
An iterator for enumerating all (IDType,IDType)-pairs stores in this Mapping.
Definition: Mapping.h:44
unordered_map< IDType, unordered_set< IDType > > Inversion
Alias for an inverse Mapping, mapping IDs to collections of IDs.
Definition: Mapping.h:55
~Mapping()
Destroys this Mapping.
Definition: Mapping.cpp:31
shared_ptr< Mapping > Mapping_sp
Alias for a shared pointer to a Mapping object.
Definition: Mapping.h:238
Mapping::Inversion getInverseMatch() const
Returns an Inversion of this Mapping.
Definition: Mapping.cpp:43
Mapping::iterator end() noexcept
Returns an iterator pointing beyond the last element of this Mapping.
Definition: Mapping.cpp:157
Mapping::const_iterator cbegin() const noexcept
Returns a const_iterator to the first element of this Mapping.
Definition: Mapping.cpp:149
bool hasTar(IDType const &target) const
Returns whether some ID is mapped to the given ID by this Mapping.
Definition: Mapping.cpp:116
void concat(Mapping const &map)
Concatenates the given Mapping to the right of this Mapping, effectively changing this Mapping...
Definition: Mapping.cpp:125
unsigned int IDType
IDType is an (unsigned) integer specifically used as an Identifier of graphs, elements of graphs or a...
Definition: globals.h:53
bool isInjective() const
Returns whether this Mapping is injective on all IDs on which it is defined.
Definition: Mapping.cpp:173
unordered_map< IDType, IDType > match
Stores the data of this Mapping.
Definition: Mapping.h:231