H
Hendrik Maryns
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message
Hi group,
I want to iterate over a set, remove the current element, then inside
the iteration iterate over the set again, such that I consider all
possible pairs with the first element, then remove the second element
from the set too if it meets certain constraints. In the end I will end
up with an empty set. Of course I am not interested in the deletion
process, but I build a new set (equivalence relation) on the way. Now
if I understand correctly, the process I describe will cause the first
iterator to fail, because it notices elements have been deleted. In my
scenario though, this is not a problem; I don?t want to consider pairs
in which one of the elements has been deleted. That?s what I deleted
them for in the first place.
So two questions:
- can I get around this failsafe behaviour of java.util.Set?
- Does anybody see a better way to implement this?
Some code to illustrate the problem (not tested or compiled, still in
the process of pseudocoding):
(note: no foreach, as I need Iterator.remove)
Equivalence<State> equivalence = new Equivalence<State>(allStates);
// allStates is the domain of the equivalence
for (Iterator<State> inner = allStates.iterator(); inner.hasNext(); ) {
State q = inner.next();
Set<State> equivClass = new HashSet<State>();
equivClass.add(q);
inner.remove();
for (Iterator<State> outer = allStates.iterator(); outer.hasNext(){
State qPrime = outer.next();
// do a lot of computation to see whether q and q' are equivalent
if (equivalent){
equivClass.add(qPrime);
outer.remove();
}
}
equivalence.add(equivClass);
}
TIA, H.
--
Hendrik Maryns
==================
www.lieverleven.be
http://aouw.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQFD80X9e+7xMGD3itQRAlHeAJ4m10HOPaYz4ls79Rw1CPu18/YLcQCcDl7T
SU+kdWKd9BsbwkQLEsDPKCY=
=9f4i
-----END PGP SIGNATURE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message
Hi group,
I want to iterate over a set, remove the current element, then inside
the iteration iterate over the set again, such that I consider all
possible pairs with the first element, then remove the second element
from the set too if it meets certain constraints. In the end I will end
up with an empty set. Of course I am not interested in the deletion
process, but I build a new set (equivalence relation) on the way. Now
if I understand correctly, the process I describe will cause the first
iterator to fail, because it notices elements have been deleted. In my
scenario though, this is not a problem; I don?t want to consider pairs
in which one of the elements has been deleted. That?s what I deleted
them for in the first place.
So two questions:
- can I get around this failsafe behaviour of java.util.Set?
- Does anybody see a better way to implement this?
Some code to illustrate the problem (not tested or compiled, still in
the process of pseudocoding):
(note: no foreach, as I need Iterator.remove)
Equivalence<State> equivalence = new Equivalence<State>(allStates);
// allStates is the domain of the equivalence
for (Iterator<State> inner = allStates.iterator(); inner.hasNext(); ) {
State q = inner.next();
Set<State> equivClass = new HashSet<State>();
equivClass.add(q);
inner.remove();
for (Iterator<State> outer = allStates.iterator(); outer.hasNext(){
State qPrime = outer.next();
// do a lot of computation to see whether q and q' are equivalent
if (equivalent){
equivClass.add(qPrime);
outer.remove();
}
}
equivalence.add(equivClass);
}
TIA, H.
--
Hendrik Maryns
==================
www.lieverleven.be
http://aouw.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQFD80X9e+7xMGD3itQRAlHeAJ4m10HOPaYz4ls79Rw1CPu18/YLcQCcDl7T
SU+kdWKd9BsbwkQLEsDPKCY=
=9f4i
-----END PGP SIGNATURE-----