weight.cc 1.83 KB
Newer Older
1
2
3
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2014 Laboratoire de Recherche et Developpement
// de l'Epita.
4
// Copyright (C) 2004  Laboratoire d'Informatique de Paris 6 (LIP6),
5
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
6
7
8
9
10
11
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
12
// the Free Software Foundation; either version 3 of the License, or
13
14
15
16
17
18
19
20
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
21
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23
24
25
26
27
28

#include <cassert>
#include <ostream>
#include "weight.hh"

namespace spot
{
29
30
  weight::weight(const acc_cond& acc):
    m(acc.num_sets())
31
32
33
  {
  }

34
  weight& weight::add(const acc_cond& acc, acc_cond::mark_t a)
35
  {
36
37
    for (auto s: acc.sets(a))
      ++m[s];
38
39
40
    return *this;
  }

41
  weight& weight::sub(const acc_cond& acc, acc_cond::mark_t a)
42
  {
43
44
45
    for (auto s: acc.sets(a))
      if (m[s] > 0)
	--m[s];
46
47
48
    return *this;
  }

49
  acc_cond::mark_t weight::diff(const acc_cond& acc, const weight& w) const
50
  {
51
52
53
54
55
56
    unsigned max = acc.num_sets();
    std::vector<unsigned> res;
    for (unsigned n = 0; n < max; ++n)
      if (m[n] > w.m[n])
	res.push_back(n);
    return acc.marks(res.begin(), res.end());
57
58
59
60
  }

  std::ostream& operator<<(std::ostream& os, const weight& w)
  {
61
62
63
    unsigned s = w.m.size();
    for (unsigned n = 0; n < s; ++n)
      os << '(' << n << ',' << w.m[n] << ')';
64
65
66
67
    return os;
  }

};