All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.openhft.chronicle.hash.hashing.Accesses Maven / Gradle / Ivy

/*
 *     Copyright (C) 2015  higherfrequencytrading.com
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 *
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with this program.  If not, see .
 */

package net.openhft.chronicle.hash.hashing;

import net.openhft.lang.io.Bytes;

import java.nio.ByteBuffer;

/**
 * Static methods returning useful {@link Access} implementations.
 */
public final class Accesses {

    private Accesses() {
    }

    /**
     * Returns the {@code Access} delegating {@code getXXX(input, offset)} methods to {@code
     * sun.misc.Unsafe.getXXX(input, offset)}.
     * 

*

Usage example:

{@code
     * class Pair {
     *     long first, second;
     * 

* static final long pairDataOffset = * theUnsafe.objectFieldOffset(Pair.class.getDeclaredField("first")); *

* static long hashPair(Pair pair, LongHashFunction hashFunction) { * return hashFunction.hash(pair, Accesses.unsafe(), pairDataOffset, 16L); * } * }}

*

*

{@code null} is a valid input, on accepting {@code null} {@code Unsafe} just interprets * the given offset as a wild memory address. * * @param the type of objects to access * @return the unsafe memory {@code Access} */ public static Access unsafe() { return (Access) UnsafeAccess.INSTANCE; } /** * Returns the {@code Access} to any {@link ByteBuffer}. * * @return the {@code Access} to {@link ByteBuffer}s */ public static Access toByteBuffer() { return ByteBufferAccess.INSTANCE; } public static Access toBytes() { return BytesAccess.INSTANCE; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy