ec: Renault et al LPAR'13 emptiness check
In order to reuse the computation of the intersection between kripke and twa efficiently, we use template inheritance through the "mixin templates" technique. * spot/Makefile.am, spot/mc/Makefile.am, spot/mc/ec.hh, spot/mc/unionfind.cc, spot/mc/unionfind.hh: here.
This commit is contained in:
parent
87de88c80c
commit
3bafe693ef
5 changed files with 419 additions and 8 deletions
93
spot/mc/unionfind.cc
Normal file
93
spot/mc/unionfind.cc
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2015, 2016 Laboratoire de Recherche et
|
||||
// Developpement de l'Epita
|
||||
//
|
||||
// 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
|
||||
// the Free Software Foundation; either version 3 of the License, or
|
||||
// (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
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <spot/mc/unionfind.hh>
|
||||
#include <assert.h>
|
||||
|
||||
namespace spot
|
||||
{
|
||||
int int_unionfind::root(int i)
|
||||
{
|
||||
assert(i > 0);
|
||||
int p = id[i];
|
||||
if (p == DEAD)
|
||||
return DEAD;
|
||||
if (p < 0)
|
||||
return i;
|
||||
int gp = id[p];
|
||||
if (gp == DEAD)
|
||||
return DEAD;
|
||||
if (gp < 0)
|
||||
return p;
|
||||
p = root(p);
|
||||
id[i] = p;
|
||||
return p;
|
||||
}
|
||||
|
||||
int_unionfind::int_unionfind() : id()
|
||||
{
|
||||
id.push_back(DEAD);
|
||||
}
|
||||
|
||||
void int_unionfind::makeset(int e)
|
||||
{
|
||||
assert(e == (int) id.size());
|
||||
id.push_back(-1);
|
||||
}
|
||||
|
||||
bool int_unionfind::unite(int e1, int e2)
|
||||
{
|
||||
// IPC - Immediate Parent Check
|
||||
int p1 = id[e1];
|
||||
int p2 = id[e2];
|
||||
if ((p1 < 0 ? e1 : p1) == (p2 < 0 ? e2 : p2))
|
||||
return false;
|
||||
int root1 = root(e1);
|
||||
int root2 = root(e2);
|
||||
if (root1 == root2)
|
||||
return false;
|
||||
int rk1 = -id[root1];
|
||||
int rk2 = -id[root2];
|
||||
if (rk1 < rk2)
|
||||
id[root1] = root2;
|
||||
else {
|
||||
id[root2] = root1;
|
||||
if (rk1 == rk2)
|
||||
id[root1] = -(rk1 + 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void int_unionfind::markdead(int e)
|
||||
{
|
||||
id[root(e)] = DEAD;
|
||||
}
|
||||
|
||||
bool int_unionfind::sameset(int e1, int e2)
|
||||
{
|
||||
assert(e1 < (int)id.size() && e2 < (int)id.size());
|
||||
return root(e1) == root(e2);
|
||||
}
|
||||
|
||||
bool int_unionfind::isdead(int e)
|
||||
{
|
||||
assert(e < (int)id.size());
|
||||
return root(e) == DEAD;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue