/* Sorted map ADT V1.02 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 _SMAP_H
#define _SMAP_H

typedef void *smap; /* smap structure */

extern smap smap_create(int (*cmp)(const void *a,const void *b),int killkeys); /* Create empty sorted map table, using supplied comparison func (if any). If killkeys is 1 and the comparison func has been supplied, key pointers will be free()d as the items are removed from the smap. Returns 0 on failure. */
extern void smap_kill(smap h); /* Delete smap. */
extern int smap_size(smap h); /* Returns number of keys/values in smap */
extern int *smap_keys(smap h); /* Returns array containing all key (pointers) in the smap, in sort order. Returns 0 on failure. */
extern void **smap_values(smap h); /* Returns array containing all value pointers in the smap, in sort order. Returns 0 on failure. */
extern int smap_add(smap h,int 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 smap_remove(smap h,int key); /* Remove an item by key. Returns the number of items removed (0 or 1). */
extern int smap_remove2(smap h,void *value); /* Remove an item by value. Returns the number of items removed. */
extern void *smap_get(smap h,int key); /* Return the value of a specific key. Returns 0 on failure. */
extern int smap_contains(smap h,int key); /* Returns !0 if the smap contains a value with key 'key' */

#endif
