SetHelper.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00024 //----------------------------------------------------------------------
00025 #ifndef ICL_CORE_SET_HELPER_H_INCLUDED
00026 #define ICL_CORE_SET_HELPER_H_INCLUDED
00027 
00028 #include <set>
00029 
00030 namespace icl_core {
00031 
00033 enum SetRelation
00034 {
00035   eSR_EQUAL,
00036   eSR_PROPER_SUPERSET,
00037   eSR_PROPER_SUBSET,
00038   eSR_INTERSECTION_NONEMPTY,
00039   eSR_DISJUNCT
00040 };
00041 
00042 typedef ICL_CORE_VC_DEPRECATE SetRelation tSetRelation ICL_CORE_GCC_DEPRECATE;
00043 
00046 template <typename T, typename TCompare>
00047 SetRelation setRelation(const std::set<T, TCompare>& s1, const std::set<T, TCompare>& s2)
00048 {
00049   bool equal = true;
00050   bool super = true;
00051   bool sub = true;
00052   bool inter = false;
00053   TCompare compare;
00054   typename std::set<T, TCompare>::const_iterator i1 = s1.begin(), i2 = s2.begin();
00055   while (i1 != s1.end() && i2 != s2.end())
00056   {
00057     if ((*i1) == (*i2))
00058     {
00059       inter = true; // Intersection found
00060       ++i1, ++i2;
00061     }
00062     else
00063     {
00064       equal = false; // Unequal elements found, cannot be equal
00065       if (compare(*i1, *i2))
00066       {
00067         sub = false; // *it is definitely not in other set, so we're no subset
00068         ++i1;
00069       }
00070       else
00071       {
00072         super = false; // *other_it is definitely not in this set, so we're no superset
00073         ++i2;
00074       }
00075     }
00076   }
00077   if (i1 != s1.end())
00078   {
00079     equal = false;
00080     sub = false; // *it is definitely not in other set, so we're no subset
00081   }
00082   if (i2 != s2.end())
00083   {
00084     equal = false;
00085     super = false; // *other_it is definitely not in this set, so we're no superset
00086   }
00087   if (equal) { return eSR_EQUAL; }
00088   if (super) { return eSR_PROPER_SUPERSET; }
00089   if (sub) { return eSR_PROPER_SUBSET; }
00090   if (inter) { return eSR_INTERSECTION_NONEMPTY; }
00091   return eSR_DISJUNCT;
00092 }
00093 
00094 }
00095 
00096 #endif


fzi_icl_core
Author(s):
autogenerated on Tue Aug 8 2017 02:28:04