68 memset(uf->
tab, UCHAR_MAX,
sizeof(int64_t[size]));
99 bool p00_uf_root(int64_t pos, int64_t
const tab[
static pos+1]) {
104 uint64_t p00_uf_size(int64_t pos, int64_t
const tab[
static pos+1]) {
105 return p00_uf_root(pos, tab) ? -tab[pos] : 0;
109 int64_t p00_uf_find(int64_t pos, int64_t
const tab[
static pos+1]) {
110 while (!p00_uf_root(pos, tab)) pos = tab[pos];
116 if (!uf || (uf->
size <= pos))
return -1;
117 else return p00_uf_find(pos, uf->
tab);
121 int64_t p00_uf_exchange(int64_t pos, int64_t tab[
static pos+1], int64_t val) {
122 int64_t ret = tab[pos];
128 void p00_uf_compress(uint64_t pos, int64_t tab[
static pos+1], uint64_t root) {
129 while (!p00_uf_root(pos, tab)) {
130 pos = p00_uf_exchange(pos, tab, root);
135 int64_t p00_uf_findCompress(int64_t pos, int64_t tab[
static pos+1]) {
136 int64_t root = p00_uf_find(pos, tab);
137 p00_uf_compress(pos, tab, root);
143 if (!uf || (uf->
size <= pos))
return -1;
144 return p00_uf_findCompress(pos, uf->
tab);
149 if (uf || (uf->
size > pos)) {
150 int64_t root = p00_uf_findCompress(pos, uf->
tab);
151 if (root >= 0 && p00_uf_root(root, uf->
tab))
152 return -uf->
tab[root];
158 void p00_uf_union(int64_t left, int64_t right, int64_t tab[
static (left < right ? right : left)+1]) {
159 tab[left] += p00_uf_exchange(right, tab, left);
165 if (uf && (uf->
size > left) && (uf->
size > right)) {
166 root = p00_uf_findCompress(left, uf->
tab);
168 int64_t rright = p00_uf_find(right, uf->
tab);
171 p00_uf_compress(right, uf->
tab, root);
173 p00_uf_union(root, rright, uf->
tab);
183 if (uf && (uf->
size > pos) && ((uf->
size-pos) >= length)) {
184 for (uint64_t stop = pos+length; pos < stop; ++pos) {
185 p00_uf_findCompress(pos, uf->
tab);