Debian Codegraph @

Kernel/tFastSet.h

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2008-2015 Dmitry Tsarkov and The University of Manchester
3 Copyright (C) 2015-2017 Dmitry Tsarkov
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #ifndef TFASTSET_H
21 #define TFASTSET_Hcxx . . $ `Kernel/tFastSet.h:21:9`!
22
23 #include <algorithm>
24 #include <vector>
25
26 /// the implementation of the set with constant-time "in" check
27 template <typename T>
28 class TFastSetcxx . . $ TFastSet#
29 {
30 protected: // internal types
31 /// type for the array of values
32 typedef stdcxx . . $ std/::vectorcxx . . $ std/vector#<T> ValArraycxx . . $ TFastSet#ValArray#;
33 /// type of the index
34 typedef size_tcxx . . $ size_t# indexTypecxx . . $ TFastSet#indexType#;
35
36 public: // type interface
37 /// RW iterator on values
38 typedef typename ValArraycxx . . $ TFastSet#ValArray#::iterator iteratorcxx . . $ TFastSet#iterator#;
39 /// RO iterator on values
40 typedef typename ValArraycxx . . $ TFastSet#ValArray#::const_iterator const_iteratorcxx . . $ TFastSet#const_iterator#;
41
42 protected: // members
43 /// values to be kept in the set
44 ValArraycxx . . $ TFastSet#ValArray# Valuecxx . . $ TFastSet#Value.;
45 /// indices of the used values
46 stdcxx . . $ std/::vectorcxx . . $ std/vector#<indexTypecxx . . $ TFastSet#indexType#> Indexcxx . . $ TFastSet#Index.;
47
48 protected: // methods
49 /// transform element into an integer; is tunable
50 static indexTypecxx . . $ TFastSet#indexType# toIntcxx . . $ TFastSet#toInt(c6bf0951926639cd). ( const T& t ) { return static_cast<indexTypecxx . . $ TFastSet#indexType#>(t); }
51
52 public: // interface
53 /// ensure that the index can cope with sets not larger that SIZE
54 void ensureMaxSetSizecxx . . $ TFastSet#ensureMaxSetSize(2c44cd906ae4e829). ( size_tcxx . . $ size_t# size ) { Indexcxx . . $ TFastSet#Index..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(size); }
55 /// empty c'tor
56 TFastSetcxx . . $ TFastSet#`TFastSet<T>`(49f6e7a06ebc5aa8). ( void ) = default;
57 /// c'tor with a given max set SIZE
58 explicit TFastSetcxx . . $ TFastSet#`TFastSet<T>`(2c44cd906ae4e829). ( size_tcxx . . $ size_t# size ) { ensureMaxSetSizecxx . . $ TFastSet#ensureMaxSetSize(2c44cd906ae4e829).(size); }
59 /// copy c'tor
60 TFastSetcxx . . $ TFastSet#`TFastSet<T>`(e13a425d98c0bf2a). ( const TFastSet& ) = default;
61 /// move c'tor
62 TFastSetcxx . . $ TFastSet#`TFastSet<T>`(3aa39fe2f2171fbe). ( TFastSet&& ) = default;
63 /// assignment
64 TFastSet& operatorcxx . . $ TFastSet#`operator=`(f1fa096b121421f7). = ( const TFastSet& ) = default;
65 /// move assignment
66 TFastSet& operatorcxx . . $ TFastSet#`operator=`(996603dfac75a5d0). = ( TFastSet && ) = default;
67 /// reserve the set size to the SIZE elements
68 void reservecxx . . $ TFastSet#reserve(2c44cd906ae4e829). ( size_tcxx . . $ size_t# size ) { Valuecxx . . $ TFastSet#Value..reservecxx . . $ std/vector#reserve(2c44cd906ae4e829).(size); }
69
70 // set iterators
71
72 /// begin RW iterator
73 iteratorcxx . . $ TFastSet#iterator# begincxx . . $ TFastSet#begin(80289270cbe5e6a0). ( void ) { return Valuecxx . . $ TFastSet#Value..begincxx . . $ std/vector#begin(33b10a496a38335b).(); }
74 /// end RW iterator
75 iteratorcxx . . $ TFastSet#iterator# endcxx . . $ TFastSet#end(80289270cbe5e6a0). ( void ) { return Valuecxx . . $ TFastSet#Value..endcxx . . $ std/vector#end(359ca5030082c9f).(); }
76 /// begin RO iterator
77 const_iteratorcxx . . $ TFastSet#const_iterator# begincxx . . $ TFastSet#begin(7fbc76ecd1fff2b4). ( void ) const { return Valuecxx . . $ TFastSet#Value..begincxx . . $ std/vector#begin(33b10a496a38335b).(); }
78 /// end RO iterator
79 const_iteratorcxx . . $ TFastSet#const_iterator# endcxx . . $ TFastSet#end(7fbc76ecd1fff2b4). ( void ) const { return Valuecxx . . $ TFastSet#Value..endcxx . . $ std/vector#end(33b10a496a38335b).(); }
80
81 // set operations -- containment
82
83 /// check whether T is in set
84 bool incxx . . $ TFastSet#in(8877ebe272b9620d). ( const T& t ) const
85 {
86 auto index = Indexcxx . . $ TFastSet#Index.[toIntcxx . . $ TFastSet#toInt(c6bf0951926639cd).(t)];
87 return index < Valuecxx . . $ TFastSet#Value..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).() && Valuecxx . . $ TFastSet#Value.[index] == t;
88 }
89 /// check whether FS contains all the elements from the given set
90 bool operatorcxx . . $ TFastSet#`operator<=`(f34749ab5625b95a). <= ( const TFastSet& fs ) const
91 {
92 return stdcxx . . $ std/::all_ofcxx . . $ std/all_of(f82cc6ce9cd000ea). ( begincxx . . $ TFastSet#begin(7fbc76ecd1fff2b4).(), endcxx . . $ TFastSet#end(80289270cbe5e6a0).(), [&] (const T& val) { return fs.incxx . . $ TFastSet#in(8877ebe272b9620d).(val); } );
93 }
94 /// check whether given set contains all the elements from FS
95 bool operatorcxx . . $ TFastSet#`operator>=`(f34749ab5625b95a). >= ( const TFastSet& fs ) const { return fs <= *this; }
96 /// equality of the sets
97 bool operatorcxx . . $ TFastSet#`operator==`(f34749ab5625b95a). == ( const TFastSet& fs ) const { return sizecxx . . $ TFastSet#size(fe4d2d262d4164a8).() == fs.sizecxx . . $ TFastSet#size(fe4d2d262d4164a8).() && (*this <= fs); }
98 /// strict containment
99 bool operatorcxx . . $ TFastSet#`operator<`(f34749ab5625b95a). < ( const TFastSet& fs ) const { return sizecxx . . $ TFastSet#size(fe4d2d262d4164a8).() < fs.sizecxx . . $ TFastSet#size(fe4d2d262d4164a8).() && (*this <= fs); }
100 /// strict containment
101 bool operatorcxx . . $ TFastSet#`operator>`(f34749ab5625b95a). > ( const TFastSet& fs ) const { return fs < *this; }
102
103 // set operations -- adding
104
105 /// add an element T to a set; assume T is not in the set (unique)
106 void adducxx . . $ TFastSet#addu(77d9f17553126ecb). ( const T& t )
107 {
108 Indexcxx . . $ TFastSet#Index.[toIntcxx . . $ TFastSet#toInt(c6bf0951926639cd).(t)] = Valuecxx . . $ TFastSet#Value..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).();
109 Valuecxx . . $ TFastSet#Value..emplace_backcxx . . $ std/vector#emplace_back(b3d147e3bb711c35).(t);
110 }
111 /// add element T to a set
112 void addcxx . . $ TFastSet#add(77d9f17553126ecb). ( const T& t ) { if ( !incxx . . $ TFastSet#in(8877ebe272b9620d).(t) ) adducxx . . $ TFastSet#addu(77d9f17553126ecb).(t); }
113
114 // misc
115
116 /// check whether the set is empty
117 bool emptycxx . . $ TFastSet#empty(50ce9a9e25b4a850). ( void ) const { return Valuecxx . . $ TFastSet#Value..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).(); }
118 /// get the size of the set
119 size_tcxx . . $ size_t# sizecxx . . $ TFastSet#size(fe4d2d262d4164a8). ( void ) const { return Valuecxx . . $ TFastSet#Value..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).(); }
120 /// clear the set
121 void clearcxx . . $ TFastSet#clear(49f6e7a06ebc5aa8). ( void ) { Valuecxx . . $ TFastSet#Value..clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).(); }
122 /// set the size of the set to be a VALUE
123 void resizecxx . . $ TFastSet#resize(2c44cd906ae4e829). ( size_tcxx . . $ size_t# value ) { Valuecxx . . $ TFastSet#Value..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(value); }
124 }; // TFastSet
125
126 #endif