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

LearnLib / automatalib / 13815628111

12 Mar 2025 03:46PM CUT coverage: 92.058% (-0.001%) from 92.059%
13815628111

push

github

mtf90
cleanup redundant type variable definitions

1 of 1 new or added line in 1 file covered. (100.0%)

16599 of 18031 relevant lines covered (92.06%)

1.7 hits per line

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

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

18
/**
19
 * Interface for disjoint-set forest implementations that operate on a universe of contiguous integers.
20
 */
21
public interface IntDisjointSets {
22

23
    /**
24
     * Returns the size of the universe. The elements of the universe are the integers between {@code 0} (inclusive) and
25
     * {@code size()} (exclusive).
26
     *
27
     * @return the size of the universe
28
     */
29
    int size();
30

31
    /**
32
     * Checks if two elements are in the same set.
33
     *
34
     * @param x
35
     *         the first element
36
     * @param y
37
     *         the second element
38
     *
39
     * @return {@code true} if {@code x} and {@code y} are in the same set, {@code false} otherwise
40
     */
41
    default boolean equivalent(int x, int y) {
42
        int rx = find(x);
×
43
        int ry = find(y);
×
44
        return rx == ry;
×
45
    }
46

47
    /**
48
     * Determines the representative element of the set containing {@code x}.
49
     *
50
     * @param x
51
     *         the element to find
52
     *
53
     * @return the representative element of the set containing {@code x}.
54
     */
55
    int find(int x);
56

57
    /**
58
     * Unites the sets containing the respective elements. If two disjoint sets were united, the return value is {@code
59
     * true}. Otherwise, if {@code x} and {@code y} were already in the same set, {@code false} is returned.
60
     * <p>
61
     * <b>Attention:</b> this method returns {@code true} if and only if {@code equivalent(x, y)} would have returned
62
     * {@code false}.
63
     *
64
     * @param x
65
     *         the first element
66
     * @param y
67
     *         the second element
68
     *
69
     * @return {@code true} if two disjoint sets have been united as a result, {@code false} otherwise
70
     */
71
    default boolean union(int x, int y) {
72
        int rx = find(x);
×
73
        int ry = find(y);
×
74
        if (rx == ry) {
×
75
            return false;
×
76
        }
77
        link(rx, ry);
×
78
        return true;
×
79
    }
80

81
    /**
82
     * Links (unites) two sets, identified by their representatives.
83
     *
84
     * @param rx
85
     *         the representative of the first set
86
     * @param ry
87
     *         the representative of the second set
88
     *
89
     * @return the representative of the resulting set (typically either {@code rx} or {@code ry}).
90
     */
91
    int link(int rx, int ry);
92

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