VirtualBox

Changeset 40052 in vbox


Ignore:
Timestamp:
Feb 9, 2012 3:36:00 PM (13 years ago)
Author:
vboxsync
Message:

IPRT: Added string hashing API (RTStrHash1*).

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/string.h

    r38658 r40052  
    31123112
    31133113
     3114/** @defgroup rt_str_hash       Sting hashing
     3115 * @ingroup grp_rt_str
     3116 * @{ */
     3117
     3118/**
     3119 * Hashes the given string using algorithm \#1.
     3120 *
     3121 * @returns String hash.
     3122 * @param   pszString       The string to hash.
     3123 */
     3124RTDECL(uint32_t)    RTStrHash1(const char *pszString);
     3125
     3126/**
     3127 * Hashes the given string using algorithm \#1.
     3128 *
     3129 * @returns String hash.
     3130 * @param   pszString       The string to hash.
     3131 * @param   cchString       The max length to hash. Hashing will stop if the
     3132 *                          terminator character is encountered first. Passing
     3133 *                          RTSTR_MAX is fine.
     3134 */
     3135RTDECL(uint32_t)    RTStrHash1N(const char *pszString, size_t cchString);
     3136
     3137/**
     3138 * Hashes the given strings as if they were concatenated using algorithm \#1.
     3139 *
     3140 * @returns String hash.
     3141 * @param   cPairs          The number of string / length pairs in the
     3142 *                          ellipsis.
     3143 * @param   ...             List of string (const char *) and length
     3144 *                          (size_t) pairs.  Passing RTSTR_MAX as the size is
     3145 *                          fine.
     3146 */
     3147RTDECL(uint32_t)    RTStrHash1ExN(size_t cPairs, ...);
     3148
     3149/**
     3150 * Hashes the given strings as if they were concatenated using algorithm \#1.
     3151 *
     3152 * @returns String hash.
     3153 * @param   cPairs          The number of string / length pairs in the @a va.
     3154 * @param   va              List of string (const char *) and length
     3155 *                          (size_t) pairs.  Passing RTSTR_MAX as the size is
     3156 *                          fine.
     3157 */
     3158RTDECL(uint32_t)    RTStrHash1ExNV(size_t cPairs, va_list va);
     3159
     3160/** @}  */
     3161
     3162
    31143163/** @defgroup rt_str_utf16      UTF-16 String Manipulation
    31153164 * @ingroup grp_rt_str
  • trunk/src/VBox/Runtime/Makefile.kmk

    r40029 r40052  
    386386        common/string/strformatrt.cpp \
    387387        common/string/strformattype.cpp \
     388        common/string/strhash1.cpp \
    388389        common/string/stringalloc.cpp \
    389390        common/string/strprintf.cpp \
     
    14941495        common/misc/term.cpp \
    14951496        common/path/RTPathFilename.cpp \
     1497        common/string/strhash1.cpp \
    14961498        common/string/strncmp.cpp \
    14971499        common/string/strpbrk.cpp \
     
    16591661        common/string/strformatrt.cpp \
    16601662        common/string/strformattype.cpp \
     1663        common/string/strhash1.cpp \
    16611664        common/string/strprintf.cpp \
    16621665        common/string/strtonum.cpp \
  • trunk/src/VBox/Runtime/include/internal/strhash.h

    r36597 r40052  
    7676}
    7777
     78
    7879/**
    7980 * Incremental hashing.
     
    9091}
    9192
     93/**
     94 * Incremental hashing with length limitation.
     95 */
     96DECLINLINE(uint32_t) sdbmIncN(const char *psz, size_t cchMax, uint32_t uHash)
     97{
     98    uint8_t *pu8 = (uint8_t *)psz;
     99    int      c;
     100
     101    while ((c = *pu8++) && cchMax-- > 0)
     102        uHash = c + (uHash << 6) + (uHash << 16) - uHash;
     103
     104    return uHash;
     105}
     106
    92107
    93108#endif
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette