RTEMS 6.1-rc2
Loading...
Searching...
No Matches
Macros | Functions

RTEMS File Systems Directory Hash function. More...

#include <rtems/rfs/rtems-rfs-dir-hash.h>

Macros

#define HASH_LITTLE_ENDIAN   0
 
#define HASH_BIG_ENDIAN   0
 
#define hashsize(n)   ((uint32_t)1<<(n))
 
#define hashmask(n)   (hashsize(n)-1)
 
#define rot(x, k)   (((x)<<(k)) | ((x)>>(32-(k))))
 
#define mix(a, b, c)
 
#define final(a, b, c)
 
#define initval   (20010928)
 

Functions

uint32_t rtems_rfs_dir_hash (const void *key, size_t length)
 

Detailed Description

RTEMS File Systems Directory Hash function.

Macro Definition Documentation

◆ final

#define final (   a,
  b,
 
)
Value:
{ \
c ^= b; c -= rot(b,14); \
a ^= c; a -= rot(c,11); \
b ^= a; b -= rot(a,25); \
c ^= b; c -= rot(b,16); \
a ^= c; a -= rot(c,4); \
b ^= a; b -= rot(a,14); \
c ^= b; c -= rot(b,24); \
}

◆ initval

#define initval   (20010928)

The follow is the documentation from Bob Jenkin's hash function:

http://burtleburtle.net/bob/hash/doobs.html

The function hashlittle() has been renamed.

hashlittle() – hash a variable-length key into a 32-bit value

k : the key (the unaligned variable-length array of bytes) length : the length of the key, counting by bytes initval : can be any 4-byte value

Returns a 32-bit value. Every bit of the key affects every bit of the return value. Two keys differing by one or two bits will have totally different hash values.

The best hash table sizes are powers of 2. There is no need to do mod a prime (mod is sooo slow!). If you need less than 32 bits, use a bitmask. For example, if you need only 10 bits, do h = (h & hashmask(10)); In which case, the hash table should have hashsize(10) elements.

If you are hashing n strings (uint8_t **)k, do it like this: for (i=0, h=0; i<n; ++i) h = hashlittle( k[i], len[i], h);

By Bob Jenkins, 2006. bob_j.nosp@m.enki.nosp@m.ns@bu.nosp@m.rtle.nosp@m.burtl.nosp@m.e.ne.nosp@m.t. You may use this code any way you wish, private, educational, or commercial. It's free.

Use for hash table lookup, or anything where one collision in 2^^32 is acceptable. Do NOT use for cryptographic purposes.

◆ mix

#define mix (   a,
  b,
 
)
Value:
{ \
a -= c; a ^= rot(c, 4); c += b; \
b -= a; b ^= rot(a, 6); a += c; \
c -= b; c ^= rot(b, 8); b += a; \
a -= c; a ^= rot(c,16); c += b; \
b -= a; b ^= rot(a,19); a += c; \
c -= b; c ^= rot(b, 4); b += a; \
}

Function Documentation

◆ rtems_rfs_dir_hash()

uint32_t rtems_rfs_dir_hash ( const void *  key,
size_t  length 
)

Compute a hash of the key over the length of string.

Parameters
[in]keyis a pointer to the key to calculate the hash of.
[in]lengthis the length of the key in bytes.
Return values
hashThe computed uint32_t hash.