Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.hadoop.mapred;
import java.lang.reflect.Field;
import java.nio.ByteOrder;
import java.security.AccessController;
import java.security.PrivilegedAction;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import sun.misc.Unsafe;
/**
* this is borrowed from
* http://guava-libraries.googlecode.com/svn/trunk/guava/src
* /com/google/common/primitives/UnsignedBytes.java
* and
* http://svn.apache.org/viewvc
* /hbase/trunk/src/main/java/org/apache/hadoop/hbase
* /util/Bytes.java?view=markup
*
*/
public class LexicographicalComparerHolder {
private static final Log LOG = LogFactory
.getLog(LexicographicalComparerHolder.class.getName());
public static int compareBytes(byte[] kvbuffer, int offset1, int keyLen1,
int offset2, int keyLen2) {
return LexicographicalComparerHolder.BEST_COMPARER.compareTo(kvbuffer,
offset1, keyLen1, kvbuffer, offset2, keyLen2);
}
/**
* The number of bytes required to represent a primitive {@code long} value.
*/
public static final int LONG_BYTES = Long.SIZE / Byte.SIZE;
interface Comparer {
abstract public int compareTo(T buffer1, int offset1, int length1,
T buffer2, int offset2, int length2);
}
static Comparer lexicographicalComparerJavaImpl() {
return LexicographicalComparerHolder.PureJavaComparer.INSTANCE;
}
static final String UNSAFE_COMPARER_NAME = LexicographicalComparerHolder.class
.getName()
+ "$UnsafeComparer";
static final Comparer BEST_COMPARER = getBestComparer();
/**
* Returns the Unsafe-using Comparer, or falls back to the pure-Java
* implementation if unable to do so.
*/
static Comparer getBestComparer() {
try {
Class> theClass = Class.forName(UNSAFE_COMPARER_NAME);
// yes, UnsafeComparer does implement Comparer
@SuppressWarnings("unchecked")
Comparer comparer = (Comparer) theClass
.getEnumConstants()[0];
return comparer;
} catch (Throwable t) { // ensure we really catch *everything*
LOG.error("Loading lexicographicalComparerJavaImpl...");
return lexicographicalComparerJavaImpl();
}
}
enum UnsafeComparer implements Comparer {
INSTANCE;
static final Unsafe theUnsafe;
/** The offset to the first element in a byte array. */
static final int BYTE_ARRAY_BASE_OFFSET;
static {
theUnsafe = (Unsafe) AccessController
.doPrivileged(new PrivilegedAction