created an incomplete implementation of a matrix
This commit is contained in:
parent
af73775dc0
commit
48acb9a639
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "matrix-operations"
|
||||
version = "0.1.0"
|
||||
16
src/lib.rs
16
src/lib.rs
@ -1,14 +1,2 @@
|
||||
pub fn add(left: u64, right: u64) -> u64 {
|
||||
left + right
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
}
|
||||
}
|
||||
//Define modules
|
||||
pub mod matrix;
|
||||
|
||||
41
src/matrix.rs
Normal file
41
src/matrix.rs
Normal file
@ -0,0 +1,41 @@
|
||||
//A matrix is constructed by chaining together elements
|
||||
|
||||
//Before even a struct, we make an enum!
|
||||
//The enum can allow us to set Number or Nothing,
|
||||
//Stopping the infinite size issues
|
||||
|
||||
//Element : either a Number or Nothing
|
||||
|
||||
//Number : a node that containes a value,
|
||||
// and points to other elements
|
||||
|
||||
|
||||
|
||||
struct Number {
|
||||
value : isize,
|
||||
// the value to the right
|
||||
// By putting the value in a Box<>, we point to a
|
||||
right : Option<Box<Number>>,
|
||||
// the value below
|
||||
below : Option<Box<Number>>
|
||||
|
||||
}
|
||||
|
||||
struct Matrix {
|
||||
size : (usize, usize),
|
||||
elements : Vec<Vec<i32>>
|
||||
}
|
||||
|
||||
|
||||
impl Matrix {
|
||||
pub fn new(rows : usize, columns : usize) -> Matrix {
|
||||
//Construct an empty vector
|
||||
let mut elements : Vec<Vec<i32>> = vec![vec![0;columns];rows];
|
||||
|
||||
Matrix {
|
||||
size : (rows , columns),
|
||||
elements : elements
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user