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

LearnLib / automatalib / 6685076669

29 Oct 2023 06:24PM UTC coverage: 89.857% (+0.06%) from 89.796%
6685076669

push

github

mtf90
align core packages with api packages

15814 of 17599 relevant lines covered (89.86%)

1.67 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-2023 TU Dortmund
2
 * This file is part of AutomataLib, http://www.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.Map;
22
import java.util.Set;
23

24
import com.google.common.collect.Maps;
25
import com.google.common.collect.Sets;
26
import net.automatalib.common.util.Pair;
27

28
public final class Worksets {
29

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

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

36
        final int expectedElementCount = algorithm.expectedElementCount();
×
37
        final Deque<T> queue = new ArrayDeque<>(expectedElementCount);
×
38
        final Set<T> tracking = Sets.newHashSetWithExpectedSize(expectedElementCount);
×
39

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

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

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

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

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

57
        }
×
58

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

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

64
        final Deque<T> queue = new ArrayDeque<>(algorithm.expectedElementCount());
1✔
65
        final Set<T> tracking = Sets.newHashSetWithExpectedSize(algorithm.expectedElementCount());
1✔
66
        final Map<T, E> mapping = Maps.newHashMapWithExpectedSize(algorithm.expectedElementCount());
1✔
67

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

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

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

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

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

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

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