/* Hash map ADT V1.00 25/11/05
   Copyright 2008 Jeffrey Lee
   This file is part of WOUM.
   WOUM is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
   WOUM is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   You should have received a copy of the GNU General Public License
   along with WOUM.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _HMAP_H
#define _HMAP_H

typedef void *hmap; /* hmap structure */

extern hmap hmap_create(int (*cmp)(const void *a,const void *b),int (*hash)(const void *a),int size,int killkeys); /* Create empty hmap table, using supplied comparison func and hashing func. size is the number of entries in the hash lookup table; it must be a power of 2. All values returned by the hash function should be between 0 and this number. If killkeys is 1, key pointers will be free()d as the items are removed from the hmap. Returns 0 on failure. */
extern void hmap_kill(hmap h); /* Delete hmap. */
extern int hmap_size(hmap h); /* Returns number of keys/values in hmap */
extern void **hmap_keys(hmap h); /* Returns array containing all key pointers in the hmap, in an arbitrary order. Returns 0 on failure. */
extern void **hmap_values(hmap h); /* Returns array containing all value pointers in the hmap, in an arbitrary order. Returns 0 on failure. */
extern int hmap_add(hmap h,void *key,void *value); /* Add an item to the table. Returns !0 on failure. Will fail if an item with the same key already exists */
extern int hmap_remove(hmap h,void *key); /* Remove an item by key. Returns the number of items removed (0 or 1). */
extern int hmap_remove2(hmap h,void *value); /* Remove an item by value. Returns the number of items removed. */
extern void *hmap_get(hmap h,void *key); /* Return the value of a specific key. Returns 0 on failure. */
extern int hmap_contains(hmap h,void *key); /* Returns !0 if the hmap contains a value with key 'key' */

#endif
