groostav
10/08/2021, 8:04 AMdouble[10_000][300]
with fast contains
and fast indexOf
, any suggestions?Hampus Londögård
10/08/2021, 8:29 AMgroostav
10/08/2021, 8:50 AMgroostav
10/08/2021, 8:51 AMgroostav
10/08/2021, 8:51 AMindexOf(elem)
as headSet(elem).size
Hampus Londögård
10/08/2021, 8:55 AMdouble[10_000*300]
Then you can have a simple HashMap which points to the array.
What are you gonna use it for? There’s most likely better data structure depending on how it’s gonna be usedIlya Muradyan
10/08/2021, 11:34 AMclass OptimizedArray2D(val n: Int, val m: Int) {
private val _data = DoubleArray(n*m)
private val _ind : MutableMap<Double, MutableSet<Int>> = HashMap<Double, MutableSet<Int>>()
init {
for (i in 0 until n) {
for (j in 0 until m) {
set(i, j, 0.0)
}
}
}
operator fun get(i: Int, j: Int) = _data[i * m + j]
operator fun set(i: Int, j: Int, el: Double) {
val index = i * m + j
val oldEl = _data[index]
_data[index] = el
_ind[oldEl]?.remove(index)
val indSet = _ind[el]
if (indSet == null) {
_ind[el] = mutableSetOf(index)
} else {
indSet.add(index)
}
}
fun indexOf(el: Double): Pair<Int, Int>? {
val indices = _ind[el] ?: return null
val firstIndex = indices.firstOrNull() ?: return null
return (firstIndex / m) to (firstIndex % m)
}
fun contains(el: Double): Boolean {
return _ind.contains(el)
}
}
Pavel Mikhailovskii
10/08/2021, 12:13 PMIlya Muradyan
10/08/2021, 12:22 PMgroostav
10/08/2021, 6:27 PMcontains(it: Double)
i need contains(row: DoubleArray)
(or similar row type), I also need fast indexOf(row: DoubleArray)
groostav
10/08/2021, 6:34 PMindexOf
Ilya Muradyan
10/08/2021, 6:37 PMindexOf()
find, index of the first subrow?Ilya Muradyan
10/08/2021, 6:39 PMIlya Muradyan
10/08/2021, 6:42 PMgroostav
10/12/2021, 8:03 PMgroostav
10/12/2021, 8:05 PMj.u.BitSet
for that which is a kind've fun performant object ive only spent a little bit of time with.