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.
fastutil extends the Java Collections Framework by providing type-specific maps, sets, lists, and queues with a small memory footprint and fast operations; it provides also big (64-bit) arrays, sets, and lists, sorting algorithms, fast, practical I/O classes for binary and text files, and facilities for memory mapping large files. This jar (fastutil-core.jar) contains data structures based on integers, longs, doubles, and objects, only; fastutil.jar contains all classes. If you have both jars in your dependencies, this jar should be excluded.
/*
* Copyright (C) 2002-2022 Sebastiano Vigna
*
* 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 it.unimi.dsi.fastutil.objects;
import static it.unimi.dsi.fastutil.BigArrays.copy;
import static it.unimi.dsi.fastutil.BigArrays.fill;
import static it.unimi.dsi.fastutil.BigArrays.set;
import it.unimi.dsi.fastutil.BigArrays;
import it.unimi.dsi.fastutil.Hash;
import it.unimi.dsi.fastutil.Size64;
import it.unimi.dsi.fastutil.HashCommon;
import static it.unimi.dsi.fastutil.HashCommon.bigArraySize;
import static it.unimi.dsi.fastutil.HashCommon.maxFill;
import java.util.function.Consumer;
import java.util.stream.Collector;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* A type-specific hash big set with with a fast, small-footprint implementation.
*
*
* Instances of this class use a hash table to represent a big set: the number of elements in the
* set is limited only by the amount of core memory. The table (backed by a
* {@linkplain it.unimi.dsi.fastutil.BigArrays big array}) is filled up to a specified load
* factor, and then doubled in size to accommodate new entries. If the table is emptied below
* one fourth of the load factor, it is halved in size; however, the table is never reduced
* to a size smaller than that at creation time: this approach makes it possible to create sets with
* a large capacity in which insertions and deletions do not cause immediately rehashing. Moreover,
* halving is not performed when deleting entries from an iterator, as it would interfere with the
* iteration process.
*
*
* Note that {@link #clear()} does not modify the hash table size. Rather, a family of
* {@linkplain #trim() trimming methods} lets you control the size of the table; this is
* particularly useful if you reuse instances of this class.
*
*
* The methods of this class are about 30% slower than those of the corresponding non-big set.
*
* @see Hash
* @see HashCommon
*/
public class ObjectOpenHashBigSet extends AbstractObjectSet implements java.io.Serializable, Cloneable, Hash, Size64 {
private static final long serialVersionUID = 0L;
private static final boolean ASSERTS = false;
/** The big array of keys. */
protected transient K[][] key;
/** The mask for wrapping a position counter. */
protected transient long mask;
/** The mask for wrapping a segment counter. */
protected transient int segmentMask;
/** The mask for wrapping a base counter. */
protected transient int baseMask;
/** Whether this set contains the null key. */
protected transient boolean containsNull;
/** The current table size (always a power of 2). */
protected transient long n;
/** Threshold after which we rehash. It must be the table size times {@link #f}. */
protected transient long maxFill;
/** We never resize below this threshold, which is the construction-time {#n}. */
protected final transient long minN;
/** The acceptable load factor. */
protected final float f;
/** Number of entries in the set. */
protected long size;
/** Initialises the mask values. */
private void initMasks() {
mask = n - 1;
/* Note that either we have more than one segment, and in this case all segments
* are BigArrays.SEGMENT_SIZE long, or we have exactly one segment whose length
* is a power of two. */
segmentMask = key[0].length - 1;
baseMask = key.length - 1;
}
/**
* Creates a new hash big set.
*
*
* 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 set.
* @param f the load factor.
*/
@SuppressWarnings("unchecked")
public ObjectOpenHashBigSet(final long expected, final float f) {
if (f <= 0 || f > 1) throw new IllegalArgumentException("Load factor must be greater than 0 and smaller than or equal to 1");
if (n < 0) throw new IllegalArgumentException("The expected number of elements must be nonnegative");
this.f = f;
minN = n = bigArraySize(expected, f);
maxFill = maxFill(n, f);
key = (K[][])ObjectBigArrays.newBigArray(n);
initMasks();
}
/**
* Creates a new hash big set with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor.
*
* @param expected the expected number of elements in the hash big set.
*/
public ObjectOpenHashBigSet(final long expected) {
this(expected, DEFAULT_LOAD_FACTOR);
}
/**
* Creates a new hash big set with initial expected {@link Hash#DEFAULT_INITIAL_SIZE} elements and
* {@link Hash#DEFAULT_LOAD_FACTOR} as load factor.
*/
public ObjectOpenHashBigSet() {
this(DEFAULT_INITIAL_SIZE, DEFAULT_LOAD_FACTOR);
}
/**
* Creates a new hash big set copying a given collection.
*
* @param c a {@link Collection} to be copied into the new hash big set.
* @param f the load factor.
*/
public ObjectOpenHashBigSet(final Collection extends K> c, final float f) {
this(Size64.sizeOf(c), f);
addAll(c);
}
/**
* Creates a new hash big set with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor copying a given
* collection.
*
* @param c a {@link Collection} to be copied into the new hash big set.
*/
public ObjectOpenHashBigSet(final Collection extends K> c) {
this(c, DEFAULT_LOAD_FACTOR);
}
/**
* Creates a new hash big set copying a given type-specific collection.
*
* @param c a type-specific collection to be copied into the new hash big set.
* @param f the load factor.
*/
public ObjectOpenHashBigSet(final ObjectCollection extends K> c, final float f) {
this(Size64.sizeOf(c), f);
addAll(c);
}
/**
* Creates a new hash big set with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor copying a given
* type-specific collection.
*
* @param c a type-specific collection to be copied into the new hash big set.
*/
public ObjectOpenHashBigSet(final ObjectCollection extends K> c) {
this(c, DEFAULT_LOAD_FACTOR);
}
/**
* Creates a new hash big set using elements provided by a type-specific iterator.
*
* @param i a type-specific iterator whose elements will fill the new hash big set.
* @param f the load factor.
*/
public ObjectOpenHashBigSet(final Iterator extends K> i, final float f) {
this(DEFAULT_INITIAL_SIZE, f);
while (i.hasNext()) add(i.next());
}
/**
* Creates a new hash big set with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor using elements
* provided by a type-specific iterator.
*
* @param i a type-specific iterator whose elements will fill the new hash big set.
*/
public ObjectOpenHashBigSet(final Iterator extends K> i) {
this(i, DEFAULT_LOAD_FACTOR);
}
/**
* Creates a new hash big set and fills it with the elements of a given array.
*
* @param a an array whose elements will be used to fill the new hash big set.
* @param offset the first element to use.
* @param length the number of elements to use.
* @param f the load factor.
*/
public ObjectOpenHashBigSet(final K[] a, final int offset, final int length, final float f) {
this(length < 0 ? 0 : length, f);
ObjectArrays.ensureOffsetLength(a, offset, length);
for (int i = 0; i < length; i++) add(a[offset + i]);
}
/**
* Creates a new hash big set with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor and fills it with
* the elements of a given array.
*
* @param a an array whose elements will be used to fill the new hash big set.
* @param offset the first element to use.
* @param length the number of elements to use.
*/
public ObjectOpenHashBigSet(final K[] a, final int offset, final int length) {
this(a, offset, length, DEFAULT_LOAD_FACTOR);
}
/**
* Creates a new hash big set copying the elements of an array.
*
* @param a an array to be copied into the new hash big set.
* @param f the load factor.
*/
public ObjectOpenHashBigSet(final K[] a, final float f) {
this(a, 0, a.length, f);
}
/**
* Creates a new hash big set with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor copying the
* elements of an array.
*
* @param a an array to be copied into the new hash big set.
*/
public ObjectOpenHashBigSet(final K[] a) {
this(a, DEFAULT_LOAD_FACTOR);
}
// Collector wants a function that returns the collection being added to.
private ObjectOpenHashBigSet combine(ObjectOpenHashBigSet extends K> toAddFrom) {
addAll(toAddFrom);
return this;
}
private static final Collector