DDD  1.9.0.20240826145154
IntDataSet.h
Go to the documentation of this file.
1 /****************************************************************************/
2 /* */
3 /* This file is part of libDDD, a library for manipulation of DDD and SDD. */
4 /* */
5 /* Copyright (C) 2001-2008 Yann Thierry-Mieg, Jean-Michel Couvreur */
6 /* and Denis Poitrenaud */
7 /* */
8 /* This program is free software; you can redistribute it and/or modify */
9 /* it under the terms of the GNU Lesser General Public License as */
10 /* published by the Free Software Foundation; either version 3 of the */
11 /* License, or (at your option) any later version. */
12 /* This program is distributed in the hope that it will be useful, */
13 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
14 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
15 /* GNU LEsserGeneral Public License for more details. */
16 /* */
17 /* You should have received a copy of the GNU Lesser General Public License */
18 /* along with this program; if not, write to the Free Software */
19 /*Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
20 /* */
21 /****************************************************************************/
22 
23 #ifndef __INT_DATASET_H__
24 #define __INT_DATASET_H__
25 
26 #include <vector>
27 #include <algorithm>
28 #include <iterator>
29 #include <cassert>
30 #include <iostream>
31 
32 #include "ddd/DataSet.h"
33 #include "ddd/UniqueTable.h"
34 #include "ddd/util/hash_support.hh"
35 
38 class IntDataSet : public DataSet {
40  typedef canonical_t::Table::iterator canonical_it;
42 
43  typedef std::set<const std::vector<int> *> marktable_t;
44  typedef marktable_t::const_iterator marktable_it;
46 
47  static const std::vector<int> * empty_;
48 
49  const std::vector<int>* data;
50 
51 
52 
53  // private constructors
54  IntDataSet (const std::vector<int>* ddata): data(ddata) {};
55 
56 public :
58  typedef std::vector<int>::const_iterator const_iterator;
59 
61  const_iterator begin () const { return data->begin() ; }
62  const_iterator end () const { return data->end() ; }
63 
64 
66  IntDataSet (const std::vector<int> & ddata) {
67  std::vector<int> tmp = std::vector<int> (ddata);
68  sort( tmp.begin() , tmp.end() );
69  data = canonical( tmp );
70  }
71 
73  IntDataSet (const std::vector<int>::iterator & begin, const std::vector<int>::iterator & end) {
74  std::vector<int> ddata(begin,end);
75  std::vector<int> tmp = std::vector<int> (ddata);
76  sort( tmp.begin() , tmp.end() );
77  data = canonical( tmp );
78  }
79 
82  data = empty_ ;
83  }
84 
86  virtual ~IntDataSet() {};
88  DataSet *newcopy () const {
89  return new IntDataSet(data);
90  }
92  DataSet *set_intersect (const DataSet & b) const {
93  std::vector<int> res ;
94  const std::vector<int>* bvec = ((const IntDataSet &) b).data;
95  std::set_intersection(data->begin(), data->end(),bvec->begin(), bvec->end(),std::back_insert_iterator<std::vector<int> > (res));
96  // trim
97  std::vector<int> trimres = std::vector<int> (res);
98  assert (trimres.size() == trimres.capacity());
99  return new IntDataSet(canonical(trimres));
100  }
102  DataSet *set_union (const DataSet & b) const {
103  std::vector<int> res ;
104  const std::vector<int>* bvec = ((const IntDataSet &) b).data;
105  std::set_union(data->begin(), data->end(),bvec->begin(), bvec->end(),std::back_insert_iterator<std::vector<int> > (res));
106  // trim
107  std::vector<int> trimres = std::vector<int> (res);
108  assert (trimres.size() == trimres.capacity());
109  return new IntDataSet(canonical(trimres));
110  }
112  DataSet *set_minus (const DataSet & b) const {
113  std::vector<int> res ;
114  const std::vector<int>* bvec = ((const IntDataSet &) b).data;
115  std::set_difference(data->begin(), data->end(),bvec->begin(), bvec->end(),std::back_insert_iterator<std::vector<int> > (res));
116  // trim
117  std::vector<int> trimres = std::vector<int> (res);
118  assert (trimres.size() == trimres.capacity());
119  return new IntDataSet(canonical(trimres));
120  }
121 
123  bool empty() const {
124  return data == empty_;
125  }
127  DataSet *empty_set() const {
128  return new IntDataSet();
129  }
131  bool set_equal(const DataSet & b) const {
132  return data == ((const IntDataSet &) b).data;
133  }
135  bool set_less_than (const DataSet & b) const {
136  return data < ((const IntDataSet &) b).data;
137  }
139  long double set_size() const {
140  return data->size();
141  }
143  virtual size_t set_hash() const {
144  return d3::util::hash<std::vector<int>* > () (data);
145  }
147  virtual void set_print (std::ostream &os) const {
148  os << "[" ;
149  if (! data->empty() ) {
150  std::copy( data->begin(), --data->end(),
151  std::ostream_iterator<int>(os, ",") );
152  os << *(--data->end());
153  }
154  os << "]" ;
155  }
156 
157  // mark phase of mark and sweep : add the reference to the set of those that SHOULD NOT be collected
158  void mark() const { marktable.insert(data); }
159 
160 #ifdef EVDDD
161  DataSet *normalizeDistance(int n) const {
162  return new IntDataSet(data);
163  }
164  int getMinDistance() const {
165  return 0;
166  }
167 #endif
168 
169 
170  // Garbage collector
171  static void garbage () ;
172 
173 };
174 
175 
176 
177 
178 #endif // __INT_DATASET_H__
This class is an abstraction of a set of data.
Definition: DataSet.h:44
This class is a very basic implementation of DataSet interface based on std::std::vector<int> and a u...
Definition: IntDataSet.h:38
IntDataSet(const std::vector< int >::iterator &begin, const std::vector< int >::iterator &end)
public constructor from iterator (begin,end)
Definition: IntDataSet.h:73
static void garbage()
Definition: IntDataSet.cpp:35
std::set< const std::vector< int > * > marktable_t
Definition: IntDataSet.h:43
IntDataSet(const std::vector< int > *ddata)
Definition: IntDataSet.h:54
std::vector< int >::const_iterator const_iterator
typedef IntDataSet::const_iterator
Definition: IntDataSet.h:54
bool empty() const
returns true if this is the empty set
Definition: IntDataSet.h:123
IntDataSet(const std::vector< int > &ddata)
public constructor from non unique std::vector<int>
Definition: IntDataSet.h:66
DataSet * set_union(const DataSet &b) const
returns a new instance with elements = this union b
Definition: IntDataSet.h:102
DataSet * newcopy() const
returns a new instance copy of this
Definition: IntDataSet.h:88
const_iterator end() const
Definition: IntDataSet.h:62
DataSet * empty_set() const
returns a pointer to an instance of the empty set
Definition: IntDataSet.h:127
static const std::vector< int > * empty_
Definition: IntDataSet.h:47
long double set_size() const
Definition: IntDataSet.h:139
virtual size_t set_hash() const
returns a hash function, used in the SDD hash function computation
Definition: IntDataSet.h:143
bool set_equal(const DataSet &b) const
Compares two sets for equality.
Definition: IntDataSet.h:131
marktable_t::const_iterator marktable_it
Definition: IntDataSet.h:44
bool set_less_than(const DataSet &b) const
Compares two sets for equality.
Definition: IntDataSet.h:135
void mark() const
for memory management : if your DataSet references no GDD,GHom,GSDD,GShom, mark() should do nothing
Definition: IntDataSet.h:158
static marktable_t marktable
Definition: IntDataSet.h:45
const_iterator begin() const
read-only iterator interface
Definition: IntDataSet.h:61
virtual ~IntDataSet()
destructor
Definition: IntDataSet.h:86
const std::vector< int > * data
Definition: IntDataSet.h:49
IntDataSet()
public deafult constructor = empty set
Definition: IntDataSet.h:81
DataSet * set_intersect(const DataSet &b) const
returns a new instance with elements = this inter b
Definition: IntDataSet.h:92
DataSet * set_minus(const DataSet &b) const
returns a new instance with elements = this setminus b
Definition: IntDataSet.h:112
UniqueTable< std::vector< int > > canonical_t
Definition: IntDataSet.h:39
virtual void set_print(std::ostream &os) const
returns a formatted string description of the set
Definition: IntDataSet.h:147
canonical_t::Table::iterator canonical_it
Definition: IntDataSet.h:40
static canonical_t canonical
Definition: IntDataSet.h:41
This class implements a unicity table mechanism, based on an STL hash_set.
Definition: UniqueTable.h:43
Definition: hash_support.hh:40

Please comment this page and report errors about it on the RefDocComments page.
Generated on Mon Aug 26 2024 14:54:00 for DDD by doxygen 1.9.1