mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Add some doc and switch to the parallel gzip library
Former-commit-id: 2c1187001f989ba3de5895f516d4c8b54d52a4c4
This commit is contained in:
40
pkg/obiutils/array.go
Normal file
40
pkg/obiutils/array.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user