| 1 |
/* File: layout_relationship_iter.inl; Copyright and License: see below */ |
| 2 |
|
| 3 |
#include "u8/u8_trace.h" |
| 4 |
#include <assert.h> |
| 5 |
|
| 6 |
static inline void layout_relationship_iter_init( layout_relationship_iter_t *this_, |
| 7 |
layout_visible_set_t *items, |
| 8 |
const universal_array_index_sorter_t *order ) |
| 9 |
{ |
| 10 |
assert( items != NULL ); |
| 11 |
assert( order != NULL ); |
| 12 |
(*this_).next_idx = 0; |
| 13 |
(*this_).length = universal_array_index_sorter_get_count( order ); |
| 14 |
(*this_).items = items; |
| 15 |
(*this_).order = order; |
| 16 |
} |
| 17 |
|
| 18 |
static inline void layout_relationship_iter_init_from_processed( layout_relationship_iter_t *this_, |
| 19 |
const layout_relationship_iter_t *that ) |
| 20 |
{ |
| 21 |
(*this_).next_idx = 0; |
| 22 |
(*this_).length = (*that).next_idx; |
| 23 |
(*this_).items = (*that).items; |
| 24 |
(*this_).order = (*that).order; |
| 25 |
} |
| 26 |
|
| 27 |
static inline void layout_relationship_iter_copy( layout_relationship_iter_t *this_, |
| 28 |
const layout_relationship_iter_t *original ) |
| 29 |
{ |
| 30 |
(*this_).next_idx = (*original).next_idx; |
| 31 |
(*this_).length = (*original).length; |
| 32 |
(*this_).items = (*original).items; |
| 33 |
(*this_).order = (*original).order; |
| 34 |
} |
| 35 |
|
| 36 |
static inline void layout_relationship_iter_reset ( layout_relationship_iter_t *this_ ) |
| 37 |
{ |
| 38 |
(*this_).next_idx = 0; |
| 39 |
} |
| 40 |
|
| 41 |
static inline void layout_relationship_iter_destroy( layout_relationship_iter_t *this_ ) |
| 42 |
{ |
| 43 |
(*this_).next_idx = 0; |
| 44 |
(*this_).length = 0; |
| 45 |
(*this_).items = NULL; |
| 46 |
(*this_).order = NULL; |
| 47 |
} |
| 48 |
|
| 49 |
static inline bool layout_relationship_iter_has_next( const layout_relationship_iter_t *this_ ) |
| 50 |
{ |
| 51 |
/* check that the size of the array has not shrinked */ |
| 52 |
/* It should not have changed at all, but this cannot be checked here. */ |
| 53 |
assert( (*this_).length <= universal_array_index_sorter_get_count( (*this_).order ) ); |
| 54 |
|
| 55 |
return ( (*this_).next_idx < (*this_).length ); |
| 56 |
} |
| 57 |
|
| 58 |
static inline layout_relationship_t *layout_relationship_iter_next_ptr( layout_relationship_iter_t *this_ ) |
| 59 |
{ |
| 60 |
layout_relationship_t *result = NULL; |
| 61 |
if ( layout_relationship_iter_has_next( this_ ) ) |
| 62 |
{ |
| 63 |
uint32_t array_index = universal_array_index_sorter_get_array_index( (*this_).order, (*this_).next_idx ); |
| 64 |
assert( array_index < layout_visible_set_get_relationship_count( (*this_).items ) ); |
| 65 |
result = layout_visible_set_get_relationship_ptr( (*this_).items, array_index ); |
| 66 |
(*this_).next_idx ++; |
| 67 |
} |
| 68 |
return result; |
| 69 |
} |
| 70 |
|
| 71 |
static inline const layout_relationship_t *layout_relationship_iter_next( layout_relationship_iter_t *this_ ) |
| 72 |
{ |
| 73 |
const layout_relationship_t *result = NULL; |
| 74 |
if ( layout_relationship_iter_has_next( this_ ) ) |
| 75 |
{ |
| 76 |
uint32_t array_index = universal_array_index_sorter_get_array_index( (*this_).order, (*this_).next_idx ); |
| 77 |
assert( array_index < layout_visible_set_get_relationship_count( (*this_).items ) ); |
| 78 |
result = layout_visible_set_get_relationship_const( (*this_).items, array_index ); |
| 79 |
(*this_).next_idx ++; |
| 80 |
} |
| 81 |
return result; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
/* |
| 86 |
Copyright 2025-2026 Andreas Warnke |
| 87 |
|
| 88 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 89 |
you may not use this file except in compliance with the License. |
| 90 |
You may obtain a copy of the License at |
| 91 |
|
| 92 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 93 |
|
| 94 |
Unless required by applicable law or agreed to in writing, software |
| 95 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 96 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 97 |
See the License for the specific language governing permissions and |
| 98 |
limitations under the License. |
| 99 |
*/ |