dschneider-pivotal commented on a change in pull request #6768: URL: https://github.com/apache/geode/pull/6768#discussion_r697731828
########## File path: geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/collections/Bytes2ObjectOpenHashMap.java ########## @@ -0,0 +1,1230 @@ +/* + * 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.geode.redis.internal.collections; + +import static it.unimi.dsi.fastutil.HashCommon.arraySize; +import static it.unimi.dsi.fastutil.HashCommon.maxFill; + +import java.util.Arrays; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.function.Consumer; +import java.util.function.Predicate; + +import it.unimi.dsi.fastutil.Hash; +import it.unimi.dsi.fastutil.HashCommon; +import it.unimi.dsi.fastutil.Pair; +import it.unimi.dsi.fastutil.bytes.ByteArrays; +import it.unimi.dsi.fastutil.objects.AbstractObject2ObjectMap; +import it.unimi.dsi.fastutil.objects.AbstractObjectCollection; +import it.unimi.dsi.fastutil.objects.AbstractObjectSet; +import it.unimi.dsi.fastutil.objects.Object2ObjectMap; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import it.unimi.dsi.fastutil.objects.ObjectCollection; +import it.unimi.dsi.fastutil.objects.ObjectIterator; +import it.unimi.dsi.fastutil.objects.ObjectSet; +import it.unimi.dsi.fastutil.objects.ObjectSpliterator; +import it.unimi.dsi.fastutil.objects.ObjectSpliterators; + +/** + * This class was derived from Object2ObjectOpenCustomHashMap. + * The differences are: + * 1. the keys are always a byte[] so no need for "strategy" field + * 2. the load factory is always the default so no need for the "f" field. + * 3. no support for the "null" key so no need for the boolean field that signifies a null key + * exists + * 4. the fields that cache a singleton instance for entrySet, keySet, and values + * no longer exist. + */ +public class Bytes2ObjectOpenHashMap<V> extends AbstractObject2ObjectMap<byte[], V> + implements java.io.Serializable, Cloneable, Hash { + private static final Strategy<byte[]> strategy = ByteArrays.HASH_STRATEGY; + private static final long serialVersionUID = 0L; + private static final boolean ASSERTS = false; + /** The array of keys. */ + protected transient byte[][] key; + /** The array of values. */ + protected transient V[] value; + /** The mask for wrapping a position counter. */ + protected transient int mask; + /** The current table size. */ + protected transient int n; + /** Threshold after which we rehash. It must be the table size times load factor. */ + protected transient int maxFill; + /** We never resize below this threshold, which is the construction-time {#n}. */ + protected final transient int minN; + /** Number of entries in the set */ + protected int size; + + /** + * Creates a new hash map. + * + * <p> + * The actual table size will be the least power of two greater than {@code expected}/{@code f}. + * + * @param expected the expected number of elements in the hash map. + */ + @SuppressWarnings("unchecked") + public Bytes2ObjectOpenHashMap(final int expected) { + if (expected < 0) + throw new IllegalArgumentException("The expected number of elements must be non-negative"); + minN = n = arraySize(expected, getLoadFactor()); + mask = n - 1; + maxFill = maxFill(n, getLoadFactor()); + key = new byte[n + 1][]; + value = (V[]) new Object[n + 1]; + } + + /** + * Creates a new hash map with initial expected {@link Hash#DEFAULT_INITIAL_SIZE} entries + * and {@link Hash#DEFAULT_LOAD_FACTOR} as load factor. + */ + public Bytes2ObjectOpenHashMap() { + this(DEFAULT_INITIAL_SIZE); + } + + /** + * Creates a new hash map with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor copying a given + * one. + * + * @param m a {@link Map} to be copied into the new hash map. + */ + public Bytes2ObjectOpenHashMap(final Map<byte[], ? extends V> m) { + this(m.size()); + putAll(m); + } + + /** + * Returns the hashing strategy. + * + * @return the hashing strategy of this custom hash map. + */ + public Strategy<byte[]> strategy() { + return strategy; + } + + private int realSize() { + return size; + } Review comment: yes -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
