Mescal
Loading...
Searching...
No Matches
type_partitions.h
Go to the documentation of this file.
1
7
8#ifndef PARTITIONS_H
9#define PARTITIONS_H
10
11 /* ____ _ _ _ _ */
12 /* | _ \ __ _ _ __| |_(_) |_(_) ___ _ __ ___ */
13 /* | |_) / _` | '__| __| | __| |/ _ \| '_ \/ __| */
14 /* | __/ (_| | | | |_| | |_| | (_) | | | \__ \ */
15 /* |_| \__,_|_| \__|_|\__|_|\___/|_| |_|___/ */
16
17#include "alloc.h"
18#include "stdbool.h"
19#include "stdlib.h"
20#include "type_basic.h"
21#include "type_dequeue.h"
22
23/**************/
24/* First Type */
25/**************/
26
36typedef struct {
37 uint size_set;
38 uint size_par;
39 uint* numcl;
40 uint* storage;
41 uint** cl_elems;
42 uint* cl_size;
43
44
45 //dequeue** cl; //!< Array indexed by the classes. Each class is mapped to the list
47} parti;
48
56parti* create_parti(uint size_set,
57 uint size_par,
58 uint* numcl
59);
60
61
67);
68
77);
78
90 parti*,
91 uint,
92 bool*,
93 uint*
94);
95
108 parti*,
109 uint,
110 bool*,
111 uint*,
112 uint* // Mapping from the original subset to the full set.
113);
114
126uint* parti_compute_inv(parti* P
127);
128
129/**************/
130/* Union-Find */
131/**************/
132
138typedef struct {
139 uint size_tab;
140 uint size_set;
142 uint size_par;
143 uint* parent;
144 uint* rank;
145 uint* sizec;
146} ufind;
147
155ufind* create_ufind(uint
156);
157
162void delete_ufind(ufind*
163);
164
172uint sizeset_ufind(ufind*
173);
174
182uint sizepar_ufind(ufind*
183);
184
192void makeset_ufind(ufind*
193);
194
202uint find_ufind(uint,
203 ufind*
204);
205
213uint sizeclass_ufind(uint,
214 ufind*
215);
216
221void union_ufind(uint,
222 uint,
223 ufind*
224);
225
230void print_ufind(ufind*
231);
232
241);
242
251);
252
263 ufind*,
264 parti*
265);
266
267#endif
Macros and functions to help memory allocation.
First type used to represent a partition. This is not the one used by Union-Find.
Definition type_partitions.h:36
uint size_par
Size of the partition.
Definition type_partitions.h:38
uint ** cl_elems
Array of classes. For each class c cl_elems[c] contains a point to its firts element in storage.
Definition type_partitions.h:41
uint * storage
Used to the classes contiguously in memory (size size_set).
Definition type_partitions.h:40
uint size_set
Size of the partitioned set (the set itself is {0,...,size_set-1}).
Definition type_partitions.h:37
uint * numcl
Array indexed by the partitioned set. Each element in the set is mapped to its class.
Definition type_partitions.h:39
uint * cl_size
Array indexed by the classes. Each class is mapped to its size.
Definition type_partitions.h:42
Second type used to represent a partition. This is the type used by Union-Find.
Definition type_partitions.h:138
uint size_set
Size of the partitionned set (the set itself is {0,...,size_set-1}).
Definition type_partitions.h:140
uint * rank
Array of ranks (meaningful only for roots).
Definition type_partitions.h:144
uint * sizec
Array of classes sizes (meaningful only for roots).
Definition type_partitions.h:145
uint size_par
Size of the partition.
Definition type_partitions.h:142
uint size_tab
Size of all arrays.
Definition type_partitions.h:139
uint * parent
Array encoding the parent relation.
Definition type_partitions.h:143
Basic types.
Implementation of dequeues of unsigned integers.
uint * parti_compute_inv(parti *P)
Computes the inverse mapping of a partition.
Definition type_partitions.c:197
ufind * create_ufind(uint)
Creation of a trivial union-find partition (all classes are singletons).
Definition type_partitions.c:216
parti * create_parti(uint size_set, uint size_par, uint *numcl)
Creation of a partition.
Definition type_partitions.c:10
void union_ufind(uint, uint, ufind *)
Merging of the classes of two elements in a union-find partition.
Definition type_partitions.c:315
parti * restrict_parti(parti *, uint, bool *, uint *)
Restriction of a partition to a subset of the partitioned set.
Definition type_partitions.c:118
void delete_parti(parti *)
Release of a partition.
Definition type_partitions.c:66
uint find_ufind(uint, ufind *)
Computes the class number of an element in a union-find partition.
Definition type_partitions.c:298
void makeset_ufind(ufind *)
Increments the size of the partionned set in a union-find partition.
Definition type_partitions.c:282
parti * ufind_to_parti(ufind *)
Conversion from the union-find type to the partition type.
Definition type_partitions.c:484
uint sizepar_ufind(ufind *)
Computes the size of the partition in a union-find partition.
Definition type_partitions.c:268
uint sizeset_ufind(ufind *)
Computes the size of the partitioned set in a union-find partition.
Definition type_partitions.c:263
ufind * parti_to_ufind(parti *)
Conversion from the partition type to the union-find type.
Definition type_partitions.c:428
parti * ufind_to_parti_refined(ufind *, parti *)
Conversion from the union-find type to the partition type. In this case, a partition that is coarser ...
Definition type_partitions.c:559
parti * restrict_parti_subset(parti *, uint, bool *, uint *, uint *)
Restriction of a partition to a subset of the partitioned set. Input partition is already a partition...
Definition type_partitions.c:176
void print_ufind(ufind *)
Displays a union-find partition.
Definition type_partitions.c:343
void delete_ufind(ufind *)
Release of a union-find partition.
Definition type_partitions.c:250
uint sizeclass_ufind(uint, ufind *)
Computes the size of the class of an element in a union-find partition.
Definition type_partitions.c:308
bool istrivial_parti(parti *)
Checks whether a partition is trivial (all classes are singletons).
Definition type_partitions.c:79