C++ Client API Reference for Oracle Coherence
14c (14.1.2.0.0)

F79659-03

coherence/util/Hashtable.hpp

00001 /*
00002  * Copyright (c) 2000, 2020, Oracle and/or its affiliates.
00003  *
00004  * Licensed under the Universal Permissive License v 1.0 as shown at
00005  * http://oss.oracle.com/licenses/upl.
00006  */
00007 #ifndef COH_HASHTABLE_HPP
00008 #define COH_HASHTABLE_HPP
00009 
00010 #include "coherence/lang.ns"
00011 
00012 #include "coherence/util/AbstractMap.hpp"
00013 #include "coherence/util/Collection.hpp"
00014 #include "coherence/util/Iterator.hpp"
00015 #include "coherence/util/Map.hpp"
00016 #include "coherence/util/Muterator.hpp"
00017 #include "coherence/util/Set.hpp"
00018 
00019 
00020 COH_OPEN_NAMESPACE2(coherence,util)
00021 
00022 /**
00023 * An implementation of coherence::util::Map that is thread-safe, but unlike
00024 * SafeHashMap does not attempt to provide stable iteration in the presence
00025 * of concurrent modifications.  Hashtable is an open-addressing based hash
00026 * map implementation, relying on an array of pre-allocated entry structures.
00027 * This approach significantly reduces the cost of insertion into the map as
00028 * there is no Entry allocation required except as part of rehashing.  This
00029 * optimization makes it an good candidate for short lived maps.
00030 *
00031 * Though thread-safe Hashtable is optimized for single-threaded access, and
00032 * assumes that in most cases escape-analysis will elide the synchronization.
00033 * If the Map will be accessed concurrently by many threads it is likely that
00034 * SafeHashMap would be a better choice.  If the Map will largely live on a
00035 * single thread, or be short lived then Hashtable is a good choice.
00036 *
00037 * Note: Hashtable's entryset iterator returns Map::Entry objects which are
00038 * only valid until the iterator is advanced.  If the Entry needs to be
00039 * retained longer then it should either be cloned or an shallow copy should
00040 * be created.
00041 *
00042 * @author mf  2009.01.23
00043 *
00044 * @since Coherence 3.5
00045 */
00046 class COH_EXPORT Hashtable
00047     : public cloneable_spec<Hashtable,
00048         extends<AbstractMap> >
00049     {
00050     friend class factory<Hashtable>;
00051 
00052     // ----- constructors ---------------------------------------------------
00053 
00054     protected:
00055         /**
00056         * Construct a thread-safe hash map using the specified settings.
00057         *
00058         * @param cEstimate        the anticipated number of elements that will
00059         *                         be stored
00060         * @param flLoadFactor     the acceptable load factor before resizing
00061         *                         occurs, 0 &lt; n, such that a load factor
00062         *                         of 1.0 causes resizing when the number of
00063         *                         entries exceeds the number of buckets
00064         * @param flGrowthRate     the rate of bucket growth when a resize
00065         *                         occurs, 0 &lt; n, such that a growth rate
00066         *                         of 1.0 will double the number of buckets:
00067         *                         bucketcount = bucketcount * (1 + growthrate)
00068         */
00069         Hashtable(size32_t cEstimate = 17, float32_t flLoadFactor = 0.75F,
00070                   float32_t flGrowthRate = 3.0F);
00071 
00072         /**
00073         * Constructs a new hash map with the same mappings as the specified Map.
00074         * The HashMap is created with default load factor (0.75) and an initial
00075         * capacity sufficient to hold the mappings in the specified Map.
00076         *
00077         * @param vMap  the map whose mappings are to be placed in this map
00078         *
00079         * @since 12.2.1
00080         */
00081         Hashtable(Map::View vMap);
00082 
00083         /**
00084         * Copy constructor.
00085         */
00086         Hashtable(const Hashtable& that);
00087 
00088 
00089     // ----- Map interface --------------------------------------------------
00090 
00091     public:
00092         /**
00093         * {@inheritDoc}
00094         */
00095         virtual size32_t size() const;
00096 
00097         /**
00098         * {@inheritDoc}
00099         */
00100         virtual bool containsKey(Object::View vKey) const;
00101 
00102         /**
00103         * {@inheritDoc}
00104         */
00105         virtual Object::Holder get(Object::View vKey) const;
00106 
00107         using Map::get;
00108 
00109         /**
00110         * {@inheritDoc}
00111         */
00112         virtual Object::Holder put(Object::View vKey, Object::Holder ohValue);
00113 
00114         /**
00115         * {@inheritDoc}
00116         */
00117         virtual void putAll(Map::View vMap);
00118 
00119         /**
00120         * {@inheritDoc}
00121         */
00122         virtual Object::Holder remove(Object::View vKey);
00123         using Map::remove;
00124 
00125         /**
00126         * {@inheritDoc}
00127         */
00128         virtual void clear();
00129 
00130         /**
00131         * {@inheritDoc}
00132         */
00133         virtual Set::View entrySet() const;
00134 
00135         /**
00136         * {@inheritDoc}
00137         */
00138         virtual Set::Handle entrySet();
00139 
00140 
00141     // ----- data members ---------------------------------------------------
00142 
00143     private:
00144         /**
00145         * The underlying storage.
00146         */
00147         FinalHandle<Map> f_hMapStorage;
00148 
00149         /**
00150         * The underlying storage's entry set.
00151         */
00152         FinalHandle<Set> f_hSetStorage;
00153     };
00154 
00155 COH_CLOSE_NAMESPACE2
00156 
00157 #endif // COH_HASHTABLE_HPP
Copyright © 2000, 2025, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.