Skip to content

Commit 3e2762c

Browse files
committed
cleanup usage of IntrusiveList
1 parent 568c369 commit 3e2762c

23 files changed

Lines changed: 225 additions & 346 deletions

File tree

algorithms/active/observation-pack-vpa/src/main/java/de/learnlib/algorithm/observationpack/vpa/AbstractVPALearner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private List<DTNode<I>> closeTransitions(TransList<I> transList, boolean hard) {
177177

178178
for (AbstractHypTrans<I> transition : transToSift) {
179179
final DTNode<I> node = leavesIter.next();
180-
if (node.isLeaf() && node.getData() == null && transition.getNextElement() == null) {
180+
if (node.isLeaf() && node.getData() == null && transition.getNext() == null) {
181181
result.add(node);
182182
}
183183
}

algorithms/active/observation-pack-vpa/src/main/java/de/learnlib/algorithm/observationpack/vpa/OPLearnerVPA.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ protected boolean refineHypothesisSingle(DefaultQuery<I, Boolean> ceQuery) {
114114

115115
HypLoc<I> newLoc = makeTree(trans);
116116
DTNode<I> oldDtNode = succState.getLocation().getLeaf();
117-
openTransitions.addAll(oldDtNode.getIncoming());
117+
openTransitions.concat(oldDtNode.getIncoming());
118118
DTNode<I>.SplitResult children = oldDtNode.split(context, acex.effect(breakpoint), acex.effect(breakpoint + 1));
119119
link(children.nodeOld, newLoc);
120120
link(children.nodeNew, succState.getLocation());

algorithms/active/observation-pack-vpa/src/main/java/de/learnlib/algorithm/observationpack/vpa/hypothesis/AbstractHypTrans.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@
1616
package de.learnlib.algorithm.observationpack.vpa.hypothesis;
1717

1818
import de.learnlib.AccessSequenceProvider;
19-
import de.learnlib.datastructure.list.IntrusiveListElemImpl;
19+
import de.learnlib.datastructure.list.AbstractIntrusiveListEntryImpl;
2020
import net.automatalib.word.Word;
2121

2222
/**
2323
* @param <I>
2424
* input symbol type
2525
*/
26-
public abstract class AbstractHypTrans<I> extends IntrusiveListElemImpl<AbstractHypTrans<I>>
26+
public abstract class AbstractHypTrans<I> extends AbstractIntrusiveListEntryImpl<AbstractHypTrans<I>>
2727
implements AccessSequenceProvider<I> {
2828

2929
private final Word<I> aseq;
30-
protected IntrusiveListElemImpl<AbstractHypTrans<I>> prev;
3130
private HypLoc<I> treeTarget;
3231
private DTNode<I> nonTreeTarget;
3332

@@ -82,14 +81,8 @@ public void makeTree(HypLoc<I> tgtLoc) {
8281
removeFromList();
8382
}
8483

85-
public void removeFromList() {
86-
if (next != null) {
87-
next.prev = prev;
88-
}
89-
if (prev != null) {
90-
prev.setNextElement(next);
91-
}
92-
prev = null;
93-
next = null;
84+
@Override
85+
public AbstractHypTrans<I> getElement() {
86+
return this;
9487
}
9588
}

algorithms/active/observation-pack-vpa/src/main/java/de/learnlib/algorithm/observationpack/vpa/hypothesis/BlockList.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

algorithms/active/observation-pack-vpa/src/main/java/de/learnlib/algorithm/observationpack/vpa/hypothesis/DTNode.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
import de.learnlib.datastructure.discriminationtree.iterators.DiscriminationTreeIterators;
2222
import de.learnlib.datastructure.discriminationtree.model.AbstractTemporaryIntrusiveDTNode;
2323
import de.learnlib.datastructure.discriminationtree.model.BooleanMap;
24-
import de.learnlib.datastructure.list.IntrusiveListElem;
24+
import de.learnlib.datastructure.list.IntrusiveListEntry;
2525

2626
/**
2727
* @param <I>
2828
* input symbol type
2929
*/
3030
public class DTNode<I>
3131
extends AbstractTemporaryIntrusiveDTNode<ContextPair<I>, Boolean, HypLoc<I>, TransList<I>, DTNode<I>>
32-
implements IntrusiveListElem<DTNode<I>> {
32+
implements IntrusiveListEntry<DTNode<I>> {
3333

3434
private final TransList<I> nonTreeIncoming = new TransList<>();
3535

@@ -82,4 +82,9 @@ protected Map<Boolean, DTNode<I>> createChildMap() {
8282
protected DTNode<I> createChild(Boolean outcome, HypLoc<I> data) {
8383
return new DTNode<>(this, outcome, data);
8484
}
85+
86+
@Override
87+
public DTNode<I> getElement() {
88+
return this;
89+
}
8590
}

algorithms/active/observation-pack-vpa/src/main/java/de/learnlib/algorithm/observationpack/vpa/hypothesis/TransList.java

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,74 +16,32 @@
1616
package de.learnlib.algorithm.observationpack.vpa.hypothesis;
1717

1818
import de.learnlib.datastructure.list.IntrusiveList;
19-
import org.checkerframework.checker.nullness.qual.Nullable;
19+
import de.learnlib.datastructure.list.IntrusiveListEntry;
2020

2121
/**
2222
* @param <I>
2323
* input symbol type
2424
*/
2525
public class TransList<I> extends IntrusiveList<AbstractHypTrans<I>> {
2626

27-
public void add(AbstractHypTrans<I> trans) {
28-
assert !trans.isTree();
29-
trans.removeFromList();
30-
31-
if (next != null) {
32-
trans.setNextElement(next);
33-
next.prev = trans;
34-
}
35-
trans.prev = this;
36-
next = trans;
37-
}
38-
39-
public void addAll(TransList<I> list) {
40-
if (list.next != null) {
41-
AbstractHypTrans<I> last = list.next;
42-
while (last.getNextElement() != null) {
43-
last = last.getNextElement();
44-
}
45-
if (next != null) {
46-
next.prev = last;
47-
}
48-
last.setNextElement(next);
49-
list.next.prev = this;
50-
next = list.next;
51-
}
52-
list.next = null;
53-
}
54-
5527
public AbstractHypTrans<I> chooseMinimal() {
56-
AbstractHypTrans<I> curr = next;
57-
AbstractHypTrans<I> shortest = curr;
58-
int shortestLen = shortest.getAccessSequence().length();
28+
IntrusiveListEntry<AbstractHypTrans<I>> curr = getNext();
29+
assert curr != null;
30+
31+
IntrusiveListEntry<AbstractHypTrans<I>> shortest = curr;
32+
int shortestLen = shortest.getElement().getAccessSequence().length();
5933

60-
curr = curr.getNextElement();
34+
curr = curr.getNext();
6135
while (curr != null) {
62-
int transLen = curr.getAccessSequence().length();
36+
int transLen = curr.getElement().getAccessSequence().length();
6337
if (transLen < shortestLen) {
6438
shortestLen = transLen;
6539
shortest = curr;
6640
}
67-
curr = curr.getNextElement();
68-
}
69-
70-
return shortest;
71-
}
72-
73-
public @Nullable AbstractHypTrans<I> poll() {
74-
if (next == null) {
75-
return null;
41+
curr = curr.getNext();
7642
}
77-
AbstractHypTrans<I> result = next;
78-
next = result.getNextElement();
79-
if (result.getNextElement() != null) {
80-
result.getNextElement().prev = this;
81-
}
82-
83-
result.prev = null;
84-
result.setNextElement(null);
8543

86-
return result;
44+
return shortest.getElement();
8745
}
8846

8947
}

algorithms/active/ttt-vpa/src/main/java/de/learnlib/algorithm/ttt/vpa/TTTLearnerVPA.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
import de.learnlib.acex.AcexAnalyzer;
3030
import de.learnlib.algorithm.observationpack.vpa.OPLearnerVPA;
3131
import de.learnlib.algorithm.observationpack.vpa.hypothesis.AbstractHypTrans;
32-
import de.learnlib.algorithm.observationpack.vpa.hypothesis.BlockList;
3332
import de.learnlib.algorithm.observationpack.vpa.hypothesis.ContextPair;
3433
import de.learnlib.algorithm.observationpack.vpa.hypothesis.DTNode;
3534
import de.learnlib.algorithm.observationpack.vpa.hypothesis.HypLoc;
3635
import de.learnlib.algorithm.observationpack.vpa.hypothesis.TransList;
3736
import de.learnlib.datastructure.discriminationtree.SplitData;
37+
import de.learnlib.datastructure.list.IntrusiveList;
3838
import de.learnlib.oracle.MembershipOracle.DFAMembershipOracle;
3939
import de.learnlib.query.DefaultQuery;
4040
import de.learnlib.tooling.annotation.builder.GenerateBuilder;
@@ -54,7 +54,7 @@
5454
*/
5555
public class TTTLearnerVPA<I> extends OPLearnerVPA<I> {
5656

57-
private final BlockList<I> blockList = new BlockList<>();
57+
private final IntrusiveList<DTNode<I>> blockList = new IntrusiveList<>();
5858

5959
@GenerateBuilder(defaults = BuilderDefaults.class)
6060
public TTTLearnerVPA(VPAlphabet<I> alphabet, DFAMembershipOracle<I> oracle, AcexAnalyzer analyzer) {
@@ -169,7 +169,7 @@ private void splitState(OutputInconsistency<I> outIncons) {
169169

170170
HypLoc<I> newLoc = makeTree(trans);
171171
DTNode<I> oldDtNode = succState.getLocation().getLeaf();
172-
openTransitions.addAll(oldDtNode.getIncoming());
172+
openTransitions.concat(oldDtNode.getIncoming());
173173
DTNode<I>.SplitResult children = oldDtNode.split(context, acex.effect(breakpoint), acex.effect(breakpoint + 1));
174174
oldDtNode.setTemp(true);
175175
if (!oldDtNode.getParent().isTemp()) {
@@ -547,7 +547,7 @@ protected void declareFinal(DTNode<I> blockRoot) {
547547
blockRoot.setTemp(false);
548548
blockRoot.setSplitData(null);
549549

550-
blockRoot.removeFromBlockList();
550+
blockRoot.removeFromList();
551551

552552
for (DTNode<I> subtree : blockRoot.getChildren()) {
553553
assert subtree.getSplitData() == null;
@@ -558,7 +558,7 @@ protected void declareFinal(DTNode<I> blockRoot) {
558558
}
559559
}
560560

561-
openTransitions.addAll(blockRoot.getIncoming());
561+
openTransitions.concat(blockRoot.getIncoming());
562562
}
563563

564564
/**
@@ -594,7 +594,7 @@ public AbstractHypTrans<I> getSplitterTrans(HypLoc<I> loc, Splitter<I> splitter)
594594
}
595595

596596
private static <I> void moveIncoming(DTNode<I> newNode, DTNode<I> oldNode, Boolean label) {
597-
newNode.getIncoming().addAll(oldNode.getSplitData().getIncoming(label));
597+
newNode.getIncoming().concat(oldNode.getSplitData().getIncoming(label));
598598
}
599599

600600
/**

algorithms/active/ttt-vpa/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
requires de.learnlib.algorithm.observationpack.vpa;
3535
requires de.learnlib.common.counterexample;
3636
requires de.learnlib.datastructure.discriminationtree;
37+
requires de.learnlib.datastructure.list;
3738
requires net.automatalib.api;
3839
requires net.automatalib.common.util;
3940

algorithms/active/ttt/src/main/java/de/learnlib/algorithm/ttt/base/AbstractBaseDTNode.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919

2020
import de.learnlib.datastructure.discriminationtree.iterators.DiscriminationTreeIterators;
2121
import de.learnlib.datastructure.discriminationtree.model.AbstractTemporaryIntrusiveDTNode;
22-
import de.learnlib.datastructure.list.IntrusiveListElem;
22+
import de.learnlib.datastructure.list.IntrusiveList;
23+
import de.learnlib.datastructure.list.IntrusiveListEntry;
2324
import net.automatalib.word.Word;
2425

2526
public abstract class AbstractBaseDTNode<I, D>
26-
extends AbstractTemporaryIntrusiveDTNode<Word<I>, D, TTTState<I, D>, IncomingList<I, D>, AbstractBaseDTNode<I, D>>
27-
implements IntrusiveListElem<AbstractBaseDTNode<I, D>> {
27+
extends AbstractTemporaryIntrusiveDTNode<Word<I>, D, TTTState<I, D>, IntrusiveList<TTTTransition<I, D>>, AbstractBaseDTNode<I, D>>
28+
implements IntrusiveListEntry<AbstractBaseDTNode<I, D>> {
2829

29-
private final IncomingList<I, D> incoming = new IncomingList<>();
30+
private final IntrusiveList<TTTTransition<I, D>> incoming = new IntrusiveList<>();
3031

3132
public AbstractBaseDTNode() {
3233
this(null, null);
@@ -52,7 +53,7 @@ public Iterator<TTTState<I, D>> subtreeStatesIterator() {
5253
return DiscriminationTreeIterators.transformingLeafIterator(this, AbstractBaseDTNode::getData);
5354
}
5455

55-
public IncomingList<I, D> getIncoming() {
56+
public IntrusiveList<TTTTransition<I, D>> getIncoming() {
5657
return incoming;
5758
}
5859

@@ -69,4 +70,9 @@ void updateIncoming() {
6970
trans.nonTreeTarget = this;
7071
}
7172
}
73+
74+
@Override
75+
public AbstractBaseDTNode<I, D> getElement() {
76+
return this;
77+
}
7278
}

0 commit comments

Comments
 (0)