1b7579f77SDag-Erling Smørgrav /* 2b7579f77SDag-Erling Smørgrav * util/storage/lookup3.h - header file for hashing functions. 3b7579f77SDag-Erling Smørgrav * 4b7579f77SDag-Erling Smørgrav * Copyright (c) 2007, NLnet Labs. All rights reserved. 5b7579f77SDag-Erling Smørgrav * 6b7579f77SDag-Erling Smørgrav * This software is open source. 7b7579f77SDag-Erling Smørgrav * 8b7579f77SDag-Erling Smørgrav * Redistribution and use in source and binary forms, with or without 9b7579f77SDag-Erling Smørgrav * modification, are permitted provided that the following conditions 10b7579f77SDag-Erling Smørgrav * are met: 11b7579f77SDag-Erling Smørgrav * 12b7579f77SDag-Erling Smørgrav * Redistributions of source code must retain the above copyright notice, 13b7579f77SDag-Erling Smørgrav * this list of conditions and the following disclaimer. 14b7579f77SDag-Erling Smørgrav * 15b7579f77SDag-Erling Smørgrav * Redistributions in binary form must reproduce the above copyright notice, 16b7579f77SDag-Erling Smørgrav * this list of conditions and the following disclaimer in the documentation 17b7579f77SDag-Erling Smørgrav * and/or other materials provided with the distribution. 18b7579f77SDag-Erling Smørgrav * 19b7579f77SDag-Erling Smørgrav * Neither the name of the NLNET LABS nor the names of its contributors may 20b7579f77SDag-Erling Smørgrav * be used to endorse or promote products derived from this software without 21b7579f77SDag-Erling Smørgrav * specific prior written permission. 22b7579f77SDag-Erling Smørgrav * 23b7579f77SDag-Erling Smørgrav * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24*17d15b25SDag-Erling Smørgrav * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25*17d15b25SDag-Erling Smørgrav * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26*17d15b25SDag-Erling Smørgrav * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27*17d15b25SDag-Erling Smørgrav * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28*17d15b25SDag-Erling Smørgrav * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29*17d15b25SDag-Erling Smørgrav * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30*17d15b25SDag-Erling Smørgrav * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31*17d15b25SDag-Erling Smørgrav * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32*17d15b25SDag-Erling Smørgrav * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33*17d15b25SDag-Erling Smørgrav * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34b7579f77SDag-Erling Smørgrav */ 35b7579f77SDag-Erling Smørgrav 36b7579f77SDag-Erling Smørgrav /** 37b7579f77SDag-Erling Smørgrav * \file 38b7579f77SDag-Erling Smørgrav * 39b7579f77SDag-Erling Smørgrav * This file contains header definitions for the hash functions we use. 40b7579f77SDag-Erling Smørgrav * The hash functions are public domain (see lookup3.c). 41b7579f77SDag-Erling Smørgrav */ 42b7579f77SDag-Erling Smørgrav 43b7579f77SDag-Erling Smørgrav #ifndef UTIL_STORAGE_LOOKUP3_H 44b7579f77SDag-Erling Smørgrav #define UTIL_STORAGE_LOOKUP3_H 45b7579f77SDag-Erling Smørgrav 46b7579f77SDag-Erling Smørgrav /** 47b7579f77SDag-Erling Smørgrav * Hash key made of 4byte chunks. 48b7579f77SDag-Erling Smørgrav * @param k: the key, an array of uint32_t values 49b7579f77SDag-Erling Smørgrav * @param length: the length of the key, in uint32_ts 50b7579f77SDag-Erling Smørgrav * @param initval: the previous hash, or an arbitrary value 51b7579f77SDag-Erling Smørgrav * @return: hash value. 52b7579f77SDag-Erling Smørgrav */ 53b7579f77SDag-Erling Smørgrav uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval); 54b7579f77SDag-Erling Smørgrav 55b7579f77SDag-Erling Smørgrav /** 56b7579f77SDag-Erling Smørgrav * Hash key data. 57b7579f77SDag-Erling Smørgrav * @param k: the key, array of uint8_t 58b7579f77SDag-Erling Smørgrav * @param length: the length of the key, in uint8_ts 59b7579f77SDag-Erling Smørgrav * @param initval: the previous hash, or an arbitrary value 60b7579f77SDag-Erling Smørgrav * @return: hash value. 61b7579f77SDag-Erling Smørgrav */ 62b7579f77SDag-Erling Smørgrav uint32_t hashlittle(const void *k, size_t length, uint32_t initval); 63b7579f77SDag-Erling Smørgrav 64b7579f77SDag-Erling Smørgrav /** 65b7579f77SDag-Erling Smørgrav * Set the randomisation initial value, set this before threads start, 66b7579f77SDag-Erling Smørgrav * and before hashing stuff (because it changes subsequent results). 67b7579f77SDag-Erling Smørgrav * @param v: value 68b7579f77SDag-Erling Smørgrav */ 69b7579f77SDag-Erling Smørgrav void hash_set_raninit(uint32_t v); 70b7579f77SDag-Erling Smørgrav 71b7579f77SDag-Erling Smørgrav #endif /* UTIL_STORAGE_LOOKUP3_H */ 72