• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LearnLib / automatalib / 13138848026

04 Feb 2025 02:53PM UTC coverage: 92.108% (+2.2%) from 89.877%
13138848026

push

github

mtf90
[maven-release-plugin] prepare release automatalib-0.12.0

16609 of 18032 relevant lines covered (92.11%)

1.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.65
/util/src/main/java/net/automatalib/util/ts/traversal/BreadthFirstIterator.java
1
/* Copyright (C) 2013-2025 TU Dortmund University
2
 * This file is part of AutomataLib <https://automatalib.net>.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package net.automatalib.util.ts.traversal;
17

18
import java.util.ArrayDeque;
19
import java.util.Collection;
20
import java.util.Iterator;
21
import java.util.NoSuchElementException;
22
import java.util.Queue;
23

24
import net.automatalib.common.util.mapping.MutableMapping;
25
import net.automatalib.ts.simple.SimpleTS;
26
import net.automatalib.util.traversal.VisitedState;
27

28
final class BreadthFirstIterator<S, I> implements Iterator<S> {
29

30
    private final Queue<S> bfsQueue = new ArrayDeque<>();
2✔
31
    private final MutableMapping<S, VisitedState> seen;
32
    private final SimpleTS<S, I> ts;
33
    private final Collection<? extends I> inputs;
34

35
    BreadthFirstIterator(SimpleTS<S, I> ts, Collection<? extends I> inputs) {
2✔
36
        this.ts = ts;
2✔
37
        this.inputs = inputs;
2✔
38
        seen = ts.createStaticStateMapping();
2✔
39
        Collection<S> initial = ts.getInitialStates();
2✔
40
        bfsQueue.addAll(initial);
2✔
41
        for (S state : initial) {
2✔
42
            seen.put(state, VisitedState.VISITED);
2✔
43
        }
2✔
44
    }
2✔
45

46
    @Override
47
    public boolean hasNext() {
48
        return !bfsQueue.isEmpty();
2✔
49
    }
50

51
    @Override
52
    public S next() {
53
        S state = bfsQueue.poll();
2✔
54

55
        if (state == null) {
2✔
56
            throw new NoSuchElementException();
×
57
        }
58

59
        for (I input : inputs) {
2✔
60
            Collection<S> succs = ts.getSuccessors(state, input);
2✔
61
            for (S succ : succs) {
2✔
62
                if (seen.put(succ, VisitedState.VISITED) != VisitedState.VISITED) {
2✔
63
                    bfsQueue.add(succ);
2✔
64
                }
65
            }
2✔
66
        }
2✔
67

68
        return state;
2✔
69
    }
70

71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc