Aktualizovat du6/a_station.c
This commit is contained in:
parent
0e74369742
commit
f728e69e51
@ -27,7 +27,7 @@ int select_track(struct station* station, const char* target) {
|
||||
unsigned long hash = 5381;
|
||||
int c;
|
||||
while ((c = (unsigned char)*target++)) {
|
||||
hash = ((hash << 5) + hash) + c; // hash * 33 + c
|
||||
hash = ((hash << 5) + hash) + c;
|
||||
}
|
||||
return (int)(hash % (unsigned long)station->track_count);
|
||||
}
|
||||
@ -36,7 +36,6 @@ void add_target_capacity(struct station* station, const char* target, int capaci
|
||||
int index = select_track(station, target);
|
||||
struct car* current = station->tracks[index];
|
||||
|
||||
// Hladame existujuci zaznam
|
||||
while (current != NULL) {
|
||||
if (strncmp(current->value, target, TARGET_SIZE) == 0) {
|
||||
current->capacity += capacity;
|
||||
@ -45,7 +44,6 @@ void add_target_capacity(struct station* station, const char* target, int capaci
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
// Zaznam neexistuje - vytvorime novy na zaciatku zoznamu
|
||||
struct car* new_car = (struct car*)calloc(1, sizeof(struct car));
|
||||
strncpy(new_car->value, target, TARGET_SIZE - 1);
|
||||
new_car->value[TARGET_SIZE - 1] = '\0';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user