Java Hash Code Calculate hashCode(final long l)

Here you can find the source of hashCode(final long l)

Description

hash Code

License

Apache License

Declaration

public static int hashCode(final long l) 

Method Source Code

//package com.java2s;
/*/*  w ww.j  a  va  2 s  .c o m*/
 * @(#)$Id$$
 *
 * Copyright 2006-2008 Makoto YUI
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Contributors:
 *     Makoto YUI - initial implementation
 */

public class Main {
    public static int hashCode(final long l) {
        return (int) (l ^ (l >>> 32));
    }

    public static int hashCode(final char[] ch, final int offset, final int length) {
        if (ch == null) {
            return 0;
        }
        int result = 1;
        final int limit = offset + length;
        for (int i = offset; i < limit; i++) {
            result = 31 * result + ch[i];
        }
        return result;
    }

    public static int hashCode(final byte[] b) {
        return hashCode(b, 0, b.length);
    }

    public static int hashCode(final byte[] b, final int offset, final int length) {
        if (b == null) {
            return 0;
        }
        int result = 1;
        final int limit = offset + length;
        for (int i = offset; i < limit; i++) {
            result = 31 * result + b[i];
        }
        return result;
    }
}

Related

  1. hashCode(final int i)
  2. hashCode(final int seed, final int hashcode)
  3. hashCode(final int x, final int y)
  4. hashcode(final int[] array)
  5. hashCode(final long l)
  6. hashCode(final long v)
  7. hashCode(final Object obj)
  8. hashCode(final Object obj)
  9. hashCode(final Object object)