spot  1.2.1a
sharedhashtable.hh
1 // Copyright (C) 2013 Laboratoire de Recherche et Développement
2 // de l'Epita (LRDE).
3 //
4 // This file is part of Spot, a model checking library.
5 //
6 // Spot is free software; you can redistribute it and/or modify it
7 // under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // Spot is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 // License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef SPOT_FASTTGBAALGOS_EC_CONCUR_SHAREDHASHTABLE_HH
20 # define SPOT_FASTTGBAALGOS_EC_CONCUR_SHAREDHASHTABLE_HH
21 
22 #include "fasttgba/fasttgba.hh"
23 #include <iosfwd>
24 #include <atomic>
25 
26 // For comparison def!
27 #include "uf.hh"
28 
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include "fasttgbaalgos/ec/concur/hashtable.h"
35 
36 #ifdef __cplusplus
37 } // extern "C"
38 #endif
39 
40 
43 namespace spot
44 {
46  {
47  public :
48  enum sharedvalues {
49  Alive_state = 1,
50  Dead_state = 2
51  };
52 
53 
55  sharedhashtable(int thread_number) : thread_number_(thread_number), size_(0)
56  {
57  (void) thread_number_;
58  effective_table_ = ht_alloc(&DATATYPE_INT_PTRINT, INIT_SCALE);
59  }
60 
62  virtual ~sharedhashtable()
63  {
64 
65  if (size_)
66  {
67  ht_print(effective_table_, true);
68  }
69 
70  ht_free(effective_table_);
71  }
72 
73 
74  const fasttgba_state* find_or_put(const fasttgba_state* key)
75  {
76  assert(key);
77  map_val_t old = 0;
78  map_key_t clone = 0;
79 
80  // Hashmap.insert(map, key, val, res, context)
81  // Ne pas inserer de clefs negatives
82  // Ne pas inserer de valeur negatives
83  old = ht_cas_empty (effective_table_, (map_key_t)key,
84  (map_val_t)Alive_state, &clone, (void*)NULL);
85 
86  // printf("key : %zu, clone : %zu,old : %zu \n",
87  // (size_t)key, (size_t)clone, (size_t)old);
88  if (old == DOES_NOT_EXIST)
89  {
90  ++size_;
91  return key;
92  }
93 
94  return (const fasttgba_state*) clone;
95  }
96 
97  void mark_dead(const fasttgba_state* )
98  {
99  assert(false);
100  // map_key_t clone = 0;
101  // ht_cas (effective_table_, (map_key_t)key, CAS_EXPECT_EXISTS,
102  // (map_val_t)Dead_state, &clone, NULL);
103  }
104 
105  bool is_dead(const fasttgba_state* key)
106  {
107  if (ht_get(effective_table_, (map_key_t) key) == DOES_NOT_EXIST)
108  return false;
109  return true;
110 
111  // map_val_t old = 0;
112  // old = ht_get(effective_table_, (map_key_t) key);
113  // if (old == DOES_NOT_EXIST)
114  // {
115  // return false;
116  // }
117  // // State is alive
118  // if (old == Alive_state)
119  // return false;
120 
121  // // Not alive
122  // return true;
123  }
124 
125 
126  int size()
127  {
128  return size_;
129  }
130 
131  private:
132  int thread_number_;
133  hashtable_t *effective_table_;
134  std::atomic<int> size_;
135  };
136 }
137 #endif // SPOT_FASTTGBAALGOS_EC_CONCUR_SHAREDHASHTABLE_HH
this class acts like a wrapper to the C code of the open_set.
Definition: public.hh:32
This class act as an interface for all classes.
Definition: fasttgba_state.hh:30
SPOT_API SPOT_DEPRECATED const formula * clone(const formula *f) __attribute__((deprecated))
Clone a formula.
virtual ~sharedhashtable()
Basic destructor.
Definition: sharedhashtable.hh:62
sharedhashtable(int thread_number)
Constructor.
Definition: sharedhashtable.hh:55
Definition: sharedhashtable.hh:45

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Fri Jun 5 2015 11:31:18 for spot by doxygen 1.8.9.1