From 3c2eb614826764dd1631489fc610fef478958b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Frankovi=C4=8D?= Date: Mon, 13 Apr 2026 18:37:38 +0000 Subject: [PATCH] Delete du6/station.c --- du6/station.c | 147 -------------------------------------------------- 1 file changed, 147 deletions(-) delete mode 100644 du6/station.c diff --git a/du6/station.c b/du6/station.c deleted file mode 100644 index 608db60..0000000 --- a/du6/station.c +++ /dev/null @@ -1,147 +0,0 @@ -#include "station.h" - -#include -#include - -struct station* create_station() { - struct station* st = (struct station*)malloc(sizeof(struct station)); - if (st == NULL) { - return NULL; - } - - st->tracks = (struct car**)calloc(STATION_SIZE, sizeof(struct car*)); - if (st->tracks == NULL) { - free(st); - return NULL; - } - - st->track_count = STATION_SIZE; - return st; -} - -void destroy_station(struct station* station) { - int i; - - if (station == NULL) { - return; - } - - for (i = 0; i < station->track_count; i++) { - struct car* current = station->tracks[i]; - while (current != NULL) { - struct car* next = current->next; - free(current); - current = next; - } - } - - free(station->tracks); - free(station); -} - -int select_track(struct station* station, const char* target) { - unsigned long hash = 5381; - const unsigned char* ptr; - - if (station == NULL || station->track_count <= 0 || target == NULL) { - return 0; - } - - ptr = (const unsigned char*)target; - while (*ptr != '\0') { - hash = ((hash << 5) + hash) + *ptr; - ptr++; - } - - return (int)(hash % (unsigned long)station->track_count); -} - -void add_target_capacity(struct station* station, const char* target, int capacity) { - int index; - struct car* current; - - if (station == NULL || station->tracks == NULL || target == NULL) { - return; - } - - index = select_track(station, target); - current = station->tracks[index]; - - while (current != NULL) { - if (strcmp(current->value, target) == 0) { - current->capacity += capacity; - return; - } - current = current->next; - } - - current = (struct car*)malloc(sizeof(struct car)); - if (current == NULL) { - return; - } - - strncpy(current->value, target, TARGET_SIZE - 1); - current->value[TARGET_SIZE - 1] = '\0'; - current->capacity = capacity; - current->next = station->tracks[index]; - station->tracks[index] = current; -} - -int get_target_capacity(struct station* station, const char* target) { - int index; - struct car* current; - - if (station == NULL || station->tracks == NULL || target == NULL) { - return 0; - } - - index = select_track(station, target); - current = station->tracks[index]; - - while (current != NULL) { - if (strcmp(current->value, target) == 0) { - return current->capacity; - } - current = current->next; - } - - return 0; -} - -int count_targets(struct station* station) { - int i; - int count = 0; - - if (station == NULL || station->tracks == NULL) { - return 0; - } - - for (i = 0; i < station->track_count; i++) { - struct car* current = station->tracks[i]; - while (current != NULL) { - count++; - current = current->next; - } - } - - return count; -} - -int count_capacity(struct station* station) { - int i; - int sum = 0; - - if (station == NULL || station->tracks == NULL) { - return 0; - } - - for (i = 0; i < station->track_count; i++) { - struct car* current = station->tracks[i]; - while (current != NULL) { - sum += current->capacity; - current = current->next; - } - } - - return sum; -}