github.com/djordje200179/extendedlibrary/datastructures@v1.7.1-0.20240227175559-d09520a92dd4/other/matrix/size.go (about) 1 package matrix 2 3 import "fmt" 4 5 // Size represents the size of a matrix. 6 type Size struct { 7 Height, Width int // Height is the number of rows, Width is the number of columns. 8 } 9 10 // Elements returns the number of elements in the matrix of the given size. 11 func (size Size) Elements() int { 12 return size.Height * size.Width 13 } 14 15 // Transposed returns the size of a transposed matrix. 16 func (size Size) Transposed() Size { 17 return Size{size.Width, size.Height} 18 } 19 20 // Index returns the index of the element at the given row and column. 21 func (size Size) Index(row, column int) int { 22 return row*size.Width + column 23 } 24 25 // String returns a string representation of the size. 26 func (size Size) String() string { 27 return fmt.Sprintf("(%d, %d)", size.Height, size.Width) 28 }