Why count the hash value in this way?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi all:
      In the function of link_path_walk() , it counts the hash value of the compoent of the pathname.
Why "(prevhash + (c <<4) + (c >> 4))*11;"?

Thank you.



http://lxr.oss.org.cn/source/fs/namei.c?v=2.6.16#L779
809                 c = *(const unsigned char *)name;
810 
811                 hash = init_name_hash();
812                 do {
813                         name++;
814                         hash = partial_name_hash(c, hash);
815                         c = *(const unsigned char *)name;
816                 } while (c && (c != '/'));
817                 this.len = name - (const char *) this.name;

/* Name hashing routines. Initial hash value */
 49 /* Hash courtesy of the R5 hash in reiserfs modulo sign bits */
 50 #define init_name_hash()                0
 51 
 52 /* partial hash update function. Assume roughly 4 bits per character */
 53 static inline unsigned long
 54 partial_name_hash(unsigned long c, unsigned long prevhash)
 55 {
 56         return (prevhash + (c << 4) + (c >> 4)) * 11;
 57 }
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux