Blame hash.h

Packit Service d8d8ac
/**
Packit Service d8d8ac
 * @file hash.h
Packit Service d8d8ac
 * @brief Implements a simple hash table.
Packit Service d8d8ac
 * @note Copyright (C) 2015 Richard Cochran <richardcochran@gmail.com>
Packit Service d8d8ac
 *
Packit Service d8d8ac
 * This program is free software; you can redistribute it and/or modify
Packit Service d8d8ac
 * it under the terms of the GNU General Public License as published by
Packit Service d8d8ac
 * the Free Software Foundation; either version 2 of the License, or
Packit Service d8d8ac
 * (at your option) any later version.
Packit Service d8d8ac
 *
Packit Service d8d8ac
 * This program is distributed in the hope that it will be useful,
Packit Service d8d8ac
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service d8d8ac
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service d8d8ac
 * GNU General Public License for more details.
Packit Service d8d8ac
 *
Packit Service d8d8ac
 * You should have received a copy of the GNU General Public License along
Packit Service d8d8ac
 * with this program; if not, write to the Free Software Foundation, Inc.,
Packit Service d8d8ac
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Packit Service d8d8ac
 */
Packit Service d8d8ac
#ifndef HAVE_HASH_H
Packit Service d8d8ac
#define HAVE_HASH_H
Packit Service d8d8ac
Packit Service d8d8ac
struct hash;
Packit Service d8d8ac
Packit Service d8d8ac
/**
Packit Service d8d8ac
 * Create a new hash table.
Packit Service d8d8ac
 * @return  A pointer to a new hash table on success, NULL otherwise.
Packit Service d8d8ac
 */
Packit Service d8d8ac
struct hash *hash_create(void);
Packit Service d8d8ac
Packit Service d8d8ac
/**
Packit Service d8d8ac
 * Destroy an instance of a hash table.
Packit Service d8d8ac
 * @param ht   Pointer to a hash table obtained via @ref hash_create().
Packit Service d8d8ac
 * @param func Callback function, possibly NULL, to apply to the
Packit Service d8d8ac
 *             data of each element in the table.
Packit Service d8d8ac
 */
Packit Service d8d8ac
void hash_destroy(struct hash *ht, void (*func)(void *));
Packit Service d8d8ac
Packit Service d8d8ac
/**
Packit Service d8d8ac
 * Inserts an element into a hash table.
Packit Service d8d8ac
 * @param ht   Hash table into which the element is to be stored.
Packit Service d8d8ac
 * @param key  Key that identifies the element.
Packit Service d8d8ac
 * @param data Pointer to the user data to be stored.
Packit Service d8d8ac
 * @return Zero on success and non-zero on error.  Attempting to
Packit Service d8d8ac
 *         insert a duplicate key will fail with an error.
Packit Service d8d8ac
 */
Packit Service d8d8ac
int hash_insert(struct hash *ht, const char* key, void *data);
Packit Service d8d8ac
Packit Service d8d8ac
/**
Packit Service d8d8ac
 * Looks up an element from the hash table.
Packit Service d8d8ac
 * @param ht   Hash table to consult.
Packit Service d8d8ac
 * @param key  Key identifying the element of interest.
Packit Service d8d8ac
 * @return  Pointer to the element's data, or NULL if the key is not found.
Packit Service d8d8ac
 */
Packit Service d8d8ac
void *hash_lookup(struct hash *ht, const char* key);
Packit Service d8d8ac
Packit Service d8d8ac
#endif
Packit Service d8d8ac
Packit Service d8d8ac