10.07.2015 Views

Information Theory, Inference, and Learning ... - Inference Group

Information Theory, Inference, and Learning ... - Inference Group

Information Theory, Inference, and Learning ... - Inference Group

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Copyright Cambridge University Press 2003. On-screen viewing permitted. Printing not permitted. http://www.cambridge.org/0521642981You can buy this book for 30 pounds or $50. See http://www.inference.phy.cam.ac.uk/mackay/itila/ for links.196 12 — Hash Codes: Codes for Efficient <strong>Information</strong> Retrievalunsigned char R<strong>and</strong>8[256]; // This array contains a r<strong>and</strong>ompermutation from 0..255 to 0..255int Hash(char *x) {// x is a pointer to the first char;int h; // *x is the first characterunsigned char h1, h2;Algorithm 12.3. C codeimplementing the variable stringexclusive-or method to create ahash h in the range 0 . . . 65 535from a string x. Author: ThomasNiemann.}if (*x == 0) return 0; // Special h<strong>and</strong>ling of empty stringh1 = *x; h2 = *x + 1; // Initialize two hashesx++;// Proceed to the next characterwhile (*x) {h1 = R<strong>and</strong>8[h1 ^ *x]; // Exclusive-or with the two hashesh2 = R<strong>and</strong>8[h2 ^ *x]; // <strong>and</strong> put through the r<strong>and</strong>omizerx++;} // End of string is reached when *x=0h = ((int)(h1)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!