hashlist.h

Go to the documentation of this file.
00001 #ifndef _CP_HASHLIST_H
00002 #define _CP_HASHLIST_H
00003 
00011 /* ----------------------------------------------------------------- */
00012 
00013 #include "common.h"
00014 
00015 __BEGIN_DECLS
00016 
00017 #include "config.h"
00018 
00019 #include "collection.h"
00020 #include "hashtable.h"
00021 
00022 /*************/
00023 
00024 typedef CPROPS_DLL struct _cp_hashlist_entry
00025 {
00026     void *key;                         
00027     void *value;                       
00028     struct _cp_hashlist_entry *next;      
00029     struct _cp_hashlist_entry *prev;      
00030     struct _cp_hashlist_entry *bucket;    
00031 } cp_hashlist_entry;
00032 
00033 
00040 typedef CPROPS_DLL struct _cp_hashlist
00041 {
00042     cp_hashlist_entry **table;    
00043     cp_hashlist_entry *head;      
00044     cp_hashlist_entry *tail;      
00045     unsigned long table_size;     
00046     unsigned long items;          
00048     cp_hashfunction  hash_fn;     
00049     cp_compare_fn    compare_fn;  
00050     cp_copy_fn       copy_key;    
00051     cp_copy_fn       copy_value;  
00052     cp_destructor_fn free_key;
00053     cp_destructor_fn free_value;
00054 
00055     int mode;                     
00056     cp_lock *lock;                
00057     cp_thread txowner;            
00058     int txtype;                   
00060     unsigned long min_size;
00061     int fill_factor_min;          
00062     int fill_factor_max;          
00064 #if (CP_DEBUGLEVEL >= 2)
00065     cp_thread dtr_caller;
00066 #endif
00067 } cp_hashlist;
00068 
00072 typedef CPROPS_DLL struct _cp_hashlist_iterator
00073 {
00074     cp_hashlist *list;        
00075     cp_hashlist_entry **pos;   
00077     int lock_type;           
00078 } cp_hashlist_iterator;
00079 
00080 
00081 /*
00082  * Removes the entry with matching key and destroys it. 
00083  *
00084  * @param list the object
00085  * @param key  Key which is searched.
00086  * @param mode locking mode
00087  * @retval value that was stored in the entry.
00088  * @retval NULL if key was not found
00089  */
00090 CPROPS_DLL 
00091 void *cp_hashlist_remove_by_option(cp_hashlist *list, void *key, int mode);
00092 
00100 CPROPS_DLL 
00101 void *cp_hashlist_remove_head_by_option(cp_hashlist *list, int mode);
00102 
00110 CPROPS_DLL 
00111 void *cp_hashlist_remove_tail_by_option(cp_hashlist *list, int mode);
00112 
00113 /*************/
00114 
00116 #define cp_hashlist_create(size_hint, hash_fn, compare_fn) \
00117         cp_hashlist_create_by_option(0, (size_hint), \
00118                                      (hash_fn), (compare_fn), \
00119                                      NULL, NULL, NULL, NULL)
00120 
00129 CPROPS_DLL 
00130 cp_hashlist *cp_hashlist_create_by_mode(int mode, 
00131                                         unsigned long size_hint, 
00132                                         cp_hashfunction hash_fn, 
00133                                         cp_compare_fn compare_fn);
00134 
00145 CPROPS_DLL 
00146 cp_hashlist *
00147     cp_hashlist_create_by_option(int mode, unsigned long size_hint, 
00148                                  cp_hashfunction hash_fn, 
00149                                  cp_compare_fn compare_fn,
00150                                  cp_copy_fn copy_key, 
00151                                  cp_destructor_fn free_key,
00152                                  cp_copy_fn copy_value,
00153                                  cp_destructor_fn free_value);
00154 
00158 CPROPS_DLL 
00159 void cp_hashlist_destroy(cp_hashlist *);
00160 
00164 CPROPS_DLL 
00165 void cp_hashlist_destroy_deep(cp_hashlist *);
00166 
00173 CPROPS_DLL 
00174 void cp_hashlist_destroy_by_option(cp_hashlist *list, int mode);
00175 
00180 CPROPS_DLL 
00181 void cp_hashlist_destroy_custom(cp_hashlist *list, 
00182                                 cp_destructor_fn dk, 
00183                                 cp_destructor_fn dv);
00184 
00192 CPROPS_DLL 
00193 int cp_hashlist_callback(cp_hashlist *list, 
00194                          int (*cb)(void *key, void *value, void *id),
00195                          void *id);
00196 
00198 CPROPS_DLL 
00199 int cp_hashlist_get_mode(cp_hashlist *list);
00200 
00202 CPROPS_DLL 
00203 int cp_hashlist_set_mode(cp_hashlist *list, int mode);
00204 
00206 CPROPS_DLL 
00207 int cp_hashlist_unset_mode(cp_hashlist *list, int mode);
00208 
00209 
00213 CPROPS_DLL 
00214 int cp_hashlist_set_min_size(cp_hashlist *list, unsigned long min_size);
00215 
00220 CPROPS_DLL 
00221 int cp_hashlist_set_max_fill_factor(cp_hashlist *list, int fill_factor);
00222 
00227 CPROPS_DLL 
00228 int cp_hashlist_set_min_fill_factor(cp_hashlist *list, int fill_factor);
00229 
00230 
00231 /* **************************************************************************
00232  *                                                                          *
00233  *                            iterator functions                            *
00234  *                                                                          *
00235  ************************************************************************** */
00236 
00244 CPROPS_DLL 
00245 cp_hashlist_iterator *cp_hashlist_create_iterator(cp_hashlist *list, int lock_mode);
00246 
00253 CPROPS_DLL 
00254 int cp_hashlist_iterator_head(cp_hashlist_iterator *iterator);
00255 //int cp_hashlist_iterator_head(cp_hashlist_iterator *iterator, cp_hashlist *l, int lock_mode);
00256 
00257 CPROPS_DLL 
00258 int cp_hashlist_iterator_init(cp_hashlist_iterator *iterator, 
00259                               cp_hashlist *list, int type);
00266 CPROPS_DLL 
00267 int cp_hashlist_iterator_init_tail(cp_hashlist_iterator *iterator, cp_hashlist *l, int lock_mode);
00268 
00272 CPROPS_DLL 
00273 int cp_hashlist_iterator_tail(cp_hashlist_iterator *iterator);
00274 
00278 CPROPS_DLL 
00279 int cp_hashlist_iterator_to_key(cp_hashlist_iterator *iterator, void *key);
00280 
00284 CPROPS_DLL 
00285 int cp_hashlist_iterator_destroy(cp_hashlist_iterator *iterator);
00286 
00292 CPROPS_DLL 
00293 int cp_hashlist_iterator_release(cp_hashlist_iterator *iterator);
00294 
00295 
00302 CPROPS_DLL 
00303 cp_hashlist_entry *cp_hashlist_iterator_next(cp_hashlist_iterator *iterator);
00304 
00311 CPROPS_DLL 
00312 void *cp_hashlist_iterator_next_key(cp_hashlist_iterator *iterator);
00313 
00320 CPROPS_DLL 
00321 void *cp_hashlist_iterator_next_value(cp_hashlist_iterator *iterator);
00322 
00329 CPROPS_DLL 
00330 cp_hashlist_entry *cp_hashlist_iterator_prev(cp_hashlist_iterator *iterator);
00331 
00338 CPROPS_DLL 
00339 void *cp_hashlist_iterator_prev_key(cp_hashlist_iterator *iterator);
00340 
00347 CPROPS_DLL 
00348 void *cp_hashlist_iterator_prev_value(cp_hashlist_iterator *iterator);
00349 
00353 CPROPS_DLL 
00354 cp_hashlist_entry *cp_hashlist_iterator_curr(cp_hashlist_iterator *iterator);
00355 
00359 CPROPS_DLL 
00360 void *cp_hashlist_iterator_curr_key(cp_hashlist_iterator *iterator);
00361 
00365 CPROPS_DLL 
00366 void *cp_hashlist_iterator_curr_value(cp_hashlist_iterator *iterator);
00367 
00368 
00372 CPROPS_DLL 
00373 cp_hashlist_entry *cp_hashlist_iterator_insert(cp_hashlist_iterator *iterator, 
00374                                                void *key, 
00375                                                void *value);
00379 CPROPS_DLL 
00380 cp_hashlist_entry *cp_hashlist_iterator_append(cp_hashlist_iterator *iterator, 
00381                                                void *key,
00382                                                void *value);
00383 
00387 CPROPS_DLL 
00388 void *cp_hashlist_iterator_remove(cp_hashlist_iterator *iterator);
00389 
00390 
00391 /* ------------------------ end iterator functions ------------------------ */
00392 
00393 
00394 
00401 CPROPS_DLL 
00402 unsigned long cp_hashlist_item_count(cp_hashlist *);
00403 
00413 CPROPS_DLL 
00414 void *cp_hashlist_entry_get_key(cp_hashlist_entry *entry);
00415 
00425 CPROPS_DLL 
00426 void *cp_hashlist_entry_get_value(cp_hashlist_entry *entry);
00427 
00436 CPROPS_DLL 
00437 void *cp_hashlist_insert(cp_hashlist *list, void *key, void *value);
00438 
00443 CPROPS_DLL 
00444 void *cp_hashlist_insert_by_option(cp_hashlist *list, void *key, void *item, int mode);
00445 
00452 CPROPS_DLL 
00453 void *cp_hashlist_append(cp_hashlist *list, void *key, void *value);
00454 
00458 CPROPS_DLL 
00459 void *cp_hashlist_append_by_option(cp_hashlist *, void *key, void *value, int mode);
00460 
00464 CPROPS_DLL 
00465 void *cp_hashlist_get(cp_hashlist *, void *key);
00466 
00470 CPROPS_DLL 
00471 int cp_hashlist_contains(cp_hashlist *list, void *key);
00472 
00476 CPROPS_DLL 
00477 void *cp_hashlist_get_head(cp_hashlist *);
00478 
00482 CPROPS_DLL 
00483 void *cp_hashlist_get_tail(cp_hashlist *);
00484 
00493 CPROPS_DLL 
00494 void *cp_hashlist_remove(cp_hashlist *list, void *key);
00495 
00496 CPROPS_DLL 
00497 void *cp_hashlist_remove_deep(cp_hashlist *list, void *key);
00498 
00499 
00509 CPROPS_DLL 
00510 void *cp_hashlist_remove_by_option(cp_hashlist *list, void *key, int mode);
00511 
00517 CPROPS_DLL 
00518 void *cp_hashlist_remove_head(cp_hashlist *list);
00519 
00527 CPROPS_DLL 
00528 void *cp_hashlist_remove_tail(cp_hashlist *list);
00529 
00530 /*
00531  * Get the next entry. 
00532  *
00533  * @return value of the next element
00534  */
00535 //CPROPS_DLL 
00536 //void *cp_hashlist_get_next(cp_hashlist *list);
00537 
00544 CPROPS_DLL 
00545 int cp_hashlist_is_empty(cp_hashlist *list); //  { return cp_hashlist_item_count(list) == 0; }
00546 
00552 CPROPS_DLL 
00553 int cp_hashlist_lock(cp_hashlist *list, int type);
00554 
00558 CPROPS_DLL 
00559 int cp_hashlist_unlock(cp_hashlist *list);
00560 
00564 #define cp_hashlist_rdlock(list) cp_hashlist_lock((list), COLLECTION_LOCK_READ)
00565 
00569 #define cp_hashlist_wrlock(list) cp_hashlist_lock((list), COLLECTION_LOCK_WRITE)
00570 
00571 __END_DECLS
00572 
00575 #endif
00576 

Generated on Mon Dec 5 23:00:21 2011 for cprops by  doxygen 1.4.7