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

F79659-03

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