Ruckus
05/13/2021, 9:11 PMmod
tells you how far into a chunk you are, and floorDiv
tells you which chunk you are in. Is getting the start of the given chunk as simple as floorDiv * chunkSize
? Is it more complicated than that? Is my mental model fundamentally wrong?ephemient
05/13/2021, 9:13 PMephemient
05/13/2021, 9:13 PMRuckus
05/13/2021, 9:14 PMfun offsetInChunk(x: Int, size: Int, origin: Int = 0): Int =
((x - origin) % size + size) % size
fun startOfChunk(x: Int, size: Int, origin: Int = 0): Int =
x - offsetInChunk(x, size, origin)
fun indexOfChunk(x: Int, size: Int, origin: Int = 0): Int =
(startOfChunk(x, size, origin) - origin) / size
And I'm wondering if it makes sense to replace them with:
fun offsetInChunk(x: Int, size: Int, origin: Int = 0): Int =
(x - origin).mod(size)
fun startOfChunk(x: Int, size: Int, origin: Int = 0): Int =
indexOfChunk(x, size, origin) * size
fun indexOfChunk(x: Int, size: Int, origin: Int = 0): Int =
(x - origin).floorDiv(size)
ephemient
05/13/2021, 9:15 PMRuckus
05/13/2021, 9:15 PMfloorDiv
and mod
, no floorMod
ephemient
05/13/2021, 9:16 PMRuckus
05/13/2021, 9:18 PMfloorMod
is equivalant to Kotlin's mod
, but I believe they are implemented differently.ephemient
05/13/2021, 9:18 PMephemient
05/13/2021, 9:19 PMRuckus
05/13/2021, 9:22 PMfloorMod
in place of mod
), does my mental model hold, and is the replacement for my code valid, or am I off somewhere? In testing the math seems to work out, but my mental model somewhat breaks down with the concept of negative sizes, so I was wondering if it was still valid with the appropriate extension into the negatives, or is it a fundamentally invalid model that happens to line up with the math under certain circumstances?ephemient
05/13/2021, 9:29 PMephemient
05/13/2021, 9:31 PM