From 699accb1f109ac4311876315bd5639cc7aeeecbb Mon Sep 17 00:00:00 2001 From: Ivan Leichenko Date: Fri, 8 Nov 2024 13:17:47 +0100 Subject: [PATCH] different hash algorithm cv6 --- cv6/a_station.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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; }