00001 /* 00002 * Author: MA Hartman 00003 * Date: may 24, 2007 00004 * 00005 * Function: 00006 * A general purpose dictionary implementation with 00007 * almost constant time get operations. 00008 * 00009 * License information: 00010 * 00011 * Copyright (c) 2006 Maurits Hartman 00012 * 00013 * Permission is hereby granted, free of charge, to any person 00014 * obtaining a copy of this software and associated documentation 00015 * files (the "Software"), to deal in the Software without 00016 * restriction, including without limitation the rights to use, 00017 * copy, modify, merge, publish, distribute, sublicense, and/or sell 00018 * copies of the Software, and to permit persons to whom the 00019 * Software is furnished to do so, subject to the following 00020 * conditions: 00021 * 00022 * The above copyright notice and this permission notice shall be 00023 * included in all copies or substantial portions of the Software. 00024 * 00025 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00026 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 00027 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00028 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 00029 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 00030 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00031 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00032 * OTHER DEALINGS IN THE SOFTWARE. 00033 * 00034 */ 00035 00036 #ifndef DICT_H_ 00037 #define DICT_H_ 00038 00039 #include "list.h" 00040 #include <biosphere.h> 00041 00042 #include <apr_pools.h> 00043 00044 00045 typedef struct bs_dict { 00046 bs_list *bucket[256]; 00047 unsigned size; 00048 apr_pool_t *pool; 00049 } bs_dict; 00050 00054 typedef struct bs_dict_item { 00055 const char *key; 00056 void *data; 00057 } bs_dict_item; 00058 00064 bs_dict *new_dict(apr_pool_t *mp); 00065 00071 void delete_dict(bs_dict *dict); 00072 00079 void *dict_get(const bs_dict *dict, const char *key); 00080 00088 bs_bool dict_add(bs_dict *dict, const char *key, void *data); 00089 00095 void dict_remove(bs_dict *dict, const char *key); 00096 00102 inline unsigned dict_size(const bs_dict *dict); 00103 00104 #endif /*DICT_H_*/