diff --git a/cv6/a_station.c b/cv6/a_station.c index a90e856..64807ee 100644 --- a/cv6/a_station.c +++ b/cv6/a_station.c @@ -34,14 +34,15 @@ void destroy_station(struct station* station) int select_track(struct station* station, const char* target) { - unsigned int hash = 0; - int prime = 36; + //DJB2 hash + unsigned int hash = 5381; + int c; - for (size_t i = 0; i < strlen(target); i++) + while ((c = *target++)) { - hash = hash * prime + (unsigned char)target[i]; + hash = hash * 33 + c; } - + return hash % station->track_count; }