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

E90870-01

coherence/util/HashHelper.hpp

00001 /*
00002 * HashHelper.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_HASH_HELPER_HPP
00017 #define COH_HASH_HELPER_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/util/Collection.hpp"
00022 
00023 COH_OPEN_NAMESPACE2(coherence, util)
00024 
00025 using coherence::util::Collection;
00026 
00027 /**
00028 * This abstract class contains helper functions for calculating hash code
00029 * values for any group of C++ intrinsics.
00030 *
00031 * @author hr 2011.08.30
00032 *
00033 * @since Coherence 12.1.2
00034 */
00035 class COH_EXPORT HashHelper
00036     : public abstract_spec<HashHelper,
00037         extends<Object> >
00038     {
00039     // ----- static functions -----------------------------------------------
00040 
00041     public:
00042         /**
00043         * Calculate a running hash using the boolean value.
00044         *
00045         * @param fValue  the boolean value for use in the hash
00046         * @param nHash   the running hash value
00047         *
00048         * @return the resulting running hash value
00049         */
00050         static size32_t hash(bool fValue, size32_t nHash);
00051 
00052         /**
00053         * Calculate a running hash using the octet_t value.
00054         *
00055         * @param bValue  the octet_t value for use in the hash
00056         * @param nHash   the running hash value
00057         *
00058         * @return the resulting running hash value
00059         */
00060         static size32_t hash(octet_t bValue, size32_t nHash);
00061 
00062         /**
00063         * Calculate a running hash using the wchar16_t value.
00064         *
00065         * @param chValue  the wchar16_t value for use in the hash
00066         * @param nHash    the running hash value
00067         *
00068         * @return the resulting running hash value
00069         */
00070         static size32_t hash(wchar16_t chValue, size32_t nHash);
00071 
00072         /**
00073         * Calculate a running hash using the float64_t value.
00074         *
00075         * @param dflValue  the float64_t value for use in the hash
00076         * @param nHash     the running hash value
00077         *
00078         * @return the resulting running hash value
00079         */
00080         static size32_t hash(float64_t dflValue, size32_t nHash);
00081 
00082         /**
00083         * Calculate a running hash using the float32_t value.
00084         *
00085         * @param flValue  the float32_t value for use in the hash
00086         * @param nHash    the running hash value
00087         *
00088         * @return the resulting running hash value
00089         */
00090         static size32_t hash(float32_t flValue, size32_t nHash);
00091 
00092         /**
00093         * Calculate a running hash using the int32_t value.
00094         *
00095         * @param nValue  the int32_t value for use in the hash
00096         * @param nHash   the running hash value
00097         *
00098         * @return the resulting running hash value
00099         */
00100         static size32_t hash(int32_t nValue, size32_t nHash);
00101 
00102         /**
00103         * Calculate a running hash using the int64_t value.
00104         *
00105         * @param nValue  the int64_t value for use in the hash
00106         * @param nHash   the running hash value
00107         *
00108         * @return the resulting running hash value
00109         */
00110         static size32_t hash(int64_t lValue, size32_t nHash);
00111 
00112         /**
00113         * Calculate a running hash using the size32_t value.
00114         *
00115         * @param nValue  the size32_t value for use in the hash
00116         * @param nHash   the running hash value
00117         *
00118         * @return the resulting running hash value
00119         */
00120         static size32_t hash(size32_t nValue, size32_t nHash);
00121 
00122         /**
00123         * Calculate a running hash using the size64_t value.
00124         *
00125         * @param lValue  the size64_t value for use in the hash
00126         * @param nHash   the running hash value
00127         *
00128         * @return the resulting running hash value
00129         */
00130         static size32_t hash(size64_t lValue, size32_t nHash);
00131 
00132         /**
00133         * Calculate a running hash using the int16_t value.
00134         *
00135         * @param shValue  the int16_t value for use in the hash
00136         * @param nHash    the running hash value
00137         *
00138         * @return the resulting running hash value
00139         */
00140         static size32_t hash(int16_t shValue, size32_t nHash);
00141 
00142         /**
00143         * Calculate a running hash using the Object value.
00144         *
00145         * @param vValue  the Object value for use in the hash
00146         * @param nHash    the running hash value
00147         *
00148         * @return the resulting running hash value
00149         */
00150         static size32_t hash(Object::View vValue, size32_t nHash);
00151 
00152         /**
00153         * Calculate a running hash using the array delegating to the
00154         * runtime type for each element.
00155         *
00156         * @param ha     the array for use in the hash
00157         * @param nHash  the running hash value
00158         *
00159         * @return the resulting running hash value
00160         */
00161         template<class T> static size32_t
00162             hash(const TypedHandle<Array<T> >& ha, size32_t nHash)
00163             {
00164             nHash = swizzle(nHash);
00165             if (NULL == ha)
00166                 {
00167                 return nHash;
00168                 }
00169 
00170             for (size32_t i = 0; i < ha->length; ++i)
00171                 {
00172                 nHash = hash((*ha)[i], nHash);
00173                 }
00174             return nHash;
00175             }
00176 
00177         /**
00178         * Calculate a running hash using the ObjectArray value.
00179         *
00180         * @param avValue  the ObjectArray value for use in the hash
00181         * @param nHash    the running hash value
00182         *
00183         * @return the resulting running hash value
00184         */
00185         static size32_t hash(ObjectArray::View avValue, size32_t nHash);
00186 
00187         /**
00188         * Calculate a running hash using the Collection value.
00189         *
00190         * @param vCol  the Collection value for use in the hash
00191         * @param nHash the running hash value
00192         *
00193         * @return the resulting running hash value
00194         */
00195         static size32_t hash(Collection::View vCol, size32_t nHash);
00196 
00197     // ----- helpers --------------------------------------------------------
00198 
00199     protected:
00200         /**
00201         * Shift the running hash value to try and help with
00202         * generating unique values given the same input, but
00203         * in a different order.
00204         *
00205         * @param nHash  the running hash value
00206         *
00207         * @return the resulting running hash value
00208         */
00209         static size32_t swizzle(size32_t nHash);
00210     };
00211 
00212 COH_CLOSE_NAMESPACE2
00213 
00214 #endif // COH_HASH_HELPER_HPP
Copyright © 2000, 2019, Oracle and/or its affiliates. All rights reserved.