• 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

50.0
/commons/util/src/main/java/net/automatalib/common/util/fixpoint/Worksets.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.common.util.fixpoint;
17

18
import java.util.ArrayDeque;
19
import java.util.Collection;
20
import java.util.Deque;
21
import java.util.HashMap;
22
import java.util.HashSet;
23
import java.util.Map;
24
import java.util.Set;
25

26
import net.automatalib.common.util.HashUtil;
27
import net.automatalib.common.util.Pair;
28

29
public final class Worksets {
30

31
    private Worksets() {
32
        // prevent instantiation
33
    }
34

35
    public static <T, R> R process(WorksetAlgorithm<T, R> algorithm) {
36

37
        final int expectedElementCount = algorithm.expectedElementCount();
×
38
        final Deque<T> queue = new ArrayDeque<>(expectedElementCount);
×
39
        final Set<T> tracking = new HashSet<>(HashUtil.capacity(expectedElementCount));
×
40

41
        final Collection<T> initialElements = algorithm.initialize();
×
42
        queue.addAll(initialElements);
×
43
        tracking.addAll(initialElements);
×
44

45
        while (!queue.isEmpty()) {
×
46

47
            T current = queue.remove();
×
48
            tracking.remove(current);
×
49

50
            final Collection<T> discovered = algorithm.update(current);
×
51

52
            for (T element : discovered) {
×
53
                if (tracking.add(element)) {
×
54
                    queue.add(element);
×
55
                }
56
            }
×
57

58
        }
×
59

60
        return algorithm.result();
×
61
    }
62

63
    public static <T, E, R> Pair<Map<T, E>, R> map(WorksetMappingAlgorithm<T, E, R> algorithm) {
64

65
        final Deque<T> queue = new ArrayDeque<>(algorithm.expectedElementCount());
1✔
66
        final Set<T> tracking = new HashSet<>(HashUtil.capacity(algorithm.expectedElementCount()));
1✔
67
        final Map<T, E> mapping = new HashMap<>(HashUtil.capacity(algorithm.expectedElementCount()));
1✔
68

69
        final Collection<T> initialElements = algorithm.initialize(mapping);
1✔
70
        queue.addAll(initialElements);
1✔
71
        tracking.addAll(initialElements);
1✔
72

73
        while (!queue.isEmpty()) {
1✔
74

75
            T currentT = queue.remove();
1✔
76
            tracking.remove(currentT);
1✔
77

78
            final Collection<T> discovered = algorithm.update(mapping, currentT);
1✔
79

80
            for (T element : discovered) {
1✔
81
                if (tracking.add(element)) {
1✔
82
                    queue.add(element);
1✔
83
                }
84
            }
1✔
85
        }
1✔
86

87
        return Pair.of(mapping, algorithm.result());
1✔
88
    }
89

90
}
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