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 access and insertion; 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. Note that if you have both this jar and fastutil-core.jar in your dependencies, fastutil-core.jar should be excluded.
/*
* Copyright (C) 2002-2023 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 java.util.Collection;
import java.util.Iterator;
import java.util.RandomAccess;
import java.util.NoSuchElementException;
import it.unimi.dsi.fastutil.BigArrays;
import static it.unimi.dsi.fastutil.BigArrays.length;
import it.unimi.dsi.fastutil.BigList;
import it.unimi.dsi.fastutil.Size64;
import java.util.function.Consumer;
import java.util.stream.Collector;
/**
* A type-specific big-array-based big list; provides some additional methods that use polymorphism
* to avoid (un)boxing.
*
*
* This class implements a lightweight, fast, open, optimized, reuse-oriented version of
* big-array-based big lists. Instances of this class represent a big list with a big array that is
* enlarged as needed when new entries are created (by increasing its current length to 50%), but is
* never made smaller (even on a {@link #clear()}). A family of {@linkplain #trim()
* trimming methods} lets you control the size of the backing big array; this is particularly useful
* if you reuse instances of this class. Range checks are equivalent to those of {@link java.util}'s
* classes, but they are delayed as much as possible.
*
*
* The backing big array is exposed by the {@link #elements()} method. If an instance of this class
* was created {@linkplain #wrap(Object[][],long) by wrapping}, backing-array reallocations will be
* performed using reflection, so that {@link #elements()} can return a big array of the same type
* of the original big array; the comments about efficiency made in
* {@link it.unimi.dsi.fastutil.objects.ObjectArrays} apply here.
*
*
* This class implements the bulk methods {@code removeElements()}, {@code addElements()} and
* {@code getElements()} using high-performance system calls (e.g.,
* {@link System#arraycopy(Object,int,Object,int,int) System.arraycopy()}) instead of expensive
* loops.
*
* @see java.util.ArrayList
*/
public class ObjectBigArrayBigList extends AbstractObjectBigList implements RandomAccess, Cloneable, java.io.Serializable {
private static final long serialVersionUID = -7046029254386353131L;
/** The initial default capacity of a big-array big list. */
public static final int DEFAULT_INITIAL_CAPACITY = 10;
/**
* Whether the backing big array was passed to {@code wrap()}. In this case, we must reallocate with
* the same type of big array.
*/
protected final boolean wrapped;
/** The backing big array. */
protected transient K a[][];
/** The current actual size of the big list (never greater than the backing-array length). */
protected long size;
/**
* Creates a new big-array big list using a given array.
*
*
* This constructor is only meant to be used by the wrapping methods.
*
* @param a the big array that will be used to back this big-array big list.
*/
protected ObjectBigArrayBigList(final K a[][], @SuppressWarnings("unused") boolean dummy) {
this.a = a;
this.wrapped = true;
}
/**
* Creates a new big-array big list with given capacity.
*
* @param capacity the initial capacity of the array list (may be 0).
*/
@SuppressWarnings("unchecked")
public ObjectBigArrayBigList(final long capacity) {
if (capacity < 0) throw new IllegalArgumentException("Initial capacity (" + capacity + ") is negative");
if (capacity == 0) a = (K[][])ObjectBigArrays.EMPTY_BIG_ARRAY;
else a = (K[][])ObjectBigArrays.newBigArray(capacity);
wrapped = false;
}
/** Creates a new big-array big list with {@link #DEFAULT_INITIAL_CAPACITY} capacity. */
@SuppressWarnings("unchecked")
public ObjectBigArrayBigList() {
a = (K[][])ObjectBigArrays.DEFAULT_EMPTY_BIG_ARRAY; // We delay allocation
wrapped = false;
}
/**
* Creates a new big-array big list and fills it with a given type-specific collection.
*
* @param c a type-specific collection that will be used to fill the array list.
*/
public ObjectBigArrayBigList(final ObjectCollection c) {
this(Size64.sizeOf(c));
if (c instanceof ObjectBigList) {
((ObjectBigList)c).getElements(0, a, 0, size = Size64.sizeOf(c));
} else {
for (ObjectIterator i = c.iterator(); i.hasNext();) add(i.next());
}
}
/**
* Creates a new big-array big list and fills it with a given collection.
*
* @param c a collection that will be used to fill the array list.
*/
public ObjectBigArrayBigList(final Collection c) {
this(Size64.sizeOf(c));
if (c instanceof ObjectBigList) {
((ObjectBigList)c).getElements(0, a, 0, size = Size64.sizeOf(c));
} else {
for (Iterator i = c.iterator(); i.hasNext();) add(i.next());
}
}
/**
* Creates a new big-array big list and fills it with a given type-specific list.
*
* @param l a type-specific list that will be used to fill the array list.
*/
public ObjectBigArrayBigList(final ObjectBigList l) {
this(l.size64());
l.getElements(0, a, 0, size = l.size64());
}
/**
* Creates a new big-array big list and fills it with the elements of a given big array.
*
* @param a a big array whose elements will be used to fill the array list.
*/
public ObjectBigArrayBigList(final K a[][]) {
this(a, 0, length(a));
}
/**
* Creates a new big-array big list and fills it with the elements of a given big array.
*
* @param a a big array whose elements will be used to fill the array list.
* @param offset the first element to use.
* @param length the number of elements to use.
*/
public ObjectBigArrayBigList(final K a[][], final long offset, final long length) {
this(length);
BigArrays.copy(a, offset, this.a, 0, length);
size = length;
}
/**
* Creates a new big-array big list and fills it with the elements returned by an iterator..
*
* @param i an iterator whose returned elements will fill the array list.
*/
public ObjectBigArrayBigList(final Iterator i) {
this();
while (i.hasNext()) this.add((i.next()));
}
/**
* Creates a new big-array big list and fills it with the elements returned by a type-specific
* iterator..
*
* @param i a type-specific iterator whose returned elements will fill the array list.
*/
public ObjectBigArrayBigList(final ObjectIterator i) {
this();
while (i.hasNext()) this.add(i.next());
}
/**
* Returns the backing big array of this big list.
*
*
* If this big-array big list was created by wrapping a given big array, it is guaranteed that the
* type of the returned big array will be the same. Otherwise, the returned big array will be an big
* array of objects.
*
* @return the backing big array.
*/
public K[][] elements() {
return a;
}
/**
* Wraps a given big array into a big-array list of given size.
*
* @param a a big array to wrap.
* @param length the length of the resulting big-array list.
* @return a new big-array list of the given size, wrapping the given big array.
*/
public static ObjectBigArrayBigList wrap(final K a[][], final long length) {
if (length > length(a)) throw new IllegalArgumentException("The specified length (" + length + ") is greater than the array size (" + length(a) + ")");
final ObjectBigArrayBigList l = new ObjectBigArrayBigList<>(a, false);
l.size = length;
return l;
}
/**
* Wraps a given big array into a big-array big list.
*
* @param a a big array to wrap.
* @return a new big-array big list wrapping the given array.
*/
public static ObjectBigArrayBigList wrap(final K a[][]) {
return wrap(a, length(a));
}
/**
* Creates a new empty big array list.
*
* @return a new empty big-array big list.
*/
public static ObjectBigArrayBigList of() {
return new ObjectBigArrayBigList<>();
}
/**
* Creates a big array list using a list of elements.
*
* @param init a list of elements that will be used to initialize the big list. It is possible (but
* not assured) that the returned big-array big list will be backed by the given array in
* one of its segments.
* @return a new big-array big list containing the given elements.
* @see BigArrays#wrap
*/
@SafeVarargs
public static ObjectBigArrayBigList of(final K... init) {
return wrap(BigArrays.wrap(init));
}
// Collector wants a function that returns the collection being added to.
private ObjectBigArrayBigList combine(ObjectBigArrayBigList toAddFrom) {
addAll(toAddFrom);
return this;
}
private static final Collector