Add some doc and switch to the parallel gzip library

Former-commit-id: 2c1187001f989ba3de5895f516d4c8b54d52a4c4
This commit is contained in:
2023-08-25 14:36:38 +02:00
parent 8a98210103
commit 2a11adb346
8 changed files with 233 additions and 5 deletions

40
pkg/obiutils/array.go Normal file
View File

@ -0,0 +1,40 @@
package obiutils
// Matrix is a generic type representing a matrix.
type Matrix[T any] [][]T
// Make2DArray generates a 2D array of type T with the specified number of rows and columns.
//
// Data is stored in a contiguous memory block in row-major order.
//
// Parameters:
// - rows: the number of rows in the 2D array.
// - cols: the number of columns in the 2D array.
//
// Return:
// - Matrix[T]: the generated 2D array of type T.
func Make2DArray[T any](rows, cols int) Matrix[T] {
matrix := make(Matrix[T], rows)
data := make([]T, cols*rows)
for i := 0; i < rows; i++ {
matrix[i] = data[i*cols : (i+1)*cols]
}
return matrix
}
// Row returns the i-th row of the matrix.
//
// Parameters:
//
// i - the index of the row to retrieve.
//
// Return:
//
// []T - the i-th row of the matrix.
func (matrix *Matrix[T]) Column(i int) []T {
r := make([]T, len(*matrix))
for j := 0; j < len(*matrix); j++ {
r[j] = (*matrix)[j][i]
}
return r
}