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

E47891-01

coherence/util/Hashtable.hpp

00001 /*
00002 * Hashtable.hpp
00003 *
00004 * Copyright (c) 2000, 2014, 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.3F,
00079                   float32_t flGrowthRate = 3.0F);
00080 
00081         /**
00082         * Copy constructor.
00083         */
00084         Hashtable(const Hashtable& that);
00085 
00086 
00087     // ----- Map interface --------------------------------------------------
00088 
00089     public:
00090         /**
00091         * {@inheritDoc}
00092         */
00093         virtual size32_t size() const;
00094 
00095         /**
00096         * {@inheritDoc}
00097         */
00098         virtual bool containsKey(Object::View vKey) const;
00099 
00100         /**
00101         * {@inheritDoc}
00102         */
00103         virtual Object::Holder get(Object::View vKey) const;
00104 
00105         using Map::get;
00106 
00107         /**
00108         * {@inheritDoc}
00109         */
00110         virtual Object::Holder put(Object::View vKey, Object::Holder ohValue);
00111 
00112         /**
00113         * {@inheritDoc}
00114         */
00115         virtual void putAll(Map::View vMap);
00116 
00117         /**
00118         * {@inheritDoc}
00119         */
00120         virtual Object::Holder remove(Object::View vKey);
00121 
00122         /**
00123         * {@inheritDoc}
00124         */
00125         virtual void clear();
00126 
00127         /**
00128         * {@inheritDoc}
00129         */
00130         virtual Set::View entrySet() const;
00131 
00132         /**
00133         * {@inheritDoc}
00134         */
00135         virtual Set::Handle entrySet();
00136 
00137 
00138     // ----- data members ---------------------------------------------------
00139 
00140     private:
00141         /**
00142         * The underlying storage.
00143         */
00144         FinalHandle<Map> f_hMapStorage;
00145 
00146         /**
00147         * The underlying storage's entry set.
00148         */
00149         FinalHandle<Set> f_hSetStorage;
00150     };
00151 
00152 COH_CLOSE_NAMESPACE2
00153 
00154 #endif // COH_HASHTABLE_HPP
Copyright © 2000, 2014, Oracle and/or its affiliates. All rights reserved.