From 0591d86aab23e5a872def99affe657805ae396f2 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Fri, 22 Mar 2024 14:24:09 +0100 Subject: [PATCH] add comments to all public interfaces --- lab1/zad1/include/mod.h | 15 +++++++++++++++ lab1/zad2/src/module.ads | 7 +++++++ lab1/zad3/src/module.rs | 6 ++++++ lab1/zad4/include/wrapper.h | 15 +++++++++++++++ lab1/zad5/include/mod.h | 15 +++++++++++++++ lab1/zad6/src/main.rs | 7 +++++++ lab1/zad7/c/wrapper.h | 15 +++++++++++++++ 7 files changed, 80 insertions(+) diff --git a/lab1/zad1/include/mod.h b/lab1/zad1/include/mod.h index f8a651a..f59b3e3 100644 --- a/lab1/zad1/include/mod.h +++ b/lab1/zad1/include/mod.h @@ -3,15 +3,30 @@ #include +/* + * computes the factorial of n + * only works on natural numbers + */ uint64_t factorial(uint64_t n); +/* + * computes the gcd of a and b + * only works on natural numbers + */ uint64_t gcd(uint64_t a, uint64_t b); +/* + * the solution of a linear diophantine equation + */ typedef struct { int64_t n; int64_t m; } Result; +/* + * computes the solution of a linear diophantine equation ax + by = c + * or returns NULL if it doesn't exist + */ Result *diophantine(int64_t a, int64_t b, int64_t c); #endif // _JPP_L1_Z1_MOD_H diff --git a/lab1/zad2/src/module.ads b/lab1/zad2/src/module.ads index 1883853..2140da0 100644 --- a/lab1/zad2/src/module.ads +++ b/lab1/zad2/src/module.ads @@ -3,16 +3,23 @@ with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; package Module is + -- computes the factorial of n + -- only works on natural numbers function gcd(a : Natural; b : Natural) return Natural; + -- computes the gcd of a and b + -- only works on natural numbers function factorial(n : Natural) return Natural; + -- the solution of a linear diophantine equation type Result is record resultExists : Boolean; n : Integer; m : Integer; end record; + -- computes the solution of a linear diophantine equation ax + by = c + -- if the solution doesn't exist Result::resultExists == false function diophantine(a : Integer; b : Integer; c : Integer) return Result; end Module; diff --git a/lab1/zad3/src/module.rs b/lab1/zad3/src/module.rs index 6e83c7a..1f2a1e8 100644 --- a/lab1/zad3/src/module.rs +++ b/lab1/zad3/src/module.rs @@ -1,8 +1,14 @@ pub trait Module { + /// computes the factorial of n + /// only works on natural numbers fn factorial(&self, n: u64) -> u64; + /// computes the gcd of a and b + /// only works on natural numbers fn gcd(&self, a: u64, b: u64) -> u64; + /// computes the solution of a linear diophantine equation ax + by = c + /// or returns None if it doesn't exist fn diophantine(&self, a: i64, b: i64, c: i64) -> Option<(i64, i64)>; } diff --git a/lab1/zad4/include/wrapper.h b/lab1/zad4/include/wrapper.h index 8b3531f..1cbe52d 100644 --- a/lab1/zad4/include/wrapper.h +++ b/lab1/zad4/include/wrapper.h @@ -3,16 +3,31 @@ #include +/* + * computes the gcd of a and b + * only works on natural numbers + */ extern unsigned int gcd(unsigned int a, unsigned int b); +/* + * computes the factorial of n + * only works on natural numbers + */ extern unsigned int factorial(unsigned int n); +/* + * the solution of a linear diophantine equation + */ typedef struct { bool resultExists; int n; int m; } Result; +/* + * computes the solution of a linear diophantine equation ax + by = c + * if the solution doesn't exist Result::resultExists == false + */ extern Result diophantine(int a, int b, int c); #endif // _JPP_L1_Z4_WRAPPER_H diff --git a/lab1/zad5/include/mod.h b/lab1/zad5/include/mod.h index 4a827dc..e36913d 100644 --- a/lab1/zad5/include/mod.h +++ b/lab1/zad5/include/mod.h @@ -4,16 +4,31 @@ #include #include +/* + * computes the factorial of n + * only works on natural numbers + */ unsigned int factorial(unsigned int n); +/* + * computes the gcd of a and b + * only works on natural numbers + */ unsigned int gcd(unsigned int a, unsigned int b); +/* + * the solution of a linear diophantine equation + */ typedef struct { bool resultExists; int n; int m; } Result; +/* + * computes the solution of a linear diophantine equation ax + by = c + * if the solution doesn't exist Result::resultExists == false + */ Result diophantine(int a, int b, int c); #endif // _JPP_L1_Z5_MOD_H diff --git a/lab1/zad6/src/main.rs b/lab1/zad6/src/main.rs index b63f4d3..c281786 100644 --- a/lab1/zad6/src/main.rs +++ b/lab1/zad6/src/main.rs @@ -1,5 +1,6 @@ use std::{env, process::exit}; +/// the solution of a linear diophantine equation #[repr(C)] pub struct Result { pub resultExists: libc::c_int, @@ -8,10 +9,16 @@ pub struct Result { } extern "C" { + /// computes the gcd of a and b + /// only works on natural numbers pub fn gcd(a: libc::c_uint, b: libc::c_uint) -> libc::c_uint; + /// computes the factorial of n + /// only works on natural numbers pub fn factorial(n: libc::c_uint) -> libc::c_uint; + /// computes the solution of a linear diophantine equation ax + by = c + /// if the solution doesn't exist Result::resultExists == false pub fn diophantine(a: libc::c_int, b: libc::c_int, c: libc::c_int) -> Result; } diff --git a/lab1/zad7/c/wrapper.h b/lab1/zad7/c/wrapper.h index 1e45105..ea758f6 100644 --- a/lab1/zad7/c/wrapper.h +++ b/lab1/zad7/c/wrapper.h @@ -3,16 +3,31 @@ #include +/* + * computes the gcd of a and b + * only works on natural numbers + */ extern unsigned int gcd(unsigned int a, unsigned int b); +/* + * computes the factorial of n + * only works on natural numbers + */ extern unsigned int factorial(unsigned int n); +/* + * the solution of a linear diophantine equation + */ typedef struct { bool resultExists; int n; int m; } Result; +/* + * computes the solution of a linear diophantine equation ax + by = c + * if the solution doesn't exist Result::resultExists == false + */ extern Result diophantine(int a, int b, int c); #endif // _JPP_L1_Z7_WRAPPER_H