Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset b2171c0 in mainline


Ignore:
Timestamp:
2020-03-14T15:04:43Z (3 weeks ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
2e03c02
Parents:
576d160
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-04-15 15:04:28)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2020-03-14 15:04:43)
Message:

Add function for hashing strings
Conflicts:

uspace/lib/c/generic/adt/hash_table.c
uspace/lib/c/include/adt/hash.h

File:
1 edited

Legend:

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

    r576d160 rb2171c0  
    111111}
    112112
     113/** Calculate hash of NULL-terminated string
     114 *
     115 * TODO Modify also same file in kernel subtree?
     116 *
     117 * @param[in]  str     NULL-terminated string (not NULL)
     118 */
     119static inline size_t hash_string(const char *str)
     120{
     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 */
     129        }
     130        return hash;
     131}
     132
    113133#endif
Note: See TracChangeset for help on using the changeset viewer.