different hash algorithm cv6

This commit is contained in:
Ivan Leichenko 2024-11-08 13:17:47 +01:00
parent 2b1ee9eadd
commit 699accb1f1

View File

@ -34,14 +34,15 @@ void destroy_station(struct station* station)
int select_track(struct station* station, const char* target) int select_track(struct station* station, const char* target)
{ {
unsigned int hash = 0; //DJB2 hash
int prime = 36; 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; return hash % station->track_count;
} }