Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Zwinkau
libfirm
Commits
331aa63c
Commit
331aa63c
authored
Sep 07, 2015
by
Matthias Braun
Browse files
unionfind: Cleanup
parent
aaa42564
Changes
1
Hide whitespace changes
Inline
Side-by-side
include/libfirm/adt/unionfind.h
View file @
331aa63c
...
...
@@ -32,10 +32,9 @@
* @param data The array (you have to allocate it yourself)
* @param n_elems number of elements handled by the data structure
*/
static
inline
void
uf_init
(
int
*
data
,
size_t
n_elems
)
static
inline
void
uf_init
(
int
*
const
data
,
size_t
const
n_elems
)
{
size_t
i
;
for
(
i
=
0
;
i
<
n_elems
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
n_elems
;
++
i
)
{
data
[
i
]
=
-
1
;
}
}
...
...
@@ -49,21 +48,17 @@ static inline void uf_init(int* data, size_t n_elems)
* @param set2 Representative of set2
* @return the new representative of the set (which is set1 or set2)
*/
static
inline
int
uf_union
(
int
*
data
,
int
set1
,
int
set2
)
static
inline
int
uf_union
(
int
*
const
data
,
int
const
set1
,
int
const
set2
)
{
int
d1
;
int
d2
;
int
newcount
;
if
(
set1
==
set2
)
return
set1
;
/* need 2 set representatives */
d1
=
data
[
set1
];
d2
=
data
[
set2
];
int
const
d1
=
data
[
set1
];
int
const
d2
=
data
[
set2
];
assert
(
d1
<
0
&&
d2
<
0
);
newcount
=
d1
+
d2
;
int
const
newcount
=
d1
+
d2
;
if
(
d1
>
d2
)
{
data
[
set1
]
=
set2
;
data
[
set2
]
=
newcount
;
...
...
@@ -85,7 +80,7 @@ static inline int uf_union(int* data, int set1, int set2)
* @param e The element
* @return The representative of the set that contains @p e
*/
static
inline
int
uf_find
(
int
*
data
,
int
e
)
static
inline
int
uf_find
(
int
*
const
data
,
int
const
e
)
{
/* go through list to find representative */
int
repr
=
e
;
...
...
@@ -94,10 +89,11 @@ static inline int uf_find(int* data, int e)
}
/* update list to point to new representative (path compression) */
while
(
e
!=
repr
)
{
int
next
=
data
[
e
];
data
[
e
]
=
repr
;
e
=
next
;
int
t
=
e
;
while
(
t
!=
repr
)
{
int
const
next
=
data
[
t
];
data
[
t
]
=
repr
;
t
=
next
;
}
return
repr
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment