00001 /* 00002 ** Copyright (C) 2006 by Kevin L. Mitchell <klmitch@mit.edu> 00003 ** 00004 ** This library is free software; you can redistribute it and/or 00005 ** modify it under the terms of the GNU Library General Public 00006 ** License as published by the Free Software Foundation; either 00007 ** version 2 of the License, or (at your option) any later version. 00008 ** 00009 ** This library is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 ** Library General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU Library General Public 00015 ** License along with this library; if not, write to the Free 00016 ** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00017 ** MA 02111-1307, USA 00018 ** 00019 ** @(#)$Id: hash_fnv1a.c,v 1.1 2006/07/13 20:27:36 klmitch Exp $ 00020 */ 00029 #include "dbprim.h" 00030 #include "dbprim_int.h" 00031 00032 RCSTAG("@(#)$Id: hash_fnv1a.c,v 1.1 2006/07/13 20:27:36 klmitch Exp $"); 00033 00034 unsigned long 00035 hash_fnv1a(hash_table_t *table, db_key_t *key) 00036 { 00037 int i; 00038 unsigned long hash = HASH_FNV_OFFSET; 00039 unsigned char *c; 00040 00041 if (!key || !dk_len(key) || !dk_key(key)) /* invalid key? return 0 */ 00042 return 0; 00043 00044 c = (unsigned char *)dk_key(key); 00045 for (i = 0; i < dk_len(key); i++) { /* FNV-1a algorithm... */ 00046 hash ^= *c; /* hash in the data octet */ 00047 hash *= HASH_FNV_PRIME; /* multiply by the prime... */ 00048 } 00049 00050 return hash; 00051 }