Changeset a73aaec1 in mainline


Ignore:
Timestamp:
2020-04-13T20:52:27Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
81c4e6ec
Parents:
aa0faeca
Message:

Removing recentely added hashing function

The function hash_string() implemented the
djb2 algorithm for hashing strings. As requested
during a review this has been changed to the
existing hashing function instead of implementing
a new one

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/adt/hash.h

    raa0faeca ra73aaec1  
    115115 * TODO Modify also same file in kernel subtree?
    116116 *
    117  * @param[in]  str     NULL-terminated string (not NULL)
     117 * @param[in]  str     NULL-terminated string
     118 * @return hash of the given string
    118119 */
    119120static inline size_t hash_string(const char *str)
    120121{
    121         /*
    122          * Using djb2 function
    123          * http://www.cse.yorku.ca/~oz/hash.html
    124          */
    125         size_t hash = 5381;
    126         char c;
    127         while ((c = *str++)) {
    128                 hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     122        size_t hash = 0;
     123        if (str != NULL) {
     124                char c;
     125                while ((c = *str++) != 0) {
     126                        hash = hash_combine(hash, c);
     127                }
    129128        }
     129
    130130        return hash;
    131131}
Note: See TracChangeset for help on using the changeset viewer.