r23508 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23507‎ | r23508 | r23509 >
Date:15:14, 28 June 2007
Author:river
Status:old
Tags:
Comment:
add missing fnv code
Modified paths:
  • /trunk/tools/trainwreck/fnv.h (added) (history)
  • /trunk/tools/trainwreck/hash_32a.c (added) (history)
  • /trunk/tools/trainwreck/trainwreck.c (modified) (history)

Diff [purge]

Index: trunk/tools/trainwreck/fnv.h
@@ -0,0 +1,114 @@
 2+/* $Id$ */
 3+/*
 4+ * fnv - Fowler/Noll/Vo- hash code
 5+ *
 6+ * @(#) Revision: 1.5
 7+ * @(#) Id: fnv.h,v 1.5 2003/10/03 20:35:52 chongo Exp
 8+ * @(#) Source: /usr/local/src/cmd/fnv/RCS/fnv.h,v
 9+ *
 10+ ***
 11+ *
 12+ * Fowler/Noll/Vo- hash
 13+ *
 14+ * The basis of this hash algorithm was taken from an idea sent
 15+ * as reviewer comments to the IEEE POSIX P1003.2 committee by:
 16+ *
 17+ * Phong Vo (http://www.research.att.com/info/kpv/)
 18+ * Glenn Fowler (http://www.research.att.com/~gsf/)
 19+ *
 20+ * In a subsequent ballot round:
 21+ *
 22+ * Landon Curt Noll (http://www.isthe.com/chongo/)
 23+ *
 24+ * improved on their algorithm. Some people tried this hash
 25+ * and found that it worked rather well. In an EMail message
 26+ * to Landon, they named it the ``Fowler/Noll/Vo'' or FNV hash.
 27+ *
 28+ * FNV hashes are designed to be fast while maintaining a low
 29+ * collision rate. The FNV speed allows one to quickly hash lots
 30+ * of data while maintaining a reasonable collision rate. See:
 31+ *
 32+ * http://www.isthe.com/chongo/tech/comp/fnv/index.html
 33+ *
 34+ * for more details as well as other forms of the FNV hash.
 35+ *
 36+ ***
 37+ *
 38+ * NOTE: The FNV-0 historic hash is not recommended. One should use
 39+ * the FNV-1 hash instead.
 40+ *
 41+ * To use the 32 bit FNV-0 historic hash, pass FNV0_32_INIT as the
 42+ * Fnv32_t hashval argument to fnv_32_buf() or fnv_32_str().
 43+ *
 44+ * To use the 64 bit FNV-0 historic hash, pass FNV0_64_INIT as the
 45+ * Fnv64_t hashval argument to fnv_64_buf() or fnv_64_str().
 46+ *
 47+ * To use the recommended 32 bit FNV-1 hash, pass FNV1_32_INIT as the
 48+ * Fnv32_t hashval argument to fnv_32_buf() or fnv_32_str().
 49+ *
 50+ * To use the recommended 64 bit FNV-1 hash, pass FNV1_64_INIT as the
 51+ * Fnv64_t hashval argument to fnv_64_buf() or fnv_64_str().
 52+ *
 53+ * To use the recommended 32 bit FNV-1a hash, pass FNV1_32A_INIT as the
 54+ * Fnv32_t hashval argument to fnv_32a_buf() or fnv_32a_str().
 55+ *
 56+ * To use the recommended 64 bit FNV-1a hash, pass FNV1_64A_INIT as the
 57+ * Fnv64_t hashval argument to fnv_64a_buf() or fnv_64a_str().
 58+ *
 59+ ***
 60+ *
 61+ * Please do not copyright this code. This code is in the public domain.
 62+ *
 63+ * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 64+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
 65+ * EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 66+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
 67+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
 68+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 69+ * PERFORMANCE OF THIS SOFTWARE.
 70+ *
 71+ * By:
 72+ * chongo <Landon Curt Noll> /\oo/\
 73+ * http://www.isthe.com/chongo/
 74+ *
 75+ * Share and Enjoy! :-)
 76+ */
 77+
 78+#if !defined(__FNV_H__)
 79+#define __FNV_H__
 80+
 81+
 82+/*
 83+ * 32 bit FNV-0 hash type
 84+ */
 85+typedef unsigned long Fnv32_t;
 86+
 87+
 88+/*
 89+ * 32 bit FNV-0 zero initial basis
 90+ *
 91+ * This historic hash is not recommended. One should use
 92+ * the FNV-1 hash and initial basis instead.
 93+ */
 94+#define FNV0_32_INIT ((Fnv32_t)0)
 95+
 96+
 97+/*
 98+ * 32 bit FNV-1 and FNV-1a non-zero initial basis
 99+ *
 100+ * The FNV-1 initial basis is the FNV-0 hash of the following 32 octets:
 101+ *
 102+ * chongo <Landon Curt Noll> /\../\
 103+ *
 104+ * NOTE: The \'s above are not back-slashing escape characters.
 105+ * They are literal ASCII backslash 0x5c characters.
 106+ *
 107+ * NOTE: The FNV-1a initial basis is the same value as FNV-1 by definition.
 108+ */
 109+#define FNV1_32_INIT ((Fnv32_t)0x811c9dc5)
 110+#define FNV1_32A_INIT FNV1_32_INIT
 111+
 112+
 113+extern Fnv32_t fnv_32a_str(char const *buf, Fnv32_t hashval);
 114+
 115+#endif /* __FNV_H__ */
Index: trunk/tools/trainwreck/hash_32a.c
@@ -0,0 +1,102 @@
 2+/* $Id$ */
 3+/*
 4+ * hash_32 - 32 bit Fowler/Noll/Vo FNV-1a hash code
 5+ *
 6+ * @(#) Revision: 1.1
 7+ * @(#) Id: hash_32a.c,v 1.1 2003/10/03 20:38:53 chongo Exp
 8+ * @(#) Source: /usr/local/src/cmd/fnv/RCS/hash_32a.c,v
 9+ *
 10+ ***
 11+ *
 12+ * Fowler/Noll/Vo hash
 13+ *
 14+ * The basis of this hash algorithm was taken from an idea sent
 15+ * as reviewer comments to the IEEE POSIX P1003.2 committee by:
 16+ *
 17+ * Phong Vo (http://www.research.att.com/info/kpv/)
 18+ * Glenn Fowler (http://www.research.att.com/~gsf/)
 19+ *
 20+ * In a subsequent ballot round:
 21+ *
 22+ * Landon Curt Noll (http://www.isthe.com/chongo/)
 23+ *
 24+ * improved on their algorithm. Some people tried this hash
 25+ * and found that it worked rather well. In an EMail message
 26+ * to Landon, they named it the ``Fowler/Noll/Vo'' or FNV hash.
 27+ *
 28+ * FNV hashes are designed to be fast while maintaining a low
 29+ * collision rate. The FNV speed allows one to quickly hash lots
 30+ * of data while maintaining a reasonable collision rate. See:
 31+ *
 32+ * http://www.isthe.com/chongo/tech/comp/fnv/index.html
 33+ *
 34+ * for more details as well as other forms of the FNV hash.
 35+ ***
 36+ *
 37+ * To use the recommended 32 bit FNV-1a hash, pass FNV1_32A_INIT as the
 38+ * Fnv32_t hashval argument to fnv_32a_buf() or fnv_32a_str().
 39+ *
 40+ ***
 41+ *
 42+ * Please do not copyright this code. This code is in the public domain.
 43+ *
 44+ * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 45+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
 46+ * EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 47+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
 48+ * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
 49+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 50+ * PERFORMANCE OF THIS SOFTWARE.
 51+ *
 52+ * By:
 53+ * chongo <Landon Curt Noll> /\oo/\
 54+ * http://www.isthe.com/chongo/
 55+ *
 56+ * Share and Enjoy! :-)
 57+ */
 58+
 59+#include <stdlib.h>
 60+#include "fnv.h"
 61+
 62+/*
 63+ * 32 bit magic FNV-1a prime
 64+ */
 65+#define FNV_32_PRIME ((Fnv32_t)0x01000193)
 66+
 67+/*
 68+ * fnv_32a_str - perform a 32 bit Fowler/Noll/Vo FNV-1a hash on a string
 69+ *
 70+ * input:
 71+ * str - string to hash
 72+ * hval - previous hash value or 0 if first call
 73+ *
 74+ * returns:
 75+ * 32 bit hash as a static hash type
 76+ *
 77+ * NOTE: To use the recommended 32 bit FNV-1a hash, use FNV1_32A_INIT as the
 78+ * hval arg on the first call to either fnv_32a_buf() or fnv_32a_str().
 79+ */
 80+Fnv32_t
 81+fnv_32a_str(char const *str, Fnv32_t hval)
 82+{
 83+ unsigned char *s = (unsigned char *)str; /* unsigned string */
 84+
 85+ /*
 86+ * FNV-1a hash each octet in the buffer
 87+ */
 88+ while (*s) {
 89+
 90+ /* xor the bottom with the current octet */
 91+ hval ^= (Fnv32_t)*s++;
 92+
 93+ /* multiply by the 32 bit FNV magic prime mod 2^32 */
 94+#if defined(NO_FNV_GCC_OPTIMIZATION)
 95+ hval *= FNV_32_PRIME;
 96+#else
 97+ hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
 98+#endif
 99+ }
 100+
 101+ /* return our new hash value */
 102+ return hval;
 103+}
Index: trunk/tools/trainwreck/trainwreck.c
@@ -522,13 +522,6 @@
523523 exit(1);
524524 }
525525
526 - if (len < 8 && master_conn->net.read_pos[0] == 254) {
527 - logmsg("no more logs!");
528 - reader_st = ST_STOPPED;
529 - pthread_mutex_unlock(&rst_mtx);
530 - return 1;
531 - }
532 -
533526 pthread_mutex_unlock(&rst_mtx);
534527
535528 if ((ent = parse_binlog(master_conn->net.read_pos + 1, len - 1)) == NULL) {

Status & tagging log