Struct dbscan::matrix::SymmetricMatrix
[−]
[src]
pub struct SymmetricMatrix<T> { /* fields omitted */ }
A generic symmetric matrix.
Methods
impl<T> SymmetricMatrix<T> where T: Default + Copy
[src]
fn new(size: usize) -> Self
Constructs a new symmetric matrix with the given number of rows and columns.
Each cell in the matrix is initialied to T::default()
. For example,
when T
is an integral type, each cell is initialied to 0
.
Examples
let m: SymmetricMatrix<i32> = SymmetricMatrix::new(5);
fn size(&self) -> usize
Returns the number of rows and columns of the matrix.
Examples
let m: SymmetricMatrix<i32> = SymmetricMatrix::new(5); assert_eq!(m.size(), 5);
fn get(&self, row: usize, col: usize) -> T
Returns the value of the given cell.
Since the matrix is symmetric, get(x, y)
returns the same value as
get(y, x)
.
Examples
let m = SymmetricMatrix::new(5); m.set(1, 2, 42); assert_eq!(m.get(1, 2), 42); assert_eq!(m.get(2, 1), 42);
Panics
When the given cell does not exist. For example, when the size of the
matrix is 5
, calling get(5, 1)
will panic.
fn set(&mut self, row: usize, col: usize, value: T)
Sets the value of the given cell.
Since the matrix is symmetric, set(x, y, value)
automatically sets
the value of (y, x)
.
Examples
let m = SymmetricMatrix::new(5); m.set(1, 2, 42); assert_eq!(m.get(1, 2), 42); assert_eq!(m.get(2, 1), 42);
Panics
When the given cell does not exist. For example, when the size of the
matrix is 5
, calling set(5, 1, X)
will panic.