updated READMEs

This commit is contained in:
Sven Vogel 2023-05-03 11:02:03 +02:00
parent 4342c25e3e
commit 53dcfcb30b
8 changed files with 59 additions and 6 deletions

View File

@ -1,3 +1,7 @@
# Rust-Programming
Repository hosting code of the excercises made during class
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.

5
duplicates/README.md Normal file
View File

@ -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

8
fibonacci/README.md Normal file
View File

@ -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

View File

@ -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));
}

4
line/README.md Normal file
View File

@ -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

View File

@ -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

8
str_sort/README.md Normal file
View File

@ -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

View File

@ -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