From 53dcfcb30b55fcc5a93407e3856d9cba85318559 Mon Sep 17 00:00:00 2001 From: teridax Date: Wed, 3 May 2023 11:02:03 +0200 Subject: [PATCH] updated READMEs --- README.md | 6 +++++- duplicates/README.md | 5 +++++ fibonacci/README.md | 8 ++++++++ fibonacci/src/main.rs | 7 ++++--- line/README.md | 4 ++++ sparse_vector/README.md | 22 ++++++++++++++++++++-- str_sort/README.md | 8 ++++++++ tuple_arithmetic/README.md | 5 +++++ 8 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 duplicates/README.md create mode 100644 fibonacci/README.md create mode 100644 line/README.md create mode 100644 str_sort/README.md create mode 100644 tuple_arithmetic/README.md diff --git a/README.md b/README.md index 031d704..e4bf3c4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # Rust-Programming -Repository hosting code of the excercises made during class \ No newline at end of file +Repository hosting code of the excercises made during class. + +The projects are not sorted chronologically. + +The entire repository and all of its content are licensed under GPLv2 or later with exceptions to specific pieces of code written by the lecturer without licencse notice. diff --git a/duplicates/README.md b/duplicates/README.md new file mode 100644 index 0000000..37adec3 --- /dev/null +++ b/duplicates/README.md @@ -0,0 +1,5 @@ +# Duplicates + +This project implements functionality to store either a floating point number or a character inside of an enumeration. A function can then find any duplicates in an array of these enumerations. + +Licensed under GPLv2 or later, same as the entire repository diff --git a/fibonacci/README.md b/fibonacci/README.md new file mode 100644 index 0000000..5066daf --- /dev/null +++ b/fibonacci/README.md @@ -0,0 +1,8 @@ +# Fibonacci + +This project implements two version of the famous fibonacci sequence: + +* an iterative one +* and a recursive one + +Licensed under GPLv2 or later, same as the entire repository \ No newline at end of file diff --git a/fibonacci/src/main.rs b/fibonacci/src/main.rs index 8f625c2..33ee974 100644 --- a/fibonacci/src/main.rs +++ b/fibonacci/src/main.rs @@ -16,7 +16,6 @@ */ /// recursive variant of the fibonacci function -#[allow(dead_code)] fn fib_rec(x: u128) -> u128 { if x < 2 { return x; @@ -26,7 +25,7 @@ fn fib_rec(x: u128) -> u128 { } /// iterative variant of the fibonacci function -fn fib_loop(x: u128) -> u128 { +fn fib_iter(x: u128) -> u128 { let mut sum = 0; let mut sum2 = 1; @@ -39,5 +38,7 @@ fn fib_loop(x: u128) -> u128 { } fn main() { - println!("{}", fib_loop(5)); + const VALUE: u128 = 23; + println!("fibonacci iterative of {VALUE}: {}", fib_iter(VALUE)); + println!("fibonacci recursive of {VALUE}: {}", fib_rec(VALUE)); } diff --git a/line/README.md b/line/README.md new file mode 100644 index 0000000..6082a03 --- /dev/null +++ b/line/README.md @@ -0,0 +1,4 @@ +# Shapes and lines +Implements some traits provided by the lecturer regarding the calculation of various distance to the origin function for various shapes. + +Licensed under GPLv2 or later, same as the entire repository \ No newline at end of file diff --git a/sparse_vector/README.md b/sparse_vector/README.md index 883e490..c3c81bd 100644 --- a/sparse_vector/README.md +++ b/sparse_vector/README.md @@ -19,6 +19,10 @@ Though this comes a the cost that we may need to decide between memory saving an ### Index Array +> **NOTE** +> +> Due to poor choice of names and lazyness the implementation can only be found in the branch `compressed_indices_2` + We can omit all zero elements by storing an index array alongside all non zero values. Each value will be associated with an index in from the index array. This model is only efficient in memory size when the amount of zero elements is at least 50%. Since I used `usize` to store the indices, which is equal to a `u64` in 64-bit architectures, The required memory is: ``` @@ -29,12 +33,22 @@ One significant downside is the cost of finding each corresponding entry when pe ### Hashmap Implementation +> **NOTE** +> +> Due to poor choice of names and lazyness the implementation can only be found in the branch `hashmap` + This implementation uses a hashmap to associate a value with its corresponding index in the vectors column. In Theory this should be as efficient in memory size as the previous array index method. But in comparision this method requires signifacantly more memory since a hashmap allocates more memory than it can fill in order to reduce collisions. It has one significant benefit, that being speed in calculations. Looking up values in a hashmap is generally faster than performing a binary seach. Also inserting and deleting is an O(1) operation. +> NOTE +> +> Two implementations of the dot product can be found: +> +> One implemented with a simple loop and one with a binary search. From testing I can say, that the simple loop variant is significanty faster than the crude binary search. + ### Compressed Index Array In order to reduce the size required to store the indices of each value we can compress them by only storing the relative offset to the previous value: @@ -50,12 +64,14 @@ In this implementation I reduced to size from 64 to 16 bit. This makes memory us ### Binary Heap -The binary heap has the advantage of being fast with inserting, removing and looking up values. +Implementation can be found in the main branch. + +The binary heap has the advantage of being fast with inserting, removing and looking up values in logarithmic time. We use indices again to sort the values of the vector into to binary heap. ## Comparision -The following values were achieved by using a randomly initialized vector with a length of 10^10 elements from which 2% were non zero. The dot product implementation was single threaded. +The following values were achieved by using a randomly initialized vector with a length of 10^10 elements from which 2% were non zero. The dot product implementation was single threaded and run in release mode on hyperthreaded intel hardware. | Implementation | Size on Heap (GB) | Runtime of dot product (s) | @@ -65,3 +81,5 @@ The following values were achieved by using a randomly initialized vector with a | Hashmap | 5.4 | 0.732189927 | | Compressed Index Array | 2.0 | > 120 | | Binary Heap | 1.3 | 2.089960966 | + +Licensed under GPLv2 or later, same as the entire repository diff --git a/str_sort/README.md b/str_sort/README.md new file mode 100644 index 0000000..8543723 --- /dev/null +++ b/str_sort/README.md @@ -0,0 +1,8 @@ +# String sorting +This repository contains a set of functions to sort the characters of a string. +Various different functions are available: +* sort the ascii characters only (unsafe but efficient) +* sort the UTF-8 characters (requires memory allocation) +* sort the UTF-8 characters (more complex implementation but efficient) + +Licensed under GPLv2 or later, same as the entire repository \ No newline at end of file diff --git a/tuple_arithmetic/README.md b/tuple_arithmetic/README.md new file mode 100644 index 0000000..0da478f --- /dev/null +++ b/tuple_arithmetic/README.md @@ -0,0 +1,5 @@ +# Tuple Arithmetic +This project contains some implementations of arithmetic operators for pairs of floating point numbers. +Note: no trait implementation is provided since at the time of writing this project trait were out of scope for the lesson. + +Licensed under GPLv2 or later, same as the entire repository \ No newline at end of file