From fd7fcec45773a578c29ac43b47470b5602cc9846 Mon Sep 17 00:00:00 2001 From: Matyas Date: Wed, 5 Apr 2023 15:25:13 +0200 Subject: [PATCH] knihovny --- Makefile | 23 +- cppoutput | 318 ------------------------- dep.d | 14 ++ src/htab.h => htab.h | 0 htab_bucket_count.c | 9 + htab_clear.c | 21 ++ htab_erase.c | 36 +++ htab_find.c | 18 ++ htab_for_each.c | 16 ++ htab_free.c | 11 + htab_hash_function.c | 13 + htab_init.c | 26 ++ htab_lookup_add.c | 45 ++++ htab_size.c | 9 + htab_statistics.c | 42 ++++ src/io.c => io.c | 0 src/io.h => io.h | 0 private_htab.h | 16 ++ src/htab.c | 212 ----------------- src/tail.c => tail.c | 0 src/to_je_jedno.cpp => to_je_jedno.cpp | 0 wcoutput | 318 ------------------------- src/wordcount.c => wordcount.c | 0 23 files changed, 289 insertions(+), 858 deletions(-) delete mode 100644 cppoutput create mode 100644 dep.d rename src/htab.h => htab.h (100%) create mode 100644 htab_bucket_count.c create mode 100644 htab_clear.c create mode 100644 htab_erase.c create mode 100644 htab_find.c create mode 100644 htab_for_each.c create mode 100644 htab_free.c create mode 100644 htab_hash_function.c create mode 100644 htab_init.c create mode 100644 htab_lookup_add.c create mode 100644 htab_size.c create mode 100644 htab_statistics.c rename src/io.c => io.c (100%) rename src/io.h => io.h (100%) create mode 100644 private_htab.h delete mode 100644 src/htab.c rename src/tail.c => tail.c (100%) rename src/to_je_jedno.cpp => to_je_jedno.cpp (100%) delete mode 100644 wcoutput rename src/wordcount.c => wordcount.c (100%) diff --git a/Makefile b/Makefile index d5d902c..31754cd 100644 --- a/Makefile +++ b/Makefile @@ -2,11 +2,15 @@ CC := clang CFLAGS := -g -Wall -std=c11 -pedantic -DSTATISTICS -Wextra -O2 CREATEDIR := $(shell mkdir -p obj) +DEPENDENCIES:=$(shell $(CC) -MM *.c | sed -r 's/.*:.*/obj\/\0/' > dep.d) + +-include dep.d + .PHONY: all all: tail wordcount wordcount-dynamic # a knihovny "libhtab.a", "libhtab.so -cpp: src/to_je_jedno.cpp +cpp: to_je_jedno.cpp clang++ -O3 $^ -o $@ tail: obj/tail.o @@ -15,19 +19,18 @@ tail: obj/tail.o wordcount: obj/io.o obj/htab.o obj/wordcount.o libhtab.a $(CC) $(CFLAGS) -lm $^ -o $@ -wordcount-dynamic: obj/wordcount.o obj/htab.o libhtab.so +wordcount-dynamic: obj/wordcount-dynamic.o obj/htab.o libhtab.so $(CC) $(CFLAGS) -lm $^ -o $@ - -obj/wordcount.o: src/wordcount.c src/io.h src/htab.h -obj/io.o: src/io.c -obj/htab.o: src/htab.c src/htab.h -obj/tail.o: src/tail.c - -obj/%.o: src/%.c +%.o: %.c $(CC) $(CFLAGS) $< -c -o $@ +lib/libhtab.a: obj/htab_bucket_count.o obj/htab_clear.o obj/htab_erase.o obj/htab_find.o obj/htab_for_each.o obj/htab_free.o obj/htab_hash_function.o obj/htab_init.o obj/htab_lookup_add.o obj/htab_size.o obj/htab_statistics.o + ar r $@ $^ + +lib/libhtab.so: obj/htab_bucket_count.o obj/htab_clear.o obj/htab_erase.o obj/htab_find.o obj/htab_for_each.o obj/htab_free.o obj/htab_hash_function.o obj/htab_init.o obj/htab_lookup_add.o obj/htab_size.o obj/htab_statistics.o + $(CC) -shared $^ -o $@ .PHONY: clean clean: - -rm -r ./obj/ tail wordcount cpp + -rm -r ./obj/ tail wordcount cpp *.o diff --git a/cppoutput b/cppoutput deleted file mode 100644 index d4cff06..0000000 --- a/cppoutput +++ /dev/null @@ -1,318 +0,0 @@ -!= 1 -!cb->data) 1 -!num_read) 1 -""); 3 -"", 1 -"--help") 1 -"--number") 1 -"-h") 1 -"-n") 1 -"Counldn't 1 -"r"); 1 -#define 1 -#include 5 -%38sinstead 1 -%= 3 -%s 1 -%s\n", 1 -&& 1 -'\0' 1 -'\n') 1 -(!buffer) 1 -(!buffer->data) 1 -(!cb 1 -(!discard_rest) 2 -(!exceeded) 1 -(!file_read) 1 -(!stream) 1 -(!tmp_string) 2 -((strcmp(argv[i], 1 -((tmp_char 1 -(NUM 1 -(argc 1 -(cb->count 2 -(cb->count) 1 -(cb->data[i]) 1 -(i 1 -(int 1 -(kind 1 -(old_string) 1 -(size 2 -(size_t 1 -(strcmp(argv[i], 1 -(tmp_char 1 -(tmp_string) 1 -*)); 1 -**argv) 1 -**data; 1 -*/ 2 -*buffer 1 -*cb 1 -*cb) 2 -*cb, 2 -*cb_create(size_t 1 -*cb_get(cb_t 1 -*cb_put(cb_t 1 -*curr_line 1 -*file_name) 1 -*line) 1 -*old_string 1 -*stream 1 -*stream) 1 -*tmp_string 1 -+ 4 -++i) 1 -++i; 1 ---help 1 ---help%26sprints 1 ---number 2 --h 1 --n 2 -/* 2 -// 23 -0 3 -0) 3 -0),\n\ 1 -0; 8 -1 1 -1) 2 -1), 1 -10 1 -10.0.0-4ubuntu1 1 -10; 1 -10\n\n", 1 -18.4.2023 1 -1; 5 -1]); 1 -4095 1 -< 3 -<= 1 - 1 - 1 - 1 - 1 - 1 -= 32 -== 7 -> 3 ->= 1 -Autor: 1 -EOF) 1 -FILE 3 -FILE, 1 -FIT 1 -IJC-DU2, 1 -LONG_MAX) 1 -MAX_LINE_SIZE 1 -MAX_LINE_SIZE) 1 -Mandatory 1 -Matyáš 1 -NULL; 3 -NUM 1 -NUM%20soutput 1 -OPTION%30sFUNCTION\n", 1 -Oujezdský, 1 -Přeloženo: 1 -With 1 -[FILE]\n", 1 -[OPTION] 1 -\n 2 -a 4 -allocate 4 -allocated 1 -and 7 -are 1 -argc 1 -argc, 1 -argc; 1 -argument 4 -arguments 1 -argv[i]); 1 -array 1 -at 4 -atoi(argv[i 1 -be 2 -big 1 -bool 4 -buffer 6 -buffer->count 1 -buffer->data 1 -buffer->end 1 -buffer->size 1 -buffer->start 1 -buffer; 1 -buffer\n", 2 -by 2 -calloc(n, 1 -cb 1 -cb->count++; 1 -cb->count--; 1 -cb->data[cb->end++] 1 -cb->data[cb->end]; 1 -cb->data[cb->start++]; 1 -cb->end 1 -cb->size) 1 -cb->size; 4 -cb->start 2 -cb->start++; 1 -cb_create(size); 1 -cb_free(cb); 1 -cb_free(cb_t 1 -cb_get(cb)); 1 -cb_put 2 -cb_put(cb, 1 -cb_t 3 -cb_t; 1 -char 8 -character 1 -chech 1 -check 1 -circular 3 -circural 1 -clang 1 -count; 1 -curr_line; 1 -current 1 -cycle 1 -discard_rest 2 -each 2 -else 2 -empty\n", 1 -end 1 -end; 1 -every 1 -exceeded 2 -false; 4 -fgetc(stream)) 1 -file 4 -file_name); 1 -file_read 2 -first 2 -fopen(argv[i], 1 -for 7 -fprintf(stderr, 1 -fputs("buffer 1 -fputs("couldn't 3 -fputs("exceeded 1 -free 1 -free(buffer); 1 -free(cb); 1 -free(cb->data); 1 -free(cb->data[i]); 1 -free(tmp_string); 1 -from 1 -happens 1 -help 2 -help\n", 1 -i 8 -i++) 1 -i++; 1 -if 24 -in 3 -increase 2 -index 2 -input 1 -input.\n\n\ 1 -inputed 1 -instance 1 -int 3 -is 3 -it 2 -last 4 -length\n", 1 -line 5 -line; 1 -lines 5 -long 1 -loop 1 -main(int 1 -make 1 -malloc(MAX_LINE_SIZE); 2 -malloc(sizeof(cb_t)); 1 -mandatory 1 -max 1 -memory 4 -must 1 -n) 1 -n; 1 -name 1 -names 1 -neccesary 1 -negative 1 -next 3 -no 1 -not 1 -num_read 2 -number 4 -numbers 1 -of 11 -old_string; 1 -only 1 -open 2 -options 2 -or 5 -output.\n\n\ 1 -part 1 -passed, 2 -pointer 5 -print 2 -print_help(argv[0]); 3 -print_help(char 1 -printf("%s\n", 1 -printf("-h, 1 -printf("-n, 1 -printf("Print 1 -printf("Usage: 1 -příklad 1 -read 6 -read_file(cb, 1 -read_file(cb_t 1 -reads 1 -return 13 -return; 1 -self-explainatory) 1 -send 1 -sends 1 -set 1 -short 1 -size 3 -size; 1 -size_t 5 -sizeof(char 1 -skip 1 -so 2 -standard 2 -start; 1 -stderr); 5 -stdin; 1 -strcmp(argv[i], 2 -stream 1 -stream); 1 -string 3 -struct 1 -sure 1 -tail.c 1 -the 12 -there 1 -this 2 -tmp_char; 2 -tmp_string 2 -tmp_string", 1 -tmp_string); 1 -tmp_string[i] 2 -to 8 -too 1 -too.\n\n\ 1 -true; 4 -typedef 1 -version 1 -void 3 -was 2 -while 2 -with 2 -write 2 -zero 1 -{ 34 -|| 4 -} 34 -Řešení 1 diff --git a/dep.d b/dep.d new file mode 100644 index 0000000..dd19fbe --- /dev/null +++ b/dep.d @@ -0,0 +1,14 @@ +obj/htab_bucket_count.o: htab_bucket_count.c private_htab.h htab.h +obj/htab_clear.o: htab_clear.c private_htab.h htab.h +obj/htab_erase.o: htab_erase.c private_htab.h htab.h +obj/htab_find.o: htab_find.c private_htab.h htab.h +obj/htab_for_each.o: htab_for_each.c private_htab.h htab.h +obj/htab_free.o: htab_free.c private_htab.h htab.h +obj/htab_hash_function.o: htab_hash_function.c htab.h +obj/htab_init.o: htab_init.c private_htab.h htab.h +obj/htab_lookup_add.o: htab_lookup_add.c private_htab.h htab.h +obj/htab_size.o: htab_size.c private_htab.h htab.h +obj/htab_statistics.o: htab_statistics.c private_htab.h htab.h +obj/io.o: io.c +obj/tail.o: tail.c +obj/wordcount.o: wordcount.c io.h htab.h diff --git a/src/htab.h b/htab.h similarity index 100% rename from src/htab.h rename to htab.h diff --git a/htab_bucket_count.c b/htab_bucket_count.c new file mode 100644 index 0000000..476b7bb --- /dev/null +++ b/htab_bucket_count.c @@ -0,0 +1,9 @@ +// htab_bucket_count.c +// Řešení IJC-DU2, příklad 1), 18.4.2023 +// Autor: Matyáš Oujezdský, FIT +// Přeloženo: clang version 10.0.0-4ubuntu1 +#include "private_htab.h" + +size_t htab_bucket_count(const htab_t *t) { + return t->arr_size; +} diff --git a/htab_clear.c b/htab_clear.c new file mode 100644 index 0000000..e044799 --- /dev/null +++ b/htab_clear.c @@ -0,0 +1,21 @@ +// htab_clear.c +// Řešení IJC-DU2, příklad 1), 18.4.2023 +// Autor: Matyáš Oujezdský, FIT +// Přeloženo: clang version 10.0.0-4ubuntu1 +#include "private_htab.h" + + +void htab_clear(htab_t *t) { + struct htab_item *tmp_ptr; + for (size_t i = 0; i < t->arr_size; ++i) { + tmp_ptr = t->arr_ptr[i]; + while (tmp_ptr) { + struct htab_item *curr_ptr = tmp_ptr; + tmp_ptr = tmp_ptr->next; + free((char*)curr_ptr->data.key); + free(curr_ptr); + } + } + + t->size = 0; +} diff --git a/htab_erase.c b/htab_erase.c new file mode 100644 index 0000000..af7ff67 --- /dev/null +++ b/htab_erase.c @@ -0,0 +1,36 @@ +// htab_erase.c +// Řešení IJC-DU2, příklad 1), 18.4.2023 +// Autor: Matyáš Oujezdský, FIT +// Přeloženo: clang version 10.0.0-4ubuntu1 +#include "private_htab.h" + +bool htab_erase(htab_t *t, htab_key_t key) { + size_t index = (htab_hash_function(key) % t->arr_size); + struct htab_item *curr_item = t->arr_ptr[index]; + struct htab_item *last_item; + + if (!curr_item) { + return false; + } + + if (strcmp(curr_item->data.key, key) == 0) { + t->arr_ptr[index] = curr_item->next; + free((char*)curr_item->data.key); + free(curr_item); + t->size--; + return true; + } + + while (curr_item) { + if (strcmp(curr_item->data.key, key) == 0) { + last_item->next = curr_item->next; + free((char*)curr_item->data.key); + free(curr_item); + t->size--; + return true; + } + last_item = curr_item; + curr_item = curr_item->next; + } + return false; +} diff --git a/htab_find.c b/htab_find.c new file mode 100644 index 0000000..93c1dd7 --- /dev/null +++ b/htab_find.c @@ -0,0 +1,18 @@ +// htab_find.c +// Řešení IJC-DU2, příklad 1), 18.4.2023 +// Autor: Matyáš Oujezdský, FIT +// Přeloženo: clang version 10.0.0-4ubuntu1 +#include "private_htab.h" + +htab_pair_t *htab_find(const htab_t *t, htab_key_t key) { + size_t index = (htab_hash_function(key) % t->arr_size); + struct htab_item *curr_item = t->arr_ptr[index]; + while (curr_item) { + if (strcmp(curr_item->data.key, key) == 0) { + return &(curr_item->data); + } + + curr_item = curr_item->next; + } + return NULL; +} diff --git a/htab_for_each.c b/htab_for_each.c new file mode 100644 index 0000000..d0c4ee0 --- /dev/null +++ b/htab_for_each.c @@ -0,0 +1,16 @@ +// htab_for_each.c +// Řešení IJC-DU2, příklad 1), 18.4.2023 +// Autor: Matyáš Oujezdský, FIT +// Přeloženo: clang version 10.0.0-4ubuntu1 +#include "private_htab.h" + +void htab_for_each(const htab_t *t, void (*f)(htab_pair_t *data)) { + struct htab_item *tmp_ptr; + for (size_t i = 0; i < t->arr_size; ++i) { + tmp_ptr = t->arr_ptr[i]; + while (tmp_ptr) { + f(&tmp_ptr->data); + tmp_ptr = tmp_ptr->next; + } + } +} diff --git a/htab_free.c b/htab_free.c new file mode 100644 index 0000000..46d9c05 --- /dev/null +++ b/htab_free.c @@ -0,0 +1,11 @@ +// htab_free.c +// Řešení IJC-DU2, příklad 1), 18.4.2023 +// Autor: Matyáš Oujezdský, FIT +// Přeloženo: clang version 10.0.0-4ubuntu1 +#include "private_htab.h" + +void htab_free(htab_t *t) { + htab_clear(t); + free(t->arr_ptr); + free(t); +} diff --git a/htab_hash_function.c b/htab_hash_function.c new file mode 100644 index 0000000..e8091f5 --- /dev/null +++ b/htab_hash_function.c @@ -0,0 +1,13 @@ +// htab_hash_function.c +// Řešení IJC-DU2, příklad 1), 18.4.2023 +// Autor: Matyáš Oujezdský, FIT +// Přeloženo: clang version 10.0.0-4ubuntu1 +#include "htab.h" + +size_t htab_hash_function(htab_key_t str) { + unsigned h = 0; // musí mít 32 bitů + const unsigned char *p; + for(p = (const unsigned char*)str; *p != '\0'; p++) + h = 65599 * h + *p; + return h; +} diff --git a/htab_init.c b/htab_init.c new file mode 100644 index 0000000..b34d91b --- /dev/null +++ b/htab_init.c @@ -0,0 +1,26 @@ +// htab_init.c +// Řešení IJC-DU2, příklad 1), 18.4.2023 +// Autor: Matyáš Oujezdský, FIT +// Přeloženo: clang version 10.0.0-4ubuntu1 +#include +#include "private_htab.h" + +htab_t *htab_init(const size_t n) { + htab_t *t = malloc(sizeof(htab_t)); + if (!t) { + fputs("couldn't allocate memory for hash tab", stderr); + return NULL; + } + + t->arr_ptr = calloc(n, sizeof(struct htab_item*)); + if (!t->arr_ptr) { + fputs("couldn't allocate memory for array of pointers", stderr); + free(t); + return NULL; + } + + t->size = 0; + t->arr_size = n; + + return t; +} diff --git a/htab_lookup_add.c b/htab_lookup_add.c new file mode 100644 index 0000000..12f84cc --- /dev/null +++ b/htab_lookup_add.c @@ -0,0 +1,45 @@ +// htab_lookup_add.c +// Řešení IJC-DU2, příklad 1), 18.4.2023 +// Autor: Matyáš Oujezdský, FIT +// Přeloženo: clang version 10.0.0-4ubuntu1 +#include +#include "private_htab.h" + +htab_pair_t *htab_lookup_add(htab_t *t, htab_key_t key) { + htab_pair_t *return_pair; + if ((return_pair = htab_find(t, key))) { + return_pair->value++; + return return_pair; + } + + struct htab_item *item_to_add = calloc(1, sizeof(struct htab_item)); + if (!item_to_add) { + fputs("couldn't allocate memory for item to add", stderr); + return NULL; + } + + size_t key_size = strlen(key) + 1; + char *key_to_add = malloc(key_size); + if (!key_to_add) { + fputs("couldn't allocate memory for key in item to add", stderr); + free(item_to_add); + return NULL; + } + + t->size++; + + memcpy(key_to_add, key, key_size); + struct htab_pair data_to_add = {.key = key_to_add, .value = 1}; + item_to_add->data = data_to_add; + + size_t index = (htab_hash_function(key) % t->arr_size); + if (!t->arr_ptr[index]) { + t->arr_ptr[index] = item_to_add; + return return_pair; + } + else { + item_to_add->next = t->arr_ptr[index]; + t->arr_ptr[index] = item_to_add; + return return_pair; + } +} diff --git a/htab_size.c b/htab_size.c new file mode 100644 index 0000000..56c6475 --- /dev/null +++ b/htab_size.c @@ -0,0 +1,9 @@ +// htab_size.c +// Řešení IJC-DU2, příklad 1), 18.4.2023 +// Autor: Matyáš Oujezdský, FIT +// Přeloženo: clang version 10.0.0-4ubuntu1 +#include "private_htab.h" + +size_t htab_size(const htab_t *t) { + return t->size; +} diff --git a/htab_statistics.c b/htab_statistics.c new file mode 100644 index 0000000..f655fd6 --- /dev/null +++ b/htab_statistics.c @@ -0,0 +1,42 @@ +// htab_statistics.c +// Řešení IJC-DU2, příklad 1), 18.4.2023 +// Autor: Matyáš Oujezdský, FIT +// Přeloženo: clang version 10.0.0-4ubuntu1 +#include "private_htab.h" + +void htab_statistics(const htab_t *t) { + struct htab_item *tmp_ptr; + size_t item_count = 0; + double nonempty_count = 0; + size_t min = 0; + size_t max = 0; + double avg = 0; + for (size_t i = 0; i < t->arr_size; ++i) { + if (!t->arr_ptr[i]) { + continue; + } + + tmp_ptr = t->arr_ptr[i]; + ++nonempty_count; + + item_count = 0; + while (tmp_ptr) { + ++item_count; + tmp_ptr = tmp_ptr->next; + } + + if (max < item_count) { + max = item_count; + } + + if (min > item_count || min == 0) { + min = item_count; + } + } + avg = t->size / nonempty_count; + + printf("min: %zu\n", min); + printf("max: %zu\n", max); + printf("avg: %lf\n", avg); + +} diff --git a/src/io.c b/io.c similarity index 100% rename from src/io.c rename to io.c diff --git a/src/io.h b/io.h similarity index 100% rename from src/io.h rename to io.h diff --git a/private_htab.h b/private_htab.h new file mode 100644 index 0000000..053d45e --- /dev/null +++ b/private_htab.h @@ -0,0 +1,16 @@ +// private_htab_h.h +// Řešení IJC-DU2, příklad 1), 18.4.2023 +// Autor: Matyáš Oujezdský, FIT +// Přeloženo: clang version 10.0.0-4ubuntu1 +#include "htab.h" + +struct htab_item { + htab_pair_t data; + struct htab_item *next; +}; + +struct htab { + size_t size; + size_t arr_size; + struct htab_item **arr_ptr; +}; diff --git a/src/htab.c b/src/htab.c deleted file mode 100644 index 6d48897..0000000 --- a/src/htab.c +++ /dev/null @@ -1,212 +0,0 @@ -// htab.c -// Řešení IJC-DU2, příklad 1), 18.4.2023 -// Autor: Matyáš Oujezdský, FIT -// Přeloženo: clang version 10.0.0-4ubuntu1 -#include -#include -#include -#include "htab.h" - -struct htab_item { - htab_pair_t data; - struct htab_item *next; -}; - -struct htab { - size_t size; - size_t arr_size; - struct htab_item **arr_ptr; -}; - -size_t htab_hash_function(htab_key_t str) { - unsigned h = 0; // musí mít 32 bitů - const unsigned char *p; - for(p = (const unsigned char*)str; *p != '\0'; p++) - h = 65599 * h + *p; - return h; -} - -htab_t *htab_init(const size_t n) { - htab_t *t = malloc(sizeof(htab_t)); - if (!t) { - fputs("couldn't allocate memory for hash tab", stderr); - return NULL; - } - - t->arr_ptr = calloc(n, sizeof(struct htab_item*)); - if (!t->arr_ptr) { - fputs("couldn't allocate memory for array of pointers", stderr); - free(t); - return NULL; - } - - t->size = 0; - t->arr_size = n; - - return t; -} - -size_t htab_size(const htab_t *t) { - return t->size; -} - -size_t htab_bucket_count(const htab_t *t) { - return t->arr_size; -} - -htab_pair_t *htab_find(const htab_t *t, htab_key_t key) { - size_t index = (htab_hash_function(key) % t->arr_size); - struct htab_item *curr_item = t->arr_ptr[index]; - while (curr_item) { - if (strcmp(curr_item->data.key, key) == 0) { - return &(curr_item->data); - } - - curr_item = curr_item->next; - } - return NULL; -} - -htab_pair_t *htab_lookup_add(htab_t *t, htab_key_t key) { - htab_pair_t *return_pair; - if ((return_pair = htab_find(t, key))) { - return_pair->value++; - return return_pair; - } - - struct htab_item *item_to_add = calloc(1, sizeof(struct htab_item)); - if (!item_to_add) { - fputs("couldn't allocate memory for item to add", stderr); - return NULL; - } - - size_t key_size = strlen(key) + 1; - char *key_to_add = malloc(key_size); - if (!key_to_add) { - fputs("couldn't allocate memory for key in item to add", stderr); - free(item_to_add); - return NULL; - } - - t->size++; - - memcpy(key_to_add, key, key_size); - struct htab_pair data_to_add = {.key = key_to_add, .value = 1}; - item_to_add->data = data_to_add; - - size_t index = (htab_hash_function(key) % t->arr_size); - if (!t->arr_ptr[index]) { - t->arr_ptr[index] = item_to_add; - return return_pair; - } - else { - item_to_add->next = t->arr_ptr[index]; - t->arr_ptr[index] = item_to_add; - return return_pair; - } -} - -bool htab_erase(htab_t *t, htab_key_t key) { - size_t index = (htab_hash_function(key) % t->arr_size); - struct htab_item *curr_item = t->arr_ptr[index]; - struct htab_item *last_item; - - if (!curr_item) { - return false; - } - - if (strcmp(curr_item->data.key, key) == 0) { - t->arr_ptr[index] = curr_item->next; - free((char*)curr_item->data.key); - free(curr_item); - t->size--; - return true; - } - - while (curr_item) { - if (strcmp(curr_item->data.key, key) == 0) { - last_item->next = curr_item->next; - free((char*)curr_item->data.key); - free(curr_item); - t->size--; - return true; - } - last_item = curr_item; - curr_item = curr_item->next; - } - return false; -} - -void htab_for_each(const htab_t *t, void (*f)(htab_pair_t *data)) { - struct htab_item *tmp_ptr; - for (size_t i = 0; i < t->arr_size; ++i) { - tmp_ptr = t->arr_ptr[i]; - while (tmp_ptr) { - f(&tmp_ptr->data); - tmp_ptr = tmp_ptr->next; - } - } -} - -void htab_clear(htab_t *t) { - struct htab_item *tmp_ptr; - for (size_t i = 0; i < t->arr_size; ++i) { - tmp_ptr = t->arr_ptr[i]; - while (tmp_ptr) { - struct htab_item *curr_ptr = tmp_ptr; - tmp_ptr = tmp_ptr->next; - free((char*)curr_ptr->data.key); - free(curr_ptr); - } - } - - t->size = 0; -} - - -void htab_free(htab_t *t) { - htab_clear(t); - free(t->arr_ptr); - free(t); -} - -#ifdef STATISTICS - -void htab_statistics(const htab_t *t) { - struct htab_item *tmp_ptr; - size_t item_count = 0; - double nonempty_count = 0; - size_t min = 0; - size_t max = 0; - double avg = 0; - for (size_t i = 0; i < t->arr_size; ++i) { - if (!t->arr_ptr[i]) { - continue; - } - - tmp_ptr = t->arr_ptr[i]; - ++nonempty_count; - - item_count = 0; - while (tmp_ptr) { - ++item_count; - tmp_ptr = tmp_ptr->next; - } - - if (max < item_count) { - max = item_count; - } - - if (min > item_count || min == 0) { - min = item_count; - } - } - avg = t->size / nonempty_count; - - printf("min: %zu\n", min); - printf("max: %zu\n", max); - printf("avg: %lf\n", avg); - -} - -#endif //STATISTICS diff --git a/src/tail.c b/tail.c similarity index 100% rename from src/tail.c rename to tail.c diff --git a/src/to_je_jedno.cpp b/to_je_jedno.cpp similarity index 100% rename from src/to_je_jedno.cpp rename to to_je_jedno.cpp diff --git a/wcoutput b/wcoutput deleted file mode 100644 index d4cff06..0000000 --- a/wcoutput +++ /dev/null @@ -1,318 +0,0 @@ -!= 1 -!cb->data) 1 -!num_read) 1 -""); 3 -"", 1 -"--help") 1 -"--number") 1 -"-h") 1 -"-n") 1 -"Counldn't 1 -"r"); 1 -#define 1 -#include 5 -%38sinstead 1 -%= 3 -%s 1 -%s\n", 1 -&& 1 -'\0' 1 -'\n') 1 -(!buffer) 1 -(!buffer->data) 1 -(!cb 1 -(!discard_rest) 2 -(!exceeded) 1 -(!file_read) 1 -(!stream) 1 -(!tmp_string) 2 -((strcmp(argv[i], 1 -((tmp_char 1 -(NUM 1 -(argc 1 -(cb->count 2 -(cb->count) 1 -(cb->data[i]) 1 -(i 1 -(int 1 -(kind 1 -(old_string) 1 -(size 2 -(size_t 1 -(strcmp(argv[i], 1 -(tmp_char 1 -(tmp_string) 1 -*)); 1 -**argv) 1 -**data; 1 -*/ 2 -*buffer 1 -*cb 1 -*cb) 2 -*cb, 2 -*cb_create(size_t 1 -*cb_get(cb_t 1 -*cb_put(cb_t 1 -*curr_line 1 -*file_name) 1 -*line) 1 -*old_string 1 -*stream 1 -*stream) 1 -*tmp_string 1 -+ 4 -++i) 1 -++i; 1 ---help 1 ---help%26sprints 1 ---number 2 --h 1 --n 2 -/* 2 -// 23 -0 3 -0) 3 -0),\n\ 1 -0; 8 -1 1 -1) 2 -1), 1 -10 1 -10.0.0-4ubuntu1 1 -10; 1 -10\n\n", 1 -18.4.2023 1 -1; 5 -1]); 1 -4095 1 -< 3 -<= 1 - 1 - 1 - 1 - 1 - 1 -= 32 -== 7 -> 3 ->= 1 -Autor: 1 -EOF) 1 -FILE 3 -FILE, 1 -FIT 1 -IJC-DU2, 1 -LONG_MAX) 1 -MAX_LINE_SIZE 1 -MAX_LINE_SIZE) 1 -Mandatory 1 -Matyáš 1 -NULL; 3 -NUM 1 -NUM%20soutput 1 -OPTION%30sFUNCTION\n", 1 -Oujezdský, 1 -Přeloženo: 1 -With 1 -[FILE]\n", 1 -[OPTION] 1 -\n 2 -a 4 -allocate 4 -allocated 1 -and 7 -are 1 -argc 1 -argc, 1 -argc; 1 -argument 4 -arguments 1 -argv[i]); 1 -array 1 -at 4 -atoi(argv[i 1 -be 2 -big 1 -bool 4 -buffer 6 -buffer->count 1 -buffer->data 1 -buffer->end 1 -buffer->size 1 -buffer->start 1 -buffer; 1 -buffer\n", 2 -by 2 -calloc(n, 1 -cb 1 -cb->count++; 1 -cb->count--; 1 -cb->data[cb->end++] 1 -cb->data[cb->end]; 1 -cb->data[cb->start++]; 1 -cb->end 1 -cb->size) 1 -cb->size; 4 -cb->start 2 -cb->start++; 1 -cb_create(size); 1 -cb_free(cb); 1 -cb_free(cb_t 1 -cb_get(cb)); 1 -cb_put 2 -cb_put(cb, 1 -cb_t 3 -cb_t; 1 -char 8 -character 1 -chech 1 -check 1 -circular 3 -circural 1 -clang 1 -count; 1 -curr_line; 1 -current 1 -cycle 1 -discard_rest 2 -each 2 -else 2 -empty\n", 1 -end 1 -end; 1 -every 1 -exceeded 2 -false; 4 -fgetc(stream)) 1 -file 4 -file_name); 1 -file_read 2 -first 2 -fopen(argv[i], 1 -for 7 -fprintf(stderr, 1 -fputs("buffer 1 -fputs("couldn't 3 -fputs("exceeded 1 -free 1 -free(buffer); 1 -free(cb); 1 -free(cb->data); 1 -free(cb->data[i]); 1 -free(tmp_string); 1 -from 1 -happens 1 -help 2 -help\n", 1 -i 8 -i++) 1 -i++; 1 -if 24 -in 3 -increase 2 -index 2 -input 1 -input.\n\n\ 1 -inputed 1 -instance 1 -int 3 -is 3 -it 2 -last 4 -length\n", 1 -line 5 -line; 1 -lines 5 -long 1 -loop 1 -main(int 1 -make 1 -malloc(MAX_LINE_SIZE); 2 -malloc(sizeof(cb_t)); 1 -mandatory 1 -max 1 -memory 4 -must 1 -n) 1 -n; 1 -name 1 -names 1 -neccesary 1 -negative 1 -next 3 -no 1 -not 1 -num_read 2 -number 4 -numbers 1 -of 11 -old_string; 1 -only 1 -open 2 -options 2 -or 5 -output.\n\n\ 1 -part 1 -passed, 2 -pointer 5 -print 2 -print_help(argv[0]); 3 -print_help(char 1 -printf("%s\n", 1 -printf("-h, 1 -printf("-n, 1 -printf("Print 1 -printf("Usage: 1 -příklad 1 -read 6 -read_file(cb, 1 -read_file(cb_t 1 -reads 1 -return 13 -return; 1 -self-explainatory) 1 -send 1 -sends 1 -set 1 -short 1 -size 3 -size; 1 -size_t 5 -sizeof(char 1 -skip 1 -so 2 -standard 2 -start; 1 -stderr); 5 -stdin; 1 -strcmp(argv[i], 2 -stream 1 -stream); 1 -string 3 -struct 1 -sure 1 -tail.c 1 -the 12 -there 1 -this 2 -tmp_char; 2 -tmp_string 2 -tmp_string", 1 -tmp_string); 1 -tmp_string[i] 2 -to 8 -too 1 -too.\n\n\ 1 -true; 4 -typedef 1 -version 1 -void 3 -was 2 -while 2 -with 2 -write 2 -zero 1 -{ 34 -|| 4 -} 34 -Řešení 1 diff --git a/src/wordcount.c b/wordcount.c similarity index 100% rename from src/wordcount.c rename to wordcount.c