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

net.openhft.collect.impl.hash.QHash Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2014 the original author or authors.
 *
 * 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.
 */

package net.openhft.collect.impl.hash;

import static net.openhft.collect.impl.hash.LHash.*;


public interface QHash extends Hash {

    static class SeparateKVByteKeyMixing {
        static int mix(byte key) {
            return (key * INT_PHI_MAGIC) & Integer.MAX_VALUE;
        }
    }
    static class SeparateKVCharKeyMixing {
        static int mix(char key) {
            return (key * INT_PHI_MAGIC) & Integer.MAX_VALUE;
        }
    }
    static class SeparateKVShortKeyMixing {
        static int mix(short key) {
            return (key * INT_PHI_MAGIC) & Integer.MAX_VALUE;
        }
    }
    static class SeparateKVIntKeyMixing {
        static int mix(int key) {
            return (key * INT_PHI_MAGIC) & Integer.MAX_VALUE;
        }
    }
    static class SeparateKVFloatKeyMixing {
        static int mix(int key) {
            return (key * INT_PHI_MAGIC) & Integer.MAX_VALUE;
        }
    }

    static class SeparateKVDoubleKeyMixing {
        static int mix(long key) {
            long h = key * LONG_PHI_MAGIC;
            h ^= h >> 32;
            return ((int) h) & Integer.MAX_VALUE;
        }
    }
    static class SeparateKVLongKeyMixing {
        static int mix(long key) {
            long h = key * LONG_PHI_MAGIC;
            h ^= h >> 32;
            return ((int) h) & Integer.MAX_VALUE;
        }
    }

    static class SeparateKVObjKeyMixing {
        static int mix(int hash) {
            return hash & Integer.MAX_VALUE;
        }
    }


    static class ParallelKVByteKeyMixing {
        static int mix(byte key) {
            return (key * INT_PHI_MAGIC) & Integer.MAX_VALUE;
        }
    }
    static class ParallelKVCharKeyMixing {
        static int mix(char key) {
            return (key * INT_PHI_MAGIC) & Integer.MAX_VALUE;
        }
    }
    static class ParallelKVShortKeyMixing {
        static int mix(short key) {
            return (key * INT_PHI_MAGIC) & Integer.MAX_VALUE;
        }
    }
    static class ParallelKVIntKeyMixing {
        static int mix(int key) {
            return (key * INT_PHI_MAGIC) & Integer.MAX_VALUE;
        }
    }
    static class ParallelKVFloatKeyMixing {
        static int mix(int key) {
            return (key * INT_PHI_MAGIC) & Integer.MAX_VALUE;
        }
    }

    static class ParallelKVDoubleKeyMixing {
        static int mix(long key) {
            long h = key * LONG_PHI_MAGIC;
            // not to loose information about 63-64-th bits
            h ^= (h >> 40) ^ (h >> 24);
            return ((((int) h) << 2) >>> 1);
        }
    }
    static class ParallelKVLongKeyMixing {
        static int mix(long key) {
            long h = key * LONG_PHI_MAGIC;
            // not to loose information about 63-64-th bits
            h ^= (h >> 40) ^ (h >> 24);
            return ((((int) h) << 2) >>> 1);
        }
    }

    static class ParallelKVObjKeyMixing {
        static int mix(int hash) {
            return (hash << 2) >>> 1;
        }
    }

}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy