package com.laseroptek.raman.utils

data class FlexibleArray2D(
    private var data: MutableMap<Pair<Float, Float>, Float> = mutableMapOf()
) {
    fun setData(newData: MutableMap<Pair<Float, Float>, Float>) {
        data = newData
    }

    fun getData(): Map<Pair<Float, Float>, Float> {
        return data
    }

    fun add(row: Float, col: Float, value: Float) {
        data[Pair(row, col)] = value
    }

    fun get(row: Float, col: Float): Float? {
        return data[Pair(row, col)]
    }

    fun isEmpty(): Boolean {
        return data.isEmpty()
    }

    fun FlexibleArray2D.getRowValues(row: Float): List<Float> {
        return data.filterKeys { it.first == row }.values.toList()
    }

    fun FlexibleArray2D.getColValues(col: Float): List<Float> {
        return data.filterKeys { it.second == col }.values.toList()
    }

    fun FlexibleArray2D.clone(): FlexibleArray2D {
        val newData = data.toMutableMap() // Create a deep copy of the data map
        return FlexibleArray2D(newData)
    }

}

/*
val originalArray = FlexibleArray2D()
// ... initialize values ...
val clonedArray = originalArray.clone()
*/

/*
val array2D = FlexibleArray2D()         // ... initialize values ...
val rowValues = array2D.getRowValues(1) // Get values of row 1
*/

/*
val initialData = mapOf(
    Pair(0f, 0f) to 1f,
    Pair(0f, 1f) to 2f,
    Pair(1f, 0f) to 3f,
    Pair(1f, 1f) to 4f
)
val array2D = FlexibleArray2D(initialData)
*/

/*
val array2D = FlexibleArray2D()
array2D.add(0f, 0f, 1f)
array2D.add(0f, 1f, 2f)
array2D.add(1f, 0f, 3f)
array2D.add(1f, 1f, 4f)
*/

/*
val rows = 3
val cols = 4
val array2D = FlexibleArray2D()
for (i in 0 until rows) {
    for (j in 0 until cols) {
        array2D.add(i, j, i * cols + j + 1) // Example: initialize with sequential values
    }
}
*/