#include <sc_hash.h>
Public 型 | |
typedef unsigned(* | hash_fn_t )(const void *) |
typedef int(* | cmpr_fn_t )(const void *, const void *) |
Public メソッド | |
sc_phash_base (void *def=0, int size=PHASH_DEFAULT_INIT_TABLE_SIZE, int density=PHASH_DEFAULT_MAX_DENSITY, double grow=PHASH_DEFAULT_GROW_FACTOR, bool reorder=PHASH_DEFAULT_REORDER_FLAG, hash_fn_t hash_fn=default_ptr_hash_fn, cmpr_fn_t cmpr_fn=0) | |
~sc_phash_base () | |
void | set_cmpr_fn (cmpr_fn_t) |
void | set_hash_fn (hash_fn_t) |
bool | empty () const |
unsigned | count () const |
void | erase () |
void | erase (void(*kfree)(void *)) |
void | copy (const sc_phash_base *) |
void | copy (const sc_phash_base &b) |
void | copy (const sc_phash_base &b, void *(*kdup)(const void *), void(*kfree)(void *)) |
int | insert (void *k, void *c) |
int | insert (void *k) |
int | insert (void *k, void *c, void *(*kdup)(const void *)) |
int | insert_if_not_exists (void *k, void *c) |
int | insert_if_not_exists (void *k) |
int | insert_if_not_exists (void *k, void *c, void *(*kdup)(const void *)) |
int | remove (const void *k) |
int | remove (const void *k, void **pk, void **pc) |
int | remove (const void *k, void(*kfree)(void *)) |
int | remove_by_contents (const void *c) |
int | remove_by_contents (bool(*predicate)(const void *, void *), void *arg) |
int | remove_by_contents (const void *c, void(*kfree)(void *)) |
int | remove_by_contents (bool(*predicate)(const void *, void *), void *arg, void(*kfree)(void *)) |
int | lookup (const void *k, void **pc) const |
bool | contains (const void *k) const |
void * | operator[] (const void *key) const |
Protected メソッド | |
void | rehash () |
unsigned | do_hash (const void *key) const |
sc_phash_elem * | add_direct (void *key, void *contents, unsigned hash_val) |
sc_phash_elem * | find_entry_c (unsigned hv, const void *k, sc_phash_elem ***plast) |
sc_phash_elem * | find_entry_q (unsigned hv, const void *k, sc_phash_elem ***plast) |
sc_phash_elem * | find_entry (unsigned hv, const void *k, sc_phash_elem ***plast=0) const |
Protected 変数 | |
void * | default_value |
int | num_bins |
int | num_entries |
int | max_density |
int | reorder_flag |
double | grow_factor |
sc_phash_elem ** | bins |
hash_fn_t | hash |
cmpr_fn_t | cmpr |
Private 型 | |
typedef sc_phash_base_iter | iterator |
フレンド | |
class | sc_phash_base_iter |
typedef sc_phash_base_iter sc_core::sc_phash_base::iterator [private] |
typedef unsigned(* sc_core::sc_phash_base::hash_fn_t)(const void *) |
typedef int(* sc_core::sc_phash_base::cmpr_fn_t)(const void *, const void *) |
sc_core::sc_phash_base::sc_phash_base | ( | void * | def = 0 , |
|
int | size = PHASH_DEFAULT_INIT_TABLE_SIZE , |
|||
int | density = PHASH_DEFAULT_MAX_DENSITY , |
|||
double | grow = PHASH_DEFAULT_GROW_FACTOR , |
|||
bool | reorder = PHASH_DEFAULT_REORDER_FLAG , |
|||
hash_fn_t | hash_fn = default_ptr_hash_fn , |
|||
cmpr_fn_t | cmpr_fn = 0 | |||
) |
sc_core::sc_phash_base::~sc_phash_base | ( | ) |
sc_hash.cpp の 118 行で定義されています。
00119 { 00120 sc_phash_elem* ptr; 00121 sc_phash_elem* next; 00122 00123 for (int i = 0; i < num_bins; ++i) { 00124 ptr = bins[i]; 00125 while (ptr != 0) { 00126 next = ptr->next; 00127 delete ptr; 00128 ptr = next; 00129 } 00130 } 00131 delete[] bins; 00132 }
void sc_core::sc_phash_base::rehash | ( | ) | [protected] |
sc_hash.cpp の 135 行で定義されています。
00136 { 00137 sc_phash_elem* ptr; 00138 sc_phash_elem* next; 00139 sc_phash_elem** old_bins = bins; 00140 00141 int old_num_bins = num_bins; 00142 unsigned hash_val; 00143 00144 num_bins = (int) (grow_factor * old_num_bins); 00145 if (num_bins % 2 == 0) 00146 ++num_bins; 00147 00148 num_entries = 0; 00149 bins = new sc_phash_elem*[num_bins]; 00150 memset( bins, 0, sizeof(sc_phash_elem*) * num_bins ); 00151 00152 for (int i = 0; i < old_num_bins; ++i) { 00153 ptr = old_bins[i]; 00154 while (ptr != 0) { 00155 next = ptr->next; 00156 hash_val = do_hash(ptr->key); 00157 ptr->next = bins[hash_val]; 00158 bins[hash_val] = ptr; 00159 ++num_entries; 00160 ptr = next; 00161 } 00162 } 00163 delete[] old_bins; 00164 }
unsigned sc_core::sc_phash_base::do_hash | ( | const void * | key | ) | const [inline, protected] |
sc_phash_elem * sc_core::sc_phash_base::add_direct | ( | void * | key, | |
void * | contents, | |||
unsigned | hash_val | |||
) | [protected] |
sc_hash.cpp の 210 行で定義されています。
00211 { 00212 if (num_entries / num_bins >= max_density) { 00213 rehash(); 00214 hash_val = do_hash(key); 00215 } 00216 00217 sc_phash_elem* new_entry = new sc_phash_elem(key, contents, bins[hash_val]); 00218 bins[hash_val] = new_entry; 00219 ++num_entries; 00220 return new_entry; 00221 }
sc_phash_elem * sc_core::sc_phash_base::find_entry_c | ( | unsigned | hv, | |
const void * | k, | |||
sc_phash_elem *** | plast | |||
) | [protected] |
sc_hash.cpp の 189 行で定義されています。
00190 { 00191 sc_phash_elem** last = &(bins[hash_val]); 00192 sc_phash_elem* ptr = *last; 00193 00194 while ((ptr != 0) && ((*cmpr)(ptr->key, key) != 0)) { 00195 last = &(ptr->next); 00196 ptr = *last; 00197 } 00198 /* Bring to front */ 00199 if ((ptr != 0) && reorder_flag) { 00200 *last = ptr->next; 00201 ptr->next = bins[hash_val]; 00202 bins[hash_val] = ptr; 00203 last = &(bins[hash_val]); 00204 } 00205 if (plast) *plast = last; 00206 return ptr; 00207 }
sc_phash_elem * sc_core::sc_phash_base::find_entry_q | ( | unsigned | hv, | |
const void * | k, | |||
sc_phash_elem *** | plast | |||
) | [protected] |
sc_hash.cpp の 167 行で定義されています。
00168 { 00169 sc_phash_elem** last = &(bins[hash_val]); 00170 sc_phash_elem* ptr = *last; 00171 00172 /* The (ptr->key != key) here is meant by the "q" */ 00173 while ((ptr != 0) && (ptr->key != key)) { 00174 /* ^^ right here */ 00175 last = &(ptr->next); 00176 ptr = *last; 00177 } 00178 if ((ptr != 0) && reorder_flag) { 00179 *last = ptr->next; 00180 ptr->next = bins[hash_val]; 00181 bins[hash_val] = ptr; 00182 last = &(bins[hash_val]); 00183 } 00184 if (plast) *plast = last; 00185 return ptr; 00186 }
sc_phash_elem* sc_core::sc_phash_base::find_entry | ( | unsigned | hv, | |
const void * | k, | |||
sc_phash_elem *** | plast = 0 | |||
) | const [inline, protected] |
00095 { 00096 /* Got rid of member func. pointer and replaced with if-else */ 00097 /* Amit (5/14/99) */ 00098 if( cmpr == 0 ) 00099 return ((sc_phash_base*)this)->find_entry_q( hv, k, plast ); 00100 else 00101 return ((sc_phash_base*)this)->find_entry_c( hv, k, plast ); 00102 }
void sc_core::sc_phash_base::set_cmpr_fn | ( | cmpr_fn_t | c | ) |
void sc_core::sc_phash_base::set_hash_fn | ( | hash_fn_t | h | ) |
bool sc_core::sc_phash_base::empty | ( | ) | const [inline] |
unsigned sc_core::sc_phash_base::count | ( | ) | const [inline] |
void sc_core::sc_phash_base::erase | ( | ) |
sc_core::sc_pdhash< K, C >, sc_core::sc_strhash< C >, と sc_core::sc_strhash< int * >で再定義されています。
sc_hash.cpp の 224 行で定義されています。
00225 { 00226 for (int i = 0; i < num_bins; ++i) { 00227 sc_phash_elem* ptr = bins[i]; 00228 while (ptr != 0) { 00229 sc_phash_elem* next = ptr->next; 00230 delete ptr; 00231 ptr = next; 00232 --num_entries; 00233 } 00234 bins[i] = 0; 00235 } 00236 assert(num_entries == 0); 00237 }
void sc_core::sc_phash_base::erase | ( | void(*)(void *) | kfree | ) |
sc_hash.cpp の 240 行で定義されています。
00241 { 00242 for (int i = 0; i < num_bins; ++i) { 00243 sc_phash_elem* ptr = bins[i]; 00244 while (ptr != 0) { 00245 sc_phash_elem* next = ptr->next; 00246 (*kfree)(ptr->key); 00247 delete ptr; 00248 ptr = next; 00249 --num_entries; 00250 } 00251 bins[i] = 0; 00252 } 00253 assert(num_entries == 0); 00254 }
void sc_core::sc_phash_base::copy | ( | const sc_phash_base * | b | ) |
sc_hash.cpp の 257 行で定義されています。
00258 { 00259 erase(); 00260 iterator iter((sc_phash_base*) b); /* cast away the const */ 00261 for ( ; ! iter.empty(); iter++) 00262 insert( iter.key(), iter.contents() ); 00263 }
void sc_core::sc_phash_base::copy | ( | const sc_phash_base & | b | ) | [inline] |
void sc_core::sc_phash_base::copy | ( | const sc_phash_base & | b, | |
void *(*)(const void *) | kdup, | |||
void(*)(void *) | kfree | |||
) |
sc_hash.cpp の 266 行で定義されています。
00267 { 00268 erase(kfree); 00269 iterator iter((sc_phash_base&) b); 00270 for ( ; ! iter.empty(); iter++) 00271 insert( (*kdup)(iter.key()), iter.contents() ); 00272 }
int sc_core::sc_phash_base::insert | ( | void * | k, | |
void * | c | |||
) |
sc_hash.cpp の 275 行で定義されています。
00276 { 00277 unsigned hash_val = do_hash(k); 00278 sc_phash_elem* ptr = find_entry( hash_val, k ); 00279 if (ptr == 0) { 00280 (void) add_direct(k, c, hash_val); 00281 return 0; 00282 } 00283 else { 00284 ptr->contents = c; 00285 return 1; 00286 } 00287 }
int sc_core::sc_phash_base::insert | ( | void * | k | ) | [inline] |
int sc_core::sc_phash_base::insert | ( | void * | k, | |
void * | c, | |||
void *(*)(const void *) | kdup | |||
) |
sc_hash.cpp の 290 行で定義されています。
00291 { 00292 unsigned hash_val = do_hash(k); 00293 sc_phash_elem* ptr = find_entry( hash_val, k ); 00294 if (ptr == 0) { 00295 (void) add_direct((*kdup)(k), c, hash_val); 00296 return 0; 00297 } 00298 else { 00299 ptr->contents = c; 00300 return 1; 00301 } 00302 }
int sc_core::sc_phash_base::insert_if_not_exists | ( | void * | k, | |
void * | c | |||
) |
sc_hash.cpp の 305 行で定義されています。
00306 { 00307 unsigned hash_val = do_hash(k); 00308 sc_phash_elem* ptr = find_entry( hash_val, k ); 00309 if (ptr == 0) { 00310 (void) add_direct( k, c, hash_val ); 00311 return 0; 00312 } 00313 else 00314 return 1; 00315 }
int sc_core::sc_phash_base::insert_if_not_exists | ( | void * | k | ) | [inline] |
int sc_core::sc_phash_base::insert_if_not_exists | ( | void * | k, | |
void * | c, | |||
void *(*)(const void *) | kdup | |||
) |
sc_hash.cpp の 318 行で定義されています。
00319 { 00320 unsigned hash_val = do_hash(k); 00321 sc_phash_elem* ptr = find_entry( hash_val, k ); 00322 if (ptr == 0) { 00323 (void) add_direct( (*kdup)(k), c, hash_val ); 00324 return 0; 00325 } 00326 else 00327 return 1; 00328 }
int sc_core::sc_phash_base::remove | ( | const void * | k | ) |
sc_hash.cpp の 331 行で定義されています。
00332 { 00333 unsigned hash_val = do_hash(k); 00334 sc_phash_elem** last; 00335 sc_phash_elem* ptr = find_entry( hash_val, k, &last ); 00336 00337 if (ptr == 0) 00338 return 0; 00339 00340 assert(*last == ptr); 00341 *last = ptr->next; 00342 delete ptr; 00343 --num_entries; 00344 return 1; 00345 }
int sc_core::sc_phash_base::remove | ( | const void * | k, | |
void ** | pk, | |||
void ** | pc | |||
) |
sc_hash.cpp の 348 行で定義されています。
00349 { 00350 unsigned hash_val = do_hash(k); 00351 sc_phash_elem** last; 00352 sc_phash_elem* ptr = find_entry( hash_val, k, &last ); 00353 00354 if (ptr == 0) { 00355 *pk = 0; 00356 *pc = 0; 00357 return 0; 00358 } 00359 else { 00360 *pk = ptr->key; 00361 *pc = ptr->contents; 00362 } 00363 00364 assert(*last == ptr); 00365 *last = ptr->next; 00366 delete ptr; 00367 --num_entries; 00368 return 1; 00369 }
int sc_core::sc_phash_base::remove | ( | const void * | k, | |
void(*)(void *) | kfree | |||
) |
sc_hash.cpp の 372 行で定義されています。
00373 { 00374 void* rk; 00375 void* rc; 00376 if (remove(k, &rk, &rc)) { 00377 (*kfree)(rk); 00378 return 1; 00379 } 00380 else 00381 return 0; 00382 }
int sc_core::sc_phash_base::remove_by_contents | ( | const void * | c | ) |
sc_hash.cpp の 385 行で定義されています。
00386 { 00387 sc_phash_elem** last; 00388 sc_phash_elem* ptr; 00389 00390 int num_removed = 0; 00391 for (int i = 0; i < num_bins; ++i) { 00392 last = &(bins[i]); 00393 ptr = *last; 00394 while (ptr != 0) { 00395 if (ptr->contents != c) { 00396 last = &(ptr->next); 00397 ptr = *last; 00398 } 00399 else { 00400 *last = ptr->next; 00401 delete ptr; 00402 ptr = *last; 00403 --num_entries; 00404 ++num_removed; 00405 } 00406 } 00407 } 00408 return num_removed; 00409 }
int sc_core::sc_phash_base::remove_by_contents | ( | bool(*)(const void *, void *) | predicate, | |
void * | arg | |||
) |
int sc_core::sc_phash_base::remove_by_contents | ( | const void * | c, | |
void(*)(void *) | kfree | |||
) |
sc_core::sc_phash< K, C >, と sc_core::sc_phash< const const sc_core::sc_process_b *, T * >で再定義されています。
sc_hash.cpp の 439 行で定義されています。
00440 { 00441 sc_phash_elem** last; 00442 sc_phash_elem* ptr; 00443 00444 int num_removed = 0; 00445 for (int i = 0; i < num_bins; ++i) { 00446 last = &(bins[i]); 00447 ptr = *last; 00448 while (ptr != 0) { 00449 if (ptr->contents != c) { 00450 last = &(ptr->next); 00451 ptr = *last; 00452 } 00453 else { 00454 *last = ptr->next; 00455 (*kfree)(ptr->key); 00456 delete ptr; 00457 ptr = *last; 00458 --num_entries; 00459 ++num_removed; 00460 } 00461 } 00462 } 00463 return num_removed; 00464 }
int sc_core::sc_phash_base::remove_by_contents | ( | bool(*)(const void *, void *) | predicate, | |
void * | arg, | |||
void(*)(void *) | kfree | |||
) |
sc_core::sc_phash< K, C >, と sc_core::sc_phash< const const sc_core::sc_process_b *, T * >で再定義されています。
sc_hash.cpp の 467 行で定義されています。
00468 { 00469 sc_phash_elem** last; 00470 sc_phash_elem* ptr; 00471 00472 int num_removed = 0; 00473 for (int i = 0; i < num_bins; ++i) { 00474 last = &(bins[i]); 00475 ptr = *last; 00476 while (ptr != 0) { 00477 if (! (*predicate)(ptr->contents, arg)) { 00478 last = &(ptr->next); 00479 ptr = *last; 00480 } 00481 else { 00482 *last = ptr->next; 00483 (*kfree)(ptr->key); 00484 delete ptr; 00485 ptr = *last; 00486 --num_entries; 00487 ++num_removed; 00488 } 00489 } 00490 } 00491 return num_removed; 00492 }
int sc_core::sc_phash_base::lookup | ( | const void * | k, | |
void ** | pc | |||
) | const |
sc_hash.cpp の 495 行で定義されています。
00496 { 00497 unsigned hash_val = do_hash(k); 00498 sc_phash_elem* ptr = find_entry( hash_val, k ); 00499 if (ptr == 0) { 00500 if (c_ptr != 0) *c_ptr = default_value; 00501 return 0; 00502 } 00503 else { 00504 if (c_ptr != 0) *c_ptr = ptr->contents; 00505 return 1; 00506 } 00507 }
bool sc_core::sc_phash_base::contains | ( | const void * | k | ) | const [inline] |
void * sc_core::sc_phash_base::operator[] | ( | const void * | key | ) | const |
sc_hash.cpp の 510 行で定義されています。
00511 { 00512 void* contents; 00513 lookup( key, &contents ); 00514 return contents; 00515 }
friend class sc_phash_base_iter [friend] |
void* sc_core::sc_phash_base::default_value [protected] |
int sc_core::sc_phash_base::num_bins [protected] |
int sc_core::sc_phash_base::num_entries [protected] |
int sc_core::sc_phash_base::max_density [protected] |
int sc_core::sc_phash_base::reorder_flag [protected] |
double sc_core::sc_phash_base::grow_factor [protected] |
sc_phash_elem** sc_core::sc_phash_base::bins [protected] |
hash_fn_t sc_core::sc_phash_base::hash [protected] |
cmpr_fn_t sc_core::sc_phash_base::cmpr [protected] |