00001 /* 00002 * Copyright (C) 2006 Baris Simsek, http://www.enderunix.org/simsek 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 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 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00017 * 00018 * $Id: ds_8c-source.html,v 1.4 2006/08/26 09:35:02 simsek Exp $ 00019 * 00020 * Library for data structures. 00021 * 00022 */ 00023 00024 00025 #include <stdio.h> 00026 #include <stdlib.h> 00027 00028 #include "../include/cupl.h" 00029 #include "../include/ds.h" 00030 00031 static unsigned int cdb_hashadd(unsigned int h, unsigned char c); 00032 00033 /* DJB's hash function, derived from CDB project. */ 00034 /* http://cr.yp.to/cdb.html */ 00035 static unsigned int cdb_hashadd(unsigned int h, unsigned char c) 00036 { 00037 h += (h << 5); 00038 00039 return h ^ c; 00040 } 00041 00042 extern unsigned int cupl_hash_get(char *buf, unsigned int len, int tbl_size) 00043 { 00044 unsigned int h; 00045 00046 h = CDB_HASHSTART; 00047 while (len) { 00048 h = cdb_hashadd(h,*buf++); 00049 --len; 00050 } 00051 00052 return h % tbl_size; 00053 } 00054 00055
1.3.9.1