Blame hash.h

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