/usr/include/gecode/int/extensional/dfa.hpp is in libgecode-dev 5.1.0-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2004
*
* Last modified:
* $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
* $Revision: 14967 $
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <sstream>
namespace Gecode {
/**
* \brief Data stored for a %DFA
*
*/
class DFA::DFAI : public SharedHandle::Object {
public:
/// Number of states
int n_states;
/// Number of symbols
unsigned int n_symbols;
/// Number of transitions
int n_trans;
/// Maximal degree (in-degree and out-degree of any state) and maximal number of transitions per symbol
unsigned int max_degree;
/// First final state
int final_fst;
/// Last final state
int final_lst;
/// The transitions
Transition* trans;
/// Specification of transition range
class HashEntry {
public:
int symbol; ///< Symbol
const Transition* fst; ///< First transition for the symbol
const Transition* lst; ///< Last transition for the symbol
};
/// The transition hash table by symbol
HashEntry* table;
/// Size of table (as binary logarithm)
int n_log;
/// Fill hash table
GECODE_INT_EXPORT void fill(void);
/// Initialize automaton implementation with \a nt transitions
DFAI(int nt);
/// Initialize automaton implementation as empty
GECODE_INT_EXPORT DFAI(void);
/// Delete automaton implemenentation
virtual ~DFAI(void);
/// Create a copy
GECODE_INT_EXPORT virtual SharedHandle::Object* copy(void) const;
};
forceinline
DFA::DFAI::DFAI(int nt)
: trans(nt == 0 ? NULL : heap.alloc<Transition>(nt)) {}
forceinline
DFA::DFAI::~DFAI(void) {
if (n_trans > 0)
heap.rfree(trans);
heap.rfree(table);
}
forceinline
DFA::DFA(void) {}
forceinline
DFA::DFA(const DFA& d)
: SharedHandle(d) {}
forceinline int
DFA::n_states(void) const {
const DFAI* d = static_cast<DFAI*>(object());
return (d == NULL) ? 1 : d->n_states;
}
forceinline unsigned int
DFA::n_symbols(void) const {
const DFAI* d = static_cast<DFAI*>(object());
return (d == NULL) ? 0 : d->n_symbols;
}
forceinline int
DFA::n_transitions(void) const {
const DFAI* d = static_cast<DFAI*>(object());
return (d == NULL) ? 0 : d->n_trans;
}
forceinline unsigned int
DFA::max_degree(void) const {
const DFAI* d = static_cast<DFAI*>(object());
return (d == NULL) ? 0 : d->max_degree;
}
forceinline int
DFA::final_fst(void) const {
const DFAI* d = static_cast<DFAI*>(object());
return (d == NULL) ? 0 : d->final_fst;
}
forceinline int
DFA::final_lst(void) const {
const DFAI* d = static_cast<DFAI*>(object());
return (d == NULL) ? 0 : d->final_lst;
}
forceinline int
DFA::symbol_min(void) const {
const DFAI* d = static_cast<DFAI*>(object());
return ((d != NULL) && (d->n_trans > 0)) ?
d->trans[0].symbol : Int::Limits::min;
}
forceinline int
DFA::symbol_max(void) const {
const DFAI* d = static_cast<DFAI*>(object());
return ((d != NULL) && (d->n_trans > 0)) ?
d->trans[d->n_trans-1].symbol : Int::Limits::max;
}
/*
* Constructing transitions
*
*/
forceinline
DFA::Transition::Transition(void) {}
forceinline
DFA::Transition::Transition(int i_state0, int symbol0, int o_state0)
: i_state(i_state0), symbol(symbol0), o_state(o_state0) {}
/*
* Iterating over all transitions
*
*/
forceinline
DFA::Transitions::Transitions(const DFA& d) {
const DFAI* o = static_cast<DFAI*>(d.object());
if (o != NULL) {
c_trans = &o->trans[0];
e_trans = c_trans+o->n_trans;
} else {
c_trans = e_trans = NULL;
}
}
forceinline
DFA::Transitions::Transitions(const DFA& d, int n) {
const DFAI* o = static_cast<DFAI*>(d.object());
if (o != NULL) {
int mask = (1<<o->n_log)-1;
int p = n & mask;
while ((o->table[p].fst != NULL) && (o->table[p].symbol != n))
p = (p+1) & mask;
c_trans = o->table[p].fst;
e_trans = o->table[p].lst;
} else {
c_trans = e_trans = NULL;
}
}
forceinline bool
DFA::Transitions::operator ()(void) const {
return c_trans < e_trans;
}
forceinline void
DFA::Transitions::operator ++(void) {
c_trans++;
}
forceinline int
DFA::Transitions::i_state(void) const {
return c_trans->i_state;
}
forceinline int
DFA::Transitions::symbol(void) const {
return c_trans->symbol;
}
forceinline int
DFA::Transitions::o_state(void) const {
return c_trans->o_state;
}
/*
* Iterating over symbols
*
*/
forceinline
DFA::Symbols::Symbols(const DFA& d) {
const DFAI* o = static_cast<DFAI*>(d.object());
if (o != NULL) {
c_trans = &o->trans[0];
e_trans = c_trans+o->n_trans;
} else {
c_trans = e_trans = NULL;
}
}
forceinline bool
DFA::Symbols::operator ()(void) const {
return c_trans < e_trans;
}
forceinline void
DFA::Symbols::operator ++(void) {
int s = c_trans->symbol;
do {
c_trans++;
} while ((c_trans < e_trans) && (s == c_trans->symbol));
}
forceinline int
DFA::Symbols::val(void) const {
return c_trans->symbol;
}
template<class Char, class Traits>
std::basic_ostream<Char,Traits>&
operator <<(std::basic_ostream<Char,Traits>& os, const DFA& d) {
std::basic_ostringstream<Char,Traits> st;
st.copyfmt(os); st.width(0);
st << "Start state: 0" << std::endl
<< "States: 0..." << d.n_states()-1 << std::endl
<< "Transitions:";
for (int s = 0; s < static_cast<int>(d.n_states()); s++) {
DFA::Transitions t(d);
int n = 0;
while (t()) {
if (t.i_state() == s) {
if ((n % 4) == 0)
st << std::endl << "\t";
st << "[" << t.i_state() << "]"
<< "- " << t.symbol() << " >"
<< "[" << t.o_state() << "] ";
++n;
}
++t;
}
}
st << std::endl << "Final states: "
<< std::endl
<< "\t[" << d.final_fst() << "] ... ["
<< d.final_lst()-1 << "]"
<< std::endl;
return os << st.str();
}
}
// STATISTICS: int-prop
|