Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

pn_state Class Reference

Encapsulation of a compressed_marking in a spot::state. More...

Inheritance diagram for pn_state:

Inheritance graph
[legend]
Collaboration diagram for pn_state:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 pn_state (const marking &m)
 Construct a pn_state encapsulating the marking m.
int compare (const state *other) const
 Compare two states (issued of a same Petri net).
size_t hash () const
 Hash a state.
state * clone () const
 Duplicate a state.
const compressed_markingget_marking () const
 Return the encapsulated compressed marking.

Private Attributes

compressed_marking ma
 The encapsulated marking is stored compressed.

Detailed Description

Encapsulation of a compressed_marking in a spot::state.

Definition at line 31 of file pnstate.hh.


Constructor & Destructor Documentation

pn_state::pn_state const marking m  ) 
 

Construct a pn_state encapsulating the marking m.

pn_state::pn_state(const marking& m) : spot::state(), ma(m) {
} //


Member Function Documentation

state* pn_state::clone  )  const [virtual]
 

Duplicate a state.

spot::state* pn_state::clone() const {
  pn_state *m = new pn_state(*this);
  return m;
} //

Implements spot::state.

int pn_state::compare const state *  other  )  const [virtual]
 

Compare two states (issued of a same Petri net).

This method returns an integer less than, equal to, or greater than zero if this is found, respectively, to be less than, equal to, or greater than other according to bit vector lexicographic order.

This method should not be called to compare states from different automata.

int pn_state::compare(const state* other) const {
  const pn_state* m = dynamic_cast<const pn_state*>(other);
  assert(m);
  
  const std::vector<bool>& b1 = ma.get_vector();
  const std::vector<bool>& b2 = m->ma.get_vector();
  if (b1.size() < b2.size()) 
    return -1;
  if (b1.size() > b2.size())
    return 1; 
  
  std::pair<std::vector<bool>::const_iterator,
std::vector<bool>::const_iterator> 
      res = std::mismatch(b1.begin(), b1.end(), b2.begin());
  
  if (res.first==b1.end())
    return 0;
  if (*(res.first) && !(*(res.second)))
    return 1;
  return -1;  
} //

Implements spot::state.

const compressed_marking& pn_state::get_marking  )  const
 

Return the encapsulated compressed marking.

const compressed_marking& pn_state::get_marking() const {
  return ma;
} //

size_t pn_state::hash  )  const [virtual]
 

Hash a state.

size_t pn_state::hash() const {
  const int max = sizeof(size_t)*8;
  size_t res = 0;
  const std::vector<bool>& b = ma.get_vector();
  int min = b.size();

  if (min>max)
    min=max;
  std::vector<bool>::const_iterator i = b.begin();

  for (; min>0; --min, ++i)
    if (*i)
      res |= 1<<min;
  return res;
} //

Implements spot::state.


Member Data Documentation

compressed_marking pn_state::ma [private]
 

The encapsulated marking is stored compressed.

Definition at line 78 of file pnstate.hh.


The documentation for this class was generated from the following file:
Please comment this page and report errors about it on the RefDocComments page.
Generated on Tue Nov 9 16:24:01 2004 for checkpn by doxygen 1.3.8