WeakHashMap Class Reference

#include <coherence/util/WeakHashMap.hpp>

Inherits SafeHashMap.

List of all members.


Detailed Description

WeakHashMap is a HashMap implementation based on weak keys.

That is the use an object as a key in the map will not prevent it from being destroyed if all other non-weak references to it are released.

The time at which the entry associated with the weak key is cleaned up is not guaranteed, it may live in the map for some time. While it is not safe to assume that the map will shrink to its absolute minimum at any point, it is safe to assume that given constant random key insertions the size of the map will initially grow and then stabilize as the keys are reclaimed.

Note: Itereating the entries may yield entries with reclaimed (NULL) keys.

Author:
mf 2008.05.27

Public Types

typedef spec::Handle Handle
 WeakHashMap Handle definition.
typedef spec::View View
 WeakHashMap View definition.
typedef spec::Holder Holder
 WeakHashMap Holder definition.

Protected Member Functions

 WeakHashMap (size32_t cInitialBuckets=17, float32_t flLoadFactor=1.0F, float32_t flGrowthRate=3.0F)
 Construct a thread-safe weak hash map using the specified settings.
 WeakHashMap (const WeakHashMap &that)
 Copy constructor.
virtual
SafeHashMap::Entry::Handle 
instantiateEntry (Object::View vKey, Object::Holder ohValue, size32_t nHash)
 Factory pattern, initialized with the specified valued.

Parameters:
vKey the associated key
ohValue the assocaited value
nHash the associated hash code
Returns:
a new instance of the Entry class (or a subclass thereof)

virtual
SafeHashMap::Entry::Handle 
instantiateEntry (SafeHashMap::Entry::View vThat)
 Factory pattern, instantiate an Entry that is either a deep or shalow copy.

Parameters:
vEntry the Entry to copy
fDeep whether to make a deep copy of the Entry or not

virtual void grow ()
 Resize the bucket array, rehashing all Entries.
virtual size32_t shrink (size32_t iBucket, size32_t cEntries)
 Shrink the specified bucket.

Classes

class  Entry
 A map entry (key-value pair). More...

Constructor & Destructor Documentation

WeakHashMap ( size32_t  cInitialBuckets = 17,
float32_t  flLoadFactor = 1.0F,
float32_t  flGrowthRate = 3.0F 
) [protected]

Construct a thread-safe weak hash map using the specified settings.

Parameters:
cInitialBuckets the initial number of hash buckets, 0 < n
flLoadFactor the acceptable load factor before resizing occurs, 0 < n, such that a load factor of 1.0 causes resizing when the number of entries exceeds the number of buckets
flGrowthRate the rate of bucket growth when a resize occurs, 0 < n, such that a growth rate of 1.0 will double the number of buckets: bucketcount = bucketcount * (1 + growthrate)


Member Function Documentation

virtual size32_t shrink ( size32_t  iBucket,
size32_t  cEntries 
) [protected, virtual]

Shrink the specified bucket.

Parameters:
iBucket the bucket to shrink
cEntries the maximum number of entries to shrink by
Returns:
the number of entries removed


The documentation for this class was generated from the following file: Copyright (c) 2000-2008 Oracle. All rights reserved.