celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erjan Altena (JIRA)" <j...@apache.org>
Subject [jira] [Created] (CELIX-348) The utils_stringHash does not generate unique hashes.
Date Tue, 09 Feb 2016 10:02:18 GMT
Erjan Altena created CELIX-348:

             Summary: The utils_stringHash does not generate unique hashes.
                 Key: CELIX-348
                 URL: https://issues.apache.org/jira/browse/CELIX-348
             Project: Celix
          Issue Type: Improvement
          Components: Framework
    Affects Versions: next
            Reporter: Erjan Altena

Using the utils_stringHash functions on a few 100 strings, it generates the same hash for
different strings. Of course the hash function can not be guaranteed to deliver unique hashes
but the uniqueness can be improved by the next calculation (the DJB2 Hash algorithm)

unsigned int hash = 5381;
unsigned int i = 0;
unsigned int len = strlen(string);

for(i=0; i < len; i++) {
	hash = (hash << 5) + (*string) + hash;

return hash;

This message was sent by Atlassian JIRA

View raw message