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

LearnLib / automatalib / 28013097648

23 Jun 2026 08:30AM UTC coverage: 92.876% (-0.1%) from 93.007%
28013097648

Pull #103

github

web-flow
Merge 1553bac46 into 87b9d660b
Pull Request #103: Distinguish between structural and semantic interpretations of automata

268 of 313 new or added lines in 46 files covered. (85.62%)

5 existing lines in 2 files now uncovered.

17560 of 18907 relevant lines covered (92.88%)

1.72 hits per line

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

93.44
/core/src/main/java/net/automatalib/automaton/impl/CompactTransitionOutput.java
1
/* Copyright (C) 2013-2026 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.automaton.impl;
17

18
import java.util.Arrays;
19

20
import net.automatalib.alphabet.Alphabet;
21
import net.automatalib.automaton.AutomatonCreator;
22
import net.automatalib.automaton.base.AbstractCompact;
23
import net.automatalib.automaton.base.AbstractCompactDeterministic;
24
import net.automatalib.automaton.concept.MutableTransitionOutput;
25
import org.checkerframework.checker.nullness.qual.Nullable;
26

27
/**
28
 * A compact implementation that supports generic transition outputs.
29
 *
30
 * @param <I>
31
 *         input symbol type
32
 * @param <O>
33
 *         output symbol type
34
 */
35
public class CompactTransitionOutput<I, O> extends AbstractCompactDeterministic<I, CompactTransition<O>, Void, O>
36
        implements MutableTransitionOutput<CompactTransition<O>, O> {
37

38
    private int[] transitions;
39
    private @Nullable Object[] outputs;
40

41
    public CompactTransitionOutput(Alphabet<I> alphabet, int stateCapacity, float resizeFactor) {
42
        super(alphabet, stateCapacity, resizeFactor);
2✔
43

44
        final int size = stateCapacity * numInputs();
2✔
45

46
        this.transitions = new int[size];
2✔
47
        this.outputs = new Object[size];
2✔
48

49
        Arrays.fill(transitions, AbstractCompact.INVALID_STATE);
2✔
50
    }
2✔
51

52
    public CompactTransitionOutput(Alphabet<I> alphabet, int stateCapacity) {
53
        this(alphabet, stateCapacity, DEFAULT_RESIZE_FACTOR);
2✔
54
    }
2✔
55

56
    public CompactTransitionOutput(Alphabet<I> alphabet) {
57
        this(alphabet, DEFAULT_INIT_CAPACITY, DEFAULT_RESIZE_FACTOR);
2✔
58
    }
2✔
59

60
    public CompactTransitionOutput(CompactTransitionOutput<I, O> other) {
61
        this(other.getInputAlphabet(), other);
1✔
62
    }
1✔
63

64
    protected CompactTransitionOutput(Alphabet<I> alphabet, CompactTransitionOutput<?, O> other) {
65
        super(alphabet, other);
1✔
66
        this.transitions = other.transitions.clone();
1✔
67
        this.outputs = other.outputs.clone();
1✔
68
    }
1✔
69

70
    @Override
71
    protected void updateTransitionStorage(Payload payload) {
72
        this.transitions = updateTransitionStorage(this.transitions, AbstractCompact.INVALID_STATE, payload);
2✔
73
        this.outputs = updateTransitionStorage(this.outputs, null, payload);
2✔
74
    }
2✔
75

76
    @Override
77
    public O getTransitionOutput(CompactTransition<O> transition) {
78
        return transition.getProperty();
2✔
79
    }
80

81
    @Override
82
    public O getTransitionProperty(CompactTransition<O> transition) {
83
        return transition.getProperty();
2✔
84
    }
85

86
    @Override
87
    @SuppressWarnings("unchecked")
88
    // Overridden for performance reasons (to prevent object instantiation of default implementation)
89
    public O getTransitionProperty(int state, int input) {
90
        return (O) outputs[toMemoryIndex(state, input)];
2✔
91
    }
92

93
    @Override
94
    public void setTransitionProperty(CompactTransition<O> transition, O property) {
95
        transition.setProperty(property);
2✔
96

97
        if (transition.isAutomatonTransition()) {
2✔
NEW
98
            outputs[transition.getMemoryIdx()] = property;
×
99
        }
100
    }
2✔
101

102
    @Override
103
    public void setTransitionOutput(CompactTransition<O> transition, O output) {
NEW
104
        setTransitionProperty(transition, output);
×
NEW
105
    }
×
106

107
    @Override
108
    public void removeAllTransitions(Integer state) {
109
        final int lower = state * numInputs();
2✔
110
        final int upper = lower + numInputs();
2✔
111
        Arrays.fill(transitions, lower, upper, AbstractCompact.INVALID_STATE);
2✔
112
        Arrays.fill(outputs, lower, upper, null);
2✔
113
    }
2✔
114

115
    @Override
116
    // Overridden for performance reasons (to prevent object instantiation of default implementation)
117
    public int getSuccessor(int state, int input) {
118
        return transitions[toMemoryIndex(state, input)];
2✔
119
    }
120

121
    @Override
122
    public int getIntSuccessor(CompactTransition<O> transition) {
123
        return transition.getSuccId();
2✔
124
    }
125

126
    @Override
127
    public CompactTransition<O> createTransition(int succId, O property) {
128
        return new CompactTransition<>(succId, property);
2✔
129
    }
130

131
    @Override
132
    public void setStateProperty(int state, Void property) {}
2✔
133

134
    @Override
135
    public Void getStateProperty(int stateId) {
136
        return null;
2✔
137
    }
138

139
    @Override
140
    public void setTransition(int state, int input, @Nullable CompactTransition<O> transition) {
141
        if (transition == null) {
2✔
142
            setTransition(state, input, AbstractCompact.INVALID_STATE, null);
2✔
143
        } else {
144
            setTransition(state, input, transition.getSuccId(), transition.getProperty());
2✔
145
            transition.setMemoryIdx(toMemoryIndex(state, input));
2✔
146
        }
147
    }
2✔
148

149
    @Override
150
    public void setTransition(int state, int input, int successor, @Nullable O property) {
151
        final int idx = toMemoryIndex(state, input);
2✔
152
        transitions[idx] = successor;
2✔
153
        outputs[idx] = property;
2✔
154
    }
2✔
155

156
    @Override
157
    public void clear() {
158
        int endIdx = size() * numInputs();
2✔
159
        Arrays.fill(transitions, 0, endIdx, AbstractCompact.INVALID_STATE);
2✔
160
        Arrays.fill(outputs, 0, endIdx, null);
2✔
161

162
        super.clear();
2✔
163
    }
2✔
164

165
    @Override
166
    public @Nullable CompactTransition<O> getTransition(int state, int input) {
167
        final int idx = toMemoryIndex(state, input);
2✔
168
        final int succ = transitions[idx];
2✔
169

170
        if (succ == AbstractCompact.INVALID_STATE) {
2✔
171
            return null;
2✔
172
        }
173

174
        @SuppressWarnings("unchecked")
175
        final O output = (O) outputs[idx];
2✔
176

177
        return new CompactTransition<>(idx, succ, output);
2✔
178
    }
179

180
    public static final class Creator<I, O> implements AutomatonCreator<CompactTransitionOutput<I, O>, I> {
2✔
181

182
        @Override
183
        public CompactTransitionOutput<I, O> createAutomaton(Alphabet<I> alphabet, int sizeHint) {
184
            return new CompactTransitionOutput<>(alphabet, sizeHint);
2✔
185
        }
186

187
        @Override
188
        public CompactTransitionOutput<I, O> createAutomaton(Alphabet<I> alphabet) {
NEW
189
            return new CompactTransitionOutput<>(alphabet);
×
190
        }
191
    }
192

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

© 2026 Coveralls, Inc