~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/ceph/ceph_hash.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /net/ceph/ceph_hash.c (Version linux-6.11.5) and /net/ceph/ceph_hash.c (Version linux-5.14.21)


  1                                                     1 
  2 #include <linux/ceph/types.h>                       2 #include <linux/ceph/types.h>
  3 #include <linux/module.h>                           3 #include <linux/module.h>
  4                                                     4 
  5 /*                                                  5 /*
  6  * Robert Jenkin's hash function.                   6  * Robert Jenkin's hash function.
  7  * https://burtleburtle.net/bob/hash/evahash.h      7  * https://burtleburtle.net/bob/hash/evahash.html
  8  * This is in the public domain.                    8  * This is in the public domain.
  9  */                                                 9  */
 10 #define mix(a, b, c)                               10 #define mix(a, b, c)                                            \
 11         do {                                       11         do {                                                    \
 12                 a = a - b;  a = a - c;  a = a      12                 a = a - b;  a = a - c;  a = a ^ (c >> 13);      \
 13                 b = b - c;  b = b - a;  b = b      13                 b = b - c;  b = b - a;  b = b ^ (a << 8);       \
 14                 c = c - a;  c = c - b;  c = c      14                 c = c - a;  c = c - b;  c = c ^ (b >> 13);      \
 15                 a = a - b;  a = a - c;  a = a      15                 a = a - b;  a = a - c;  a = a ^ (c >> 12);      \
 16                 b = b - c;  b = b - a;  b = b      16                 b = b - c;  b = b - a;  b = b ^ (a << 16);      \
 17                 c = c - a;  c = c - b;  c = c      17                 c = c - a;  c = c - b;  c = c ^ (b >> 5);       \
 18                 a = a - b;  a = a - c;  a = a      18                 a = a - b;  a = a - c;  a = a ^ (c >> 3);       \
 19                 b = b - c;  b = b - a;  b = b      19                 b = b - c;  b = b - a;  b = b ^ (a << 10);      \
 20                 c = c - a;  c = c - b;  c = c      20                 c = c - a;  c = c - b;  c = c ^ (b >> 15);      \
 21         } while (0)                                21         } while (0)
 22                                                    22 
 23 unsigned int ceph_str_hash_rjenkins(const char     23 unsigned int ceph_str_hash_rjenkins(const char *str, unsigned int length)
 24 {                                                  24 {
 25         const unsigned char *k = (const unsign     25         const unsigned char *k = (const unsigned char *)str;
 26         __u32 a, b, c;  /* the internal state      26         __u32 a, b, c;  /* the internal state */
 27         __u32 len;      /* how many key bytes      27         __u32 len;      /* how many key bytes still need mixing */
 28                                                    28 
 29         /* Set up the internal state */            29         /* Set up the internal state */
 30         len = length;                              30         len = length;
 31         a = 0x9e3779b9;      /* the golden rat     31         a = 0x9e3779b9;      /* the golden ratio; an arbitrary value */
 32         b = a;                                     32         b = a;
 33         c = 0;               /* variable initi     33         c = 0;               /* variable initialization of internal state */
 34                                                    34 
 35         /* handle most of the key */               35         /* handle most of the key */
 36         while (len >= 12) {                        36         while (len >= 12) {
 37                 a = a + (k[0] + ((__u32)k[1] <     37                 a = a + (k[0] + ((__u32)k[1] << 8) + ((__u32)k[2] << 16) +
 38                          ((__u32)k[3] << 24));     38                          ((__u32)k[3] << 24));
 39                 b = b + (k[4] + ((__u32)k[5] <     39                 b = b + (k[4] + ((__u32)k[5] << 8) + ((__u32)k[6] << 16) +
 40                          ((__u32)k[7] << 24));     40                          ((__u32)k[7] << 24));
 41                 c = c + (k[8] + ((__u32)k[9] <     41                 c = c + (k[8] + ((__u32)k[9] << 8) + ((__u32)k[10] << 16) +
 42                          ((__u32)k[11] << 24))     42                          ((__u32)k[11] << 24));
 43                 mix(a, b, c);                      43                 mix(a, b, c);
 44                 k = k + 12;                        44                 k = k + 12;
 45                 len = len - 12;                    45                 len = len - 12;
 46         }                                          46         }
 47                                                    47 
 48         /* handle the last 11 bytes */             48         /* handle the last 11 bytes */
 49         c = c + length;                            49         c = c + length;
 50         switch (len) {                             50         switch (len) {
 51         case 11:                                   51         case 11:
 52                 c = c + ((__u32)k[10] << 24);      52                 c = c + ((__u32)k[10] << 24);
 53                 fallthrough;                       53                 fallthrough;
 54         case 10:                                   54         case 10:
 55                 c = c + ((__u32)k[9] << 16);       55                 c = c + ((__u32)k[9] << 16);
 56                 fallthrough;                       56                 fallthrough;
 57         case 9:                                    57         case 9:
 58                 c = c + ((__u32)k[8] << 8);        58                 c = c + ((__u32)k[8] << 8);
 59                 /* the first byte of c is rese     59                 /* the first byte of c is reserved for the length */
 60                 fallthrough;                       60                 fallthrough;
 61         case 8:                                    61         case 8:
 62                 b = b + ((__u32)k[7] << 24);       62                 b = b + ((__u32)k[7] << 24);
 63                 fallthrough;                       63                 fallthrough;
 64         case 7:                                    64         case 7:
 65                 b = b + ((__u32)k[6] << 16);       65                 b = b + ((__u32)k[6] << 16);
 66                 fallthrough;                       66                 fallthrough;
 67         case 6:                                    67         case 6:
 68                 b = b + ((__u32)k[5] << 8);        68                 b = b + ((__u32)k[5] << 8);
 69                 fallthrough;                       69                 fallthrough;
 70         case 5:                                    70         case 5:
 71                 b = b + k[4];                      71                 b = b + k[4];
 72                 fallthrough;                       72                 fallthrough;
 73         case 4:                                    73         case 4:
 74                 a = a + ((__u32)k[3] << 24);       74                 a = a + ((__u32)k[3] << 24);
 75                 fallthrough;                       75                 fallthrough;
 76         case 3:                                    76         case 3:
 77                 a = a + ((__u32)k[2] << 16);       77                 a = a + ((__u32)k[2] << 16);
 78                 fallthrough;                       78                 fallthrough;
 79         case 2:                                    79         case 2:
 80                 a = a + ((__u32)k[1] << 8);        80                 a = a + ((__u32)k[1] << 8);
 81                 fallthrough;                       81                 fallthrough;
 82         case 1:                                    82         case 1:
 83                 a = a + k[0];                      83                 a = a + k[0];
 84                 /* case 0: nothing left to add     84                 /* case 0: nothing left to add */
 85         }                                          85         }
 86         mix(a, b, c);                              86         mix(a, b, c);
 87                                                    87 
 88         return c;                                  88         return c;
 89 }                                                  89 }
 90                                                    90 
 91 /*                                                 91 /*
 92  * linux dcache hash                               92  * linux dcache hash
 93  */                                                93  */
 94 unsigned int ceph_str_hash_linux(const char *s     94 unsigned int ceph_str_hash_linux(const char *str, unsigned int length)
 95 {                                                  95 {
 96         unsigned long hash = 0;                    96         unsigned long hash = 0;
 97         unsigned char c;                           97         unsigned char c;
 98                                                    98 
 99         while (length--) {                         99         while (length--) {
100                 c = *str++;                       100                 c = *str++;
101                 hash = (hash + (c << 4) + (c >    101                 hash = (hash + (c << 4) + (c >> 4)) * 11;
102         }                                         102         }
103         return hash;                              103         return hash;
104 }                                                 104 }
105                                                   105 
106                                                   106 
107 unsigned int ceph_str_hash(int type, const cha    107 unsigned int ceph_str_hash(int type, const char *s, unsigned int len)
108 {                                                 108 {
109         switch (type) {                           109         switch (type) {
110         case CEPH_STR_HASH_LINUX:                 110         case CEPH_STR_HASH_LINUX:
111                 return ceph_str_hash_linux(s,     111                 return ceph_str_hash_linux(s, len);
112         case CEPH_STR_HASH_RJENKINS:              112         case CEPH_STR_HASH_RJENKINS:
113                 return ceph_str_hash_rjenkins(    113                 return ceph_str_hash_rjenkins(s, len);
114         default:                                  114         default:
115                 return -1;                        115                 return -1;
116         }                                         116         }
117 }                                                 117 }
118 EXPORT_SYMBOL(ceph_str_hash);                     118 EXPORT_SYMBOL(ceph_str_hash);
119                                                   119 
120 const char *ceph_str_hash_name(int type)          120 const char *ceph_str_hash_name(int type)
121 {                                                 121 {
122         switch (type) {                           122         switch (type) {
123         case CEPH_STR_HASH_LINUX:                 123         case CEPH_STR_HASH_LINUX:
124                 return "linux";                   124                 return "linux";
125         case CEPH_STR_HASH_RJENKINS:              125         case CEPH_STR_HASH_RJENKINS:
126                 return "rjenkins";                126                 return "rjenkins";
127         default:                                  127         default:
128                 return "unknown";                 128                 return "unknown";
129         }                                         129         }
130 }                                                 130 }
131 EXPORT_SYMBOL(ceph_str_hash_name);                131 EXPORT_SYMBOL(ceph_str_hash_name);
132                                                   132 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php