Jakub Gwóźdź
11/25/2025, 11:41 AMoverride fun toString() on value classes and it works!
@JvmInline
value class LongPos(val value: Long) {
override fun toString() = "$row,$col"
}
fun longPos(row: Int, col: Int) = LongPos((row.toLong() shl 32) or (col.toLong() and 0xFFFF_FFFFL))
val LongPos.row get() = value.shr(32).toInt()
val LongPos.col get() = (value and 0xFFFF_FFFFL).toInt()
This will make my debugging somewhat easier 🙂Norbert Kiesel
11/26/2025, 4:55 PMconstructor(row: Int, col: Int)): this((row.toLong() shl 32) or (col.toLong() and 0xFFFF_FFFFL))Jakub Gwóźdź
11/26/2025, 5:02 PMtypealias PairPos = Pair<Int, Int>
fun PairPos.row get() = first
fun PairPos.row get() = second
And in my code I'll be just using
typealias Pos = PairPos // or = LongPos
but maybe it's overcomplication, I'll see 🙂Norbert Kiesel
11/26/2025, 5:07 PMdata class Point(val x: Int, val y: Int) in my AoC code. Pretty sure your LongPos is more efficient, but I normally do not care so much about efficiency of my AoC code (as long as it finishes within some seconds), and instead care more about code prettiness (of course also very subjective).