1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * https://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.commons.codec.digest; 19 20 /** 21 * Commons implementation methods for MurmurHash* classes in this package. 22 */ 23 final class MurmurHash { 24 25 /** 26 * Gets the little-endian int from 4 bytes starting at the specified index. 27 * 28 * @param data The data 29 * @param index The index 30 * @return The little-endian int 31 */ 32 static int getLittleEndianInt(final byte[] data, final int index) { 33 // @formatter:off 34 return data[index ] & 0xff | 35 (data[index + 1] & 0xff) << 8 | 36 (data[index + 2] & 0xff) << 16 | 37 (data[index + 3] & 0xff) << 24; 38 // @formatter:on 39 } 40 41 /** 42 * Gets the little-endian long from 8 bytes starting at the specified index. 43 * 44 * @param data The data 45 * @param index The index 46 * @return The little-endian long 47 */ 48 static long getLittleEndianLong(final byte[] data, final int index) { 49 // @formatter:off 50 return (long) data[index ] & 0xff | 51 ((long) data[index + 1] & 0xff) << 8 | 52 ((long) data[index + 2] & 0xff) << 16 | 53 ((long) data[index + 3] & 0xff) << 24 | 54 ((long) data[index + 4] & 0xff) << 32 | 55 ((long) data[index + 5] & 0xff) << 40 | 56 ((long) data[index + 6] & 0xff) << 48 | 57 ((long) data[index + 7] & 0xff) << 56; 58 // @formatter:on 59 } 60 }