From 3a11fb5be6170dff56dc58e1d671509e72c0265e Mon Sep 17 00:00:00 2001 From: buraq Date: Tue, 1 Mar 2005 12:58:58 +0000 Subject: minor changes --- sources/scala/util/automata/DetWordAutom.scala | 2 +- sources/scala/util/automata/Inclusion.scala | 2 +- sources/scala/util/automata/NondetWordAutom.scala | 12 ++++++------ sources/scala/util/automata/SubsetConstruction.scala | 18 +++++++++--------- sources/scala/util/automata/WordBerrySethi.scala | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/sources/scala/util/automata/DetWordAutom.scala b/sources/scala/util/automata/DetWordAutom.scala index 117454b4b4..58dc9ef937 100644 --- a/sources/scala/util/automata/DetWordAutom.scala +++ b/sources/scala/util/automata/DetWordAutom.scala @@ -9,7 +9,7 @@ import scala.collection.{ Set, Map }; * All states are reachable. Accepting states are those for which * the partial function 'finals' is defined. */ -abstract class DetWordAutom[T] { +abstract class DetWordAutom[T <: AnyRef] { val nstates: Int; val finals: Array[Int] ; diff --git a/sources/scala/util/automata/Inclusion.scala b/sources/scala/util/automata/Inclusion.scala index 6f1eee3c09..329e56b5bc 100644 --- a/sources/scala/util/automata/Inclusion.scala +++ b/sources/scala/util/automata/Inclusion.scala @@ -4,7 +4,7 @@ package scala.util.automata ; * inspired by the AMoRE automata library * @author Burak */ -trait Inclusion[A] { +trait Inclusion[A <: AnyRef] { val labels: Seq[A]; diff --git a/sources/scala/util/automata/NondetWordAutom.scala b/sources/scala/util/automata/NondetWordAutom.scala index ee0b2cc07d..1f453b218f 100644 --- a/sources/scala/util/automata/NondetWordAutom.scala +++ b/sources/scala/util/automata/NondetWordAutom.scala @@ -9,15 +9,15 @@ import scala.collection.{ immutable, mutable, Set, Map }; * All states are reachable. Accepting states are those for which * the partial function 'finals' is defined. */ -abstract class NondetWordAutom { +abstract class NondetWordAutom[T <: AnyRef] { - type _labelT; + //type _labelT <: AnyRef ; val nstates: Int; - val labels: Seq[_labelT]; + val labels: Seq[T]; val finals: Array[Int] ; // 0 means not final - val delta: Array[Map[_labelT, immutable.BitSet]]; + val delta: Array[Map[T, immutable.BitSet]]; val default: Array[immutable.BitSet]; /** returns true if the state is final */ @@ -46,7 +46,7 @@ abstract class NondetWordAutom { } /** returns a bitset with the next states for given state and label */ - def next(q:Int, a: _labelT): immutable.BitSet = { + def next(q:Int, a: T): immutable.BitSet = { delta(q).get(a).match { case Some(bs) => bs case _ => default(q) @@ -54,7 +54,7 @@ abstract class NondetWordAutom { } /** returns a bitset with the next states for given state and label */ - def next(Q:immutable.BitSet, a: _labelT): immutable.BitSet = { + def next(Q:immutable.BitSet, a: T): immutable.BitSet = { val x = new mutable.BitSet(nstates); for(val q <- Q.toSet(true)) { for(val i <- next(q,a).toSet(true)) { diff --git a/sources/scala/util/automata/SubsetConstruction.scala b/sources/scala/util/automata/SubsetConstruction.scala index ac08ef02e3..c00c73a422 100644 --- a/sources/scala/util/automata/SubsetConstruction.scala +++ b/sources/scala/util/automata/SubsetConstruction.scala @@ -1,9 +1,9 @@ package scala.util.automata ; -class SubsetConstruction(val nfa: NondetWordAutom) { - - import nfa.{ _labelT, labels }; +class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T]) { + //import nfa.{ _labelT, labels }; + import nfa.labels ; import scala.collection.{immutable, mutable, Map} ; import immutable.{ BitSet, TreeMap, TreeSet } ; @@ -36,7 +36,7 @@ class SubsetConstruction(val nfa: NondetWordAutom) { mintag } - def determinize: DetWordAutom[_labelT] = { + def determinize: DetWordAutom[ T ] = { // for assigning numbers to bitsets var indexMap = new TreeMap[ BitSet, Int ]; @@ -46,7 +46,7 @@ class SubsetConstruction(val nfa: NondetWordAutom) { // we compute the dfa with states = bitsets var states = new TreeSet[BitSet](); val delta = new mutable.HashMap[BitSet, - mutable.HashMap[_labelT, BitSet]]; + mutable.HashMap[T, BitSet]]; var deftrans = new TreeMap[BitSet, BitSet]; var finals = new TreeMap[BitSet, Int]; @@ -80,7 +80,7 @@ class SubsetConstruction(val nfa: NondetWordAutom) { ix = ix + 1; // make transitiion map - val Pdelta = new mutable.HashMap[_labelT, BitSet]; + val Pdelta = new mutable.HashMap[T, BitSet]; delta.update( P, Pdelta ); val it = labels.elements; while(it.hasNext) { @@ -101,7 +101,7 @@ class SubsetConstruction(val nfa: NondetWordAutom) { // create DetWordAutom, using indices instead of sets val nstatesR = states.size; - val deltaR = new Array[Map[_labelT,Int]](nstatesR); + val deltaR = new Array[Map[T,Int]](nstatesR); val defaultR = new Array[Int](nstatesR); val finalsR = new Array[Int](nstatesR); @@ -111,7 +111,7 @@ class SubsetConstruction(val nfa: NondetWordAutom) { val trans = delta(Q); val transDef = deftrans(Q); val qDef = indexMap(transDef); - val ntrans = new mutable.HashMap[_labelT,Int](); + val ntrans = new mutable.HashMap[T,Int](); val it = trans.keys; while(it.hasNext) { val label = it.next; val p = indexMap(trans(label)); @@ -131,7 +131,7 @@ class SubsetConstruction(val nfa: NondetWordAutom) { finalsR(indexMap(fQ)) = finals(fQ); } - new DetWordAutom [ _labelT ] { + new DetWordAutom [ T ] { //type _labelT = SubsetConstruction.this.nfa._labelT; val nstates = nstatesR; diff --git a/sources/scala/util/automata/WordBerrySethi.scala b/sources/scala/util/automata/WordBerrySethi.scala index 517c8643dd..bf3baa9372 100644 --- a/sources/scala/util/automata/WordBerrySethi.scala +++ b/sources/scala/util/automata/WordBerrySethi.scala @@ -143,7 +143,7 @@ abstract class WordBerrySethi extends BaseBerrySethi { } } - def automatonFrom(pat: RegExp, finalTag: Int): NondetWordAutom = { + def automatonFrom(pat: RegExp, finalTag: Int): NondetWordAutom[_labelT] = { this.finalTag = finalTag; pat match { @@ -217,7 +217,7 @@ abstract class WordBerrySethi extends BaseBerrySethi { } } - new NondetWordAutom { + new NondetWordAutom[_labelT] { type _labelT = WordBerrySethi.this._labelT; val nstates = pos; val labels = WordBerrySethi.this.labels.toList; -- cgit v1.2.3