1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2025-05-21 23:21:15 +02:00

feat: first release

This commit is contained in:
Divlo
2023-01-05 21:13:10 +01:00
parent 0fa82c5772
commit cf6b7db16d
25 changed files with 486 additions and 39 deletions

View File

@ -26,7 +26,7 @@ void dictionary_add(struct dictionary *dictionary, char *key, void *data) {
}
struct dictionary_item *item = NULL;
for (size_t index = 0; index < dictionary->length && item == NULL; index++) {
if (string_get_is_equal(key, dictionary->items[index]->key)) {
if (string_equals(key, dictionary->items[index]->key)) {
item = dictionary->items[index];
}
}
@ -44,7 +44,7 @@ void dictionary_add(struct dictionary *dictionary, char *key, void *data) {
void dictionary_remove(struct dictionary *dictionary, char *key) {
bool found = false;
for (size_t index = 0; index < dictionary->length && !found; index++) {
if (string_get_is_equal(key, dictionary->items[index]->key)) {
if (string_equals(key, dictionary->items[index]->key)) {
free(dictionary->items[index]);
dictionary->items[index] = dictionary->items[dictionary->length - 1];
dictionary->length--;
@ -56,7 +56,7 @@ void dictionary_remove(struct dictionary *dictionary, char *key) {
struct dictionary_item *dictionary_get(struct dictionary *dictionary, char *key) {
for (size_t index = 0; index < dictionary->length; index++) {
struct dictionary_item *item = dictionary->items[index];
if (string_get_is_equal(key, item->key)) {
if (string_equals(key, item->key)) {
return item;
}
}

View File

@ -2,7 +2,7 @@
#include <stdbool.h>
bool mathematics_get_is_equal(const float number1, const float number2) {
bool mathematics_equals(const float number1, const float number2) {
return (number1 - number2) < MATHEMATICS_FLOAT_PRECISION;
}
@ -20,7 +20,7 @@ unsigned long long mathematics_pow(unsigned long long base, unsigned long long e
float mathematics_root(float number, unsigned int nth_root) {
float result = number;
float previous_result = 0;
while (!mathematics_get_is_equal(result, previous_result)) {
while (!mathematics_equals(result, previous_result)) {
result = (((nth_root - 1) * previous_result) + (number / mathematics_pow(result, nth_root - 1))) / nth_root;
previous_result = result;
}

View File

@ -5,7 +5,7 @@
#include <stdbool.h>
bool mathematics_get_is_equal(const float number1, const float number2);
bool mathematics_equals(const float number1, const float number2);
unsigned long long mathematics_absolute_value(const long long number);

View File

@ -142,7 +142,7 @@ char* string_reverse(const char* string) {
return result;
}
bool string_get_is_equal(const char* string1, const char* string2) {
bool string_equals(const char* string1, const char* string2) {
size_t string1_length = string_get_length(string1);
size_t string2_length = string_get_length(string2);
bool is_equal = string1_length == string2_length;

View File

@ -102,7 +102,7 @@ char* string_reverse(const char* string);
* @param string2
* @return true if the strings are equals, false otherwise
*/
bool string_get_is_equal(const char* string1, const char* string2);
bool string_equals(const char* string1, const char* string2);
/**
* @brief Check if the string is a integer.