00001 #ifndef _CP_HASHLIST_H
00002 #define _CP_HASHLIST_H
00003
00004
00005
00006
00007
00008
00009
00010
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
00034
00035
00036
00037
00038
00039
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;
00047
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;
00059
00060 unsigned long min_size;
00061 int fill_factor_min;
00062 int fill_factor_max;
00063
00064 #if (CP_DEBUGLEVEL >= 2)
00065 cp_thread dtr_caller;
00066 #endif
00067 } cp_hashlist;
00068
00069
00070
00071
00072 typedef CPROPS_DLL struct _cp_hashlist_iterator
00073 {
00074 cp_hashlist *list;
00075 cp_hashlist_entry **pos;
00076
00077 int lock_type;
00078 } cp_hashlist_iterator;
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 CPROPS_DLL
00091 void *cp_hashlist_remove_by_option(cp_hashlist *list, void *key, int mode);
00092
00093
00094
00095
00096
00097
00098
00099
00100 CPROPS_DLL
00101 void *cp_hashlist_remove_head_by_option(cp_hashlist *list, int mode);
00102
00103
00104
00105
00106
00107
00108
00109
00110 CPROPS_DLL
00111 void *cp_hashlist_remove_tail_by_option(cp_hashlist *list, int mode);
00112
00113
00114
00115
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
00121
00122
00123
00124
00125
00126
00127
00128
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
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
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
00155
00156
00157
00158 CPROPS_DLL
00159 void cp_hashlist_destroy(cp_hashlist *);
00160
00161
00162
00163
00164 CPROPS_DLL
00165 void cp_hashlist_destroy_deep(cp_hashlist *);
00166
00167
00168
00169
00170
00171
00172
00173 CPROPS_DLL
00174 void cp_hashlist_destroy_by_option(cp_hashlist *list, int mode);
00175
00176
00177
00178
00179
00180 CPROPS_DLL
00181 void cp_hashlist_destroy_custom(cp_hashlist *list,
00182 cp_destructor_fn dk,
00183 cp_destructor_fn dv);
00184
00185
00186
00187
00188
00189
00190
00191
00192 CPROPS_DLL
00193 int cp_hashlist_callback(cp_hashlist *list,
00194 int (*cb)(void *key, void *value, void *id),
00195 void *id);
00196
00197
00198 CPROPS_DLL
00199 int cp_hashlist_get_mode(cp_hashlist *list);
00200
00201
00202 CPROPS_DLL
00203 int cp_hashlist_set_mode(cp_hashlist *list, int mode);
00204
00205
00206 CPROPS_DLL
00207 int cp_hashlist_unset_mode(cp_hashlist *list, int mode);
00208
00209
00210
00211
00212
00213 CPROPS_DLL
00214 int cp_hashlist_set_min_size(cp_hashlist *list, unsigned long min_size);
00215
00216
00217
00218
00219
00220 CPROPS_DLL
00221 int cp_hashlist_set_max_fill_factor(cp_hashlist *list, int fill_factor);
00222
00223
00224
00225
00226
00227 CPROPS_DLL
00228 int cp_hashlist_set_min_fill_factor(cp_hashlist *list, int fill_factor);
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 CPROPS_DLL
00245 cp_hashlist_iterator *cp_hashlist_create_iterator(cp_hashlist *list, int lock_mode);
00246
00247
00248
00249
00250
00251
00252
00253 CPROPS_DLL
00254 int cp_hashlist_iterator_head(cp_hashlist_iterator *iterator);
00255
00256
00257 CPROPS_DLL
00258 int cp_hashlist_iterator_init(cp_hashlist_iterator *iterator,
00259 cp_hashlist *list, int type);
00260
00261
00262
00263
00264
00265
00266 CPROPS_DLL
00267 int cp_hashlist_iterator_init_tail(cp_hashlist_iterator *iterator, cp_hashlist *l, int lock_mode);
00268
00269
00270
00271
00272 CPROPS_DLL
00273 int cp_hashlist_iterator_tail(cp_hashlist_iterator *iterator);
00274
00275
00276
00277
00278 CPROPS_DLL
00279 int cp_hashlist_iterator_to_key(cp_hashlist_iterator *iterator, void *key);
00280
00281
00282
00283
00284 CPROPS_DLL
00285 int cp_hashlist_iterator_destroy(cp_hashlist_iterator *iterator);
00286
00287
00288
00289
00290
00291
00292 CPROPS_DLL
00293 int cp_hashlist_iterator_release(cp_hashlist_iterator *iterator);
00294
00295
00296
00297
00298
00299
00300
00301
00302 CPROPS_DLL
00303 cp_hashlist_entry *cp_hashlist_iterator_next(cp_hashlist_iterator *iterator);
00304
00305
00306
00307
00308
00309
00310
00311 CPROPS_DLL
00312 void *cp_hashlist_iterator_next_key(cp_hashlist_iterator *iterator);
00313
00314
00315
00316
00317
00318
00319
00320 CPROPS_DLL
00321 void *cp_hashlist_iterator_next_value(cp_hashlist_iterator *iterator);
00322
00323
00324
00325
00326
00327
00328
00329 CPROPS_DLL
00330 cp_hashlist_entry *cp_hashlist_iterator_prev(cp_hashlist_iterator *iterator);
00331
00332
00333
00334
00335
00336
00337
00338 CPROPS_DLL
00339 void *cp_hashlist_iterator_prev_key(cp_hashlist_iterator *iterator);
00340
00341
00342
00343
00344
00345
00346
00347 CPROPS_DLL
00348 void *cp_hashlist_iterator_prev_value(cp_hashlist_iterator *iterator);
00349
00350
00351
00352
00353 CPROPS_DLL
00354 cp_hashlist_entry *cp_hashlist_iterator_curr(cp_hashlist_iterator *iterator);
00355
00356
00357
00358
00359 CPROPS_DLL
00360 void *cp_hashlist_iterator_curr_key(cp_hashlist_iterator *iterator);
00361
00362
00363
00364
00365 CPROPS_DLL
00366 void *cp_hashlist_iterator_curr_value(cp_hashlist_iterator *iterator);
00367
00368
00369
00370
00371
00372 CPROPS_DLL
00373 cp_hashlist_entry *cp_hashlist_iterator_insert(cp_hashlist_iterator *iterator,
00374 void *key,
00375 void *value);
00376
00377
00378
00379 CPROPS_DLL
00380 cp_hashlist_entry *cp_hashlist_iterator_append(cp_hashlist_iterator *iterator,
00381 void *key,
00382 void *value);
00383
00384
00385
00386
00387 CPROPS_DLL
00388 void *cp_hashlist_iterator_remove(cp_hashlist_iterator *iterator);
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401 CPROPS_DLL
00402 unsigned long cp_hashlist_item_count(cp_hashlist *);
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 CPROPS_DLL
00414 void *cp_hashlist_entry_get_key(cp_hashlist_entry *entry);
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425 CPROPS_DLL
00426 void *cp_hashlist_entry_get_value(cp_hashlist_entry *entry);
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436 CPROPS_DLL
00437 void *cp_hashlist_insert(cp_hashlist *list, void *key, void *value);
00438
00439
00440
00441
00442
00443 CPROPS_DLL
00444 void *cp_hashlist_insert_by_option(cp_hashlist *list, void *key, void *item, int mode);
00445
00446
00447
00448
00449
00450
00451
00452 CPROPS_DLL
00453 void *cp_hashlist_append(cp_hashlist *list, void *key, void *value);
00454
00455
00456
00457
00458 CPROPS_DLL
00459 void *cp_hashlist_append_by_option(cp_hashlist *, void *key, void *value, int mode);
00460
00461
00462
00463
00464 CPROPS_DLL
00465 void *cp_hashlist_get(cp_hashlist *, void *key);
00466
00467
00468
00469
00470 CPROPS_DLL
00471 int cp_hashlist_contains(cp_hashlist *list, void *key);
00472
00473
00474
00475
00476 CPROPS_DLL
00477 void *cp_hashlist_get_head(cp_hashlist *);
00478
00479
00480
00481
00482 CPROPS_DLL
00483 void *cp_hashlist_get_tail(cp_hashlist *);
00484
00485
00486
00487
00488
00489
00490
00491
00492
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
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509 CPROPS_DLL
00510 void *cp_hashlist_remove_by_option(cp_hashlist *list, void *key, int mode);
00511
00512
00513
00514
00515
00516
00517 CPROPS_DLL
00518 void *cp_hashlist_remove_head(cp_hashlist *list);
00519
00520
00521
00522
00523
00524
00525
00526
00527 CPROPS_DLL
00528 void *cp_hashlist_remove_tail(cp_hashlist *list);
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544 CPROPS_DLL
00545 int cp_hashlist_is_empty(cp_hashlist *list);
00546
00547
00548
00549
00550
00551
00552 CPROPS_DLL
00553 int cp_hashlist_lock(cp_hashlist *list, int type);
00554
00555
00556
00557
00558 CPROPS_DLL
00559 int cp_hashlist_unlock(cp_hashlist *list);
00560
00561
00562
00563
00564 #define cp_hashlist_rdlock(list) cp_hashlist_lock((list), COLLECTION_LOCK_READ)
00565
00566
00567
00568
00569 #define cp_hashlist_wrlock(list) cp_hashlist_lock((list), COLLECTION_LOCK_WRITE)
00570
00571 __END_DECLS
00572
00573
00574
00575 #endif
00576