libept
set.h
Go to the documentation of this file.
1 #ifndef TAGCOLL_UTILS_SET_H
2 #define TAGCOLL_UTILS_SET_H
3 
8 /*
9  * Copyright (C) 2003,2004,2005,2006 Enrico Zini <enrico@debian.org>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  */
25 
27 #include <set>
28 
29 namespace ept {
30 namespace debtags {
31 namespace coll {
32 namespace utils {
33 
34 template<typename T>
35 int set_distance(const std::set<T>& set1, const std::set<T>& set2)
36 {
37  int res = 0;
38  int intCount = 0;
39 
40  typename std::set<T>::const_iterator a = set1.begin();
41  typename std::set<T>::const_iterator b = set2.begin();
42 
43  while (a != set1.end() || b != set2.end())
44  if ((b == set2.end()) || (a != set1.end() && *a < *b))
45  {
46  res++;
47  a++;
48  }
49  else if ((a == set1.end()) || (b != set2.end() && *b < *a))
50  {
51  res++;
52  b++;
53  }
54  else
55  {
56  a++;
57  b++;
58  intCount++;
59  }
60 
61  return intCount ? res : -1;
62 }
63 
64 template<typename T>
65 bool set_contains(const std::set<T>& set1, const std::set<T>& set2)
66 {
67  typename std::set<T>::const_iterator b = set2.begin();
68 
69  for (typename std::set<T>::const_iterator a = set1.begin(); a != set1.end(); ++a)
70  if (b == set2.end())
71  return true;
72  else if (*a == *b)
73  b++;
74  else if (*b < *a)
75  return false;
76 
77  return b == set2.end();
78 }
79 
80 template<typename T>
81 bool set_contains(const std::set<T>& set1, const T& item)
82 {
83  return set1.find(item) != set1.end();
84 }
85 
86 }
87 }
88 }
89 }
90 
91 #endif
String functions.
Definition: apt.cc:38
bool set_contains(const std::set< T > &set1, const std::set< T > &set2)
Definition: set.h:65
int set_distance(const std::set< T > &set1, const std::set< T > &set2)
Definition: set.h:35
set< string > & res
Definition: packagerecord.cc:73