ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
RemUnionFind.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File RemUnionFind.h ---------------------------*/
3/*--------------------------------------------------------------------------*/
64/*--------------------------------------------------------------------------*/
65/*----------------------------- DEFINITIONS --------------------------------*/
66/*--------------------------------------------------------------------------*/
67
68#ifndef __ADS_RemUnionFind
69 #define __ADS_RemUnionFind
70/* self-identification: #endif constant */
71
72/*--------------------------------------------------------------------------*/
73/*------------------------------ INCLUDES ----------------------------------*/
74/*--------------------------------------------------------------------------*/
75
76#include "ADS/Contract.h"
77
78#include <cstddef>
79#include <cstdint>
80#include <vector>
81
82/*--------------------------------------------------------------------------*/
83/*--------------------------- NAMESPACE ------------------------------------*/
84/*--------------------------------------------------------------------------*/
85
86namespace ADS
87{
88
89/*--------------------------------------------------------------------------*/
90/*--------------------------- CLASS RemUnionFind ---------------------------*/
91/*--------------------------------------------------------------------------*/
92
95{
96
97/*--------------------------------------------------------------------------*/
98 public:
101 explicit RemUnionFind( std::size_t n = 0 );
102
104 [[nodiscard]] std::size_t n( void ) const;
105
107 [[nodiscard]] std::size_t count( void ) const;
108
121 std::uint32_t find( std::uint32_t x );
122
143 bool merge( std::uint32_t x , std::uint32_t y );
144
147 bool same( std::uint32_t x , std::uint32_t y );
148
150 [[nodiscard]] std::uint32_t parent( std::uint32_t x ) const;
151
152/*--------------------------------------------------------------------------*/
153 private:
155 [[nodiscard]] bool forest( void ) const;
156
159 [[nodiscard]] std::uint32_t root( std::uint32_t x ) const;
160
161 std::vector< std::uint32_t > f_p;
162 std::size_t f_count = 0;
163
164 }; // end( class RemUnionFind )
165
166/*--------------------------------------------------------------------------*/
167
168} // end( namespace ADS )
169
170/*--------------------------------------------------------------------------*/
171/*-------------------------- IMPLEMENTATION --------------------------------*/
172/*--------------------------------------------------------------------------*/
173
174#include "ADS/mfset/impl/RemUnionFind.tpp"
175
176/*--------------------------------------------------------------------------*/
177
178#endif /* RemUnionFind.h included */
179
180/*--------------------------------------------------------------------------*/
181/*------------------------ End File RemUnionFind.h -------------------------*/
182/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
std::uint32_t parent(std::uint32_t x) const
the parent of , itself if a root
bool same(std::uint32_t x, std::uint32_t y)
whether and are in the same set
std::size_t n(void) const
the number of the elements
bool merge(std::uint32_t x, std::uint32_t y)
joins the sets of and ; true if they were distinct
std::uint32_t find(std::uint32_t x)
the representative of the set of , the root of its tree
RemUnionFind(std::size_t n=0)
the sets
std::size_t count(void) const
the number of the sets
Definition ADT.h:96