SetHelper.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
24 //----------------------------------------------------------------------
25 #ifndef ICL_CORE_SET_HELPER_H_INCLUDED
26 #define ICL_CORE_SET_HELPER_H_INCLUDED
27 
28 #include <set>
29 
30 namespace icl_core {
31 
34 {
40 };
41 
43 
46 template <typename T, typename TCompare>
47 SetRelation setRelation(const std::set<T, TCompare>& s1, const std::set<T, TCompare>& s2)
48 {
49  bool equal = true;
50  bool super = true;
51  bool sub = true;
52  bool inter = false;
53  TCompare compare;
54  typename std::set<T, TCompare>::const_iterator i1 = s1.begin(), i2 = s2.begin();
55  while (i1 != s1.end() && i2 != s2.end())
56  {
57  if ((*i1) == (*i2))
58  {
59  inter = true; // Intersection found
60  ++i1, ++i2;
61  }
62  else
63  {
64  equal = false; // Unequal elements found, cannot be equal
65  if (compare(*i1, *i2))
66  {
67  sub = false; // *it is definitely not in other set, so we're no subset
68  ++i1;
69  }
70  else
71  {
72  super = false; // *other_it is definitely not in this set, so we're no superset
73  ++i2;
74  }
75  }
76  }
77  if (i1 != s1.end())
78  {
79  equal = false;
80  sub = false; // *it is definitely not in other set, so we're no subset
81  }
82  if (i2 != s2.end())
83  {
84  equal = false;
85  super = false; // *other_it is definitely not in this set, so we're no superset
86  }
87  if (equal) { return eSR_EQUAL; }
88  if (super) { return eSR_PROPER_SUPERSET; }
89  if (sub) { return eSR_PROPER_SUBSET; }
90  if (inter) { return eSR_INTERSECTION_NONEMPTY; }
91  return eSR_DISJUNCT;
92 }
93 
94 }
95 
96 #endif
#define ICL_CORE_VC_DEPRECATE
Definition: Deprecate.h:35
SetRelation
Helper enum to describe relations between sets.
Definition: SetHelper.h:33
ICL_CORE_VC_DEPRECATE SetRelation tSetRelation ICL_CORE_GCC_DEPRECATE
Definition: SetHelper.h:42
SetRelation setRelation(const std::set< T, TCompare > &s1, const std::set< T, TCompare > &s2)
Definition: SetHelper.h:47


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58