Xenomai API  2.5.6.1
include/nucleus/jhash.h
00001 /*
00002  * Jenkins hash support, lifted from the Linux kernel from
00003  * linux/include/linux/jhash.h.
00004  *
00005  * Original credits:
00006  *
00007  * Copyright (C) 1996 Bob Jenkins ([email protected])
00008  *
00009  * http://burtleburtle.net/bob/hash/
00010  *
00011  * These are the credits from Bob's sources:
00012  *
00013  * lookup2.c, by Bob Jenkins, December 1996, Public Domain.
00014  * hash(), hash2(), hash3, and mix() are externally useful functions.
00015  * Routines to test the hash are included if SELF_TEST is defined.
00016  * You can use this free for any purpose.  It has no warranty.
00017  *
00018  * Copyright (C) 2003 David S. Miller ([email protected])
00019  *
00020  * I've modified Bob's hash to be useful in the Linux kernel, and
00021  * any bugs present are surely my fault.  -DaveM
00022  */
00023 
00024 #ifndef _XENO_NUCLEUS_JHASH_H
00025 #define _XENO_NUCLEUS_JHASH_H
00026 
00027 #include <nucleus/types.h>
00028 
00029 /* NOTE: Arguments are modified. */
00030 #define __jhash_mix(a, b, c) \
00031 { \
00032   a -= b; a -= c; a ^= (c>>13); \
00033   b -= c; b -= a; b ^= (a<<8); \
00034   c -= a; c -= b; c ^= (b>>13); \
00035   a -= b; a -= c; a ^= (c>>12);  \
00036   b -= c; b -= a; b ^= (a<<16); \
00037   c -= a; c -= b; c ^= (b>>5); \
00038   a -= b; a -= c; a ^= (c>>3);  \
00039   b -= c; b -= a; b ^= (a<<10); \
00040   c -= a; c -= b; c ^= (b>>15); \
00041 }
00042 
00043 /* The golden ratio: an arbitrary value */
00044 #define JHASH_GOLDEN_RATIO      0x9e3779b9
00045 
00046 /* A special optimized version that handles 1 or more of u32s.
00047  * The length parameter here is the number of u32s in the key.
00048  */
00049 static inline uint32_t jhash2(const uint32_t *k, uint32_t length, uint32_t initval)
00050 {
00051         uint32_t a, b, c, len;
00052 
00053         a = b = JHASH_GOLDEN_RATIO;
00054         c = initval;
00055         len = length;
00056 
00057         while (len >= 3) {
00058                 a += k[0];
00059                 b += k[1];
00060                 c += k[2];
00061                 __jhash_mix(a, b, c);
00062                 k += 3; len -= 3;
00063         }
00064 
00065         c += length * 4;
00066 
00067         switch (len) {
00068         case 2 : b += k[1];
00069         case 1 : a += k[0];
00070         };
00071 
00072         __jhash_mix(a,b,c);
00073 
00074         return c;
00075 }
00076 
00077 #endif /* _XENO_NUCLEUS_JHASH_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines