Oracle® Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.2.1.4.0)

E90870-01

coherence/util/Hashtable.hpp

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