dictionary.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006  SRI International
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  * SRI International: 333 Ravenswood Ave, Menlo Park, CA 94025
00019  */
00020 
00021 /* Make sure only loaded once... */
00022 #ifndef _LIBDICO_H_INCLUDED
00023 #define _LIBDICO_H_INCLUDED
00024 
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028 
00029 #define INIT_CAPACITY 512
00030 
00031   typedef struct dictionary {
00032     int size;
00033     int capacity;
00034     int  (*compar)(void *, void *);    /* user fn for comparing keys & values */
00035     void (*keyfree)(void *);        /* user fn for freeing keeys */
00036     void **key;
00037     void **value;
00038   } DICTIONARY;
00039 
00040   /*
00041    * prototypes
00042    */
00043 
00044   extern DICTIONARY *dict_new(int (*_compar)(void *, void *), void (*_keyfree)(void *));
00045   extern int     dict_expand_capacity(DICTIONARY *dict);
00046   extern void     *dict_get(DICTIONARY *d, void *key);
00047   extern int dict_get_nth(DICTIONARY *d, void **key, void **value, int n);
00048   extern int     dict_index_for_key(DICTIONARY *d, void *key);
00049   extern void     *dict_put(DICTIONARY *d, void *key, void *value);
00050   extern void   *dict_put_nonunique(DICTIONARY *d, void *key, void *value);
00051   extern void   *dict_remove(DICTIONARY *d, void *key);
00052   extern void   *dict_remove_specific(DICTIONARY *d, void *key, void *value);
00053   extern void  **dict_remove_all(DICTIONARY *d, void *key, int *num_removed);
00054   extern void    dict_free(DICTIONARY *d);
00055 
00056 #ifdef __cplusplus
00057 }
00058 #endif
00059 
00060 #endif

Generated on Wed May 23 17:20:10 2007 using doxygen 1.5.2