Navigation
API > API/Runtime > API/Runtime/GeometryCore > API/Runtime/GeometryCore/Util
References
| Module | GeometryCore |
| Header | /Engine/Source/Runtime/GeometryCore/Public/Util/IteratorUtil.h |
| Include | #include "Util/IteratorUtil.h" |
Syntax
struct FModuloIteration
Remarks
FModuloIteration is used to iterate over a range of indices [0,N) using modulo-arithmetic. The iteration proceeds as NextValue = (CurValue + ModuloValue) % N. As long as the ModuloValue is a prime number > N/2, then every integer in the sequence 0...N-1 will appear exactly once before 0 re-appears (and in fact any index in the range can be used as the starting value).
FModuloIteration computes in 64-bit with (by default) a large enough prime that will work for any 32-bit unsigned integer. If 64-bit iterations are needed, some larger primes can be found here: https://en.wikipedia.org/wiki/P%C3%A9pin%27s_test
(The prime does not strictly need to be > N/2, any prime will work as long as it is not a divisor of N. And it doesn't even need to be a prime number, just a co-prime of N, ie GCD(N, ModuloValue) = 1. It is possible to check GCD relatively quickly to search for valid constants, for example if many values were needed to use as seeds/etc)
Usage:
FModuloIteration Iter(N); uint32 Index; while (Iter.GetNextIndex(Index)) { ... }
Variables
| Type | Name | Description | |
|---|---|---|---|
| uint64 | Count | ||
| uint64 | CurIndex | ||
| uint64 | MaxIndex | ||
| uint64 | ModuloNum | ||
| uint64 | ModuloPrime | ||
| uint64 | StartIndex |
Constructors
| Type | Name | Description | |
|---|---|---|---|
FModuloIteration
(
uint32 MaxIndexIn, |
Functions
| Type | Name | Description | |
|---|---|---|---|
| bool | GetNextIndex
(
uint32& NextIndexOut |
||
| bool | GetNextIndex
(
int32& NextIndexOut |