DDD  1.9.0.20240425101308
UniqueTable.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 /* -*- C++ -*- */
24 #ifndef UNIQUETABLE_H
25 #define UNIQUETABLE_H
26 
27 #include <cassert>
28 #include <vector>
29 #include "ddd/util/hash_support.hh"
30 #include "ddd/util/hash_set.hh"
31 
32 
33 #ifdef REENTRANT
34 #include "tbb/queuing_mutex.h"
35 #include "tbb/mutex.h"
36 #endif
37 
38 
39 
42 template<typename T>
44 
45 private:
46 
47 #ifdef REENTRANT
48  // typedef tbb::queuing_mutex table_mutex_t;
49  typedef tbb::mutex table_mutex_t;
50  table_mutex_t table_mutex_;
51 #endif
52 
53 public:
56 #ifdef REENTRANT
57  :
58  table_mutex_()
59 #endif
60  {
61 #ifndef REENTRANT
62 #ifndef USE_STD_HASH
63  table.set_deleted_key(NULL);
64 #endif
65 #endif
66  }
67 
68  UniqueTable(size_t s):
69 #ifdef REENTRANT
70  table_mutex_(),
71 #endif
72  table (s)
73  {
74 #ifndef REENTRANT
75 #ifndef USE_STD_HASH
76  table.set_deleted_key(NULL);
77 #endif
78 #endif
79  }
80 
84  Table table; // Unique table of GDDD
85 
86 /* Canonical */
91  const T*
92  operator()(const T &_g)
93  {
94 #ifdef REENTRANT
95  table_mutex_t::scoped_lock lock(table_mutex_);
96 #endif
97 
98  typename Table::const_iterator it = table.find(&_g);
99  if (it != table.end() ) {
100  return *it;
101  } else {
102  T * clone = unique::clone<T>() (_g);
103  std::pair<typename Table::iterator, bool> ref=table.insert(clone);
104  assert(ref.second);
105  ((void)ref);
106  return clone;
107  }
108  }
109 
111  size_t
112  size() const
113  {
114  return table.size();
115  }
116 
117 #ifdef HASH_STAT
118  std::map<std::string, size_t> get_hits() const { return table.get_hits(); }
119  std::map<std::string, size_t> get_misses() const { return table.get_misses(); }
120  std::map<std::string, size_t> get_bounces() const { return table.get_bounces(); }
121 #endif // HASH_STAT
122 };
123 
124 #endif
This class implements a unicity table mechanism, based on an STL hash_set.
Definition: UniqueTable.h:43
d3::hash_set< const T * >::type Table
Typedef helps hide implementation type (currently gnu gcc's hash_set).
Definition: UniqueTable.h:82
Table table
The actual table, operations on the UniqueTable are delegated on this.
Definition: UniqueTable.h:84
const T * operator()(const T &_g)
The application operator, returns the address of the value already in the table if it exists,...
Definition: UniqueTable.h:92
size_t size() const
Returns the current number of filled entries in the table.
Definition: UniqueTable.h:112
UniqueTable()
Constructor, builds a default table.
Definition: UniqueTable.h:55
UniqueTable(size_t s)
Definition: UniqueTable.h:68
google::sparse_hash_set< Key, Hash, Compare, Allocator > type
Definition: hash_set.hh:24
Definition: hash_support.hh:230

Please comment this page and report errors about it on the RefDocComments page.
Generated on Thu Apr 25 2024 10:15:16 for DDD by doxygen 1.9.1