Skip to content
Commits on Source (11)
8.2.2
- Fixed small bug in new lazy allocation scheme for array-based lists.
Resizing would throw an exception in certain circumstances.
- Now strategies must accept a supertype of the base type. Thanks to
shevek@github.com for suggesting this change.
- The Maven source jar does not contain tests anymore.
8.2.1
- Added default modularization to OSGi version, too.
8.2.0
- Added default modularization. Thanks to Joshua Popoff for taking care of
this issue.
- Implemented lazy allocation of arrays in array-based lists. Thanks to
Zheka Kozlov for suggesting this feature.
- Fixed a long-standing issue: the allocation of big lists based on big
arrays could not go beyond 2^31 because of a cut-and-paste bug.
- In line with the JDK, the default initial capacity for lists is 10 and
backing arrays (and, in generally, arrays) are automatically enlarged by
a 50% factor instead of a 100% factor.
- Included dependency-finding scripts by Tobias Meggendorfer.
8.1.1
- More default methods.
- Fixed lack of proper forEach()/fastForEach() method for entry sets of
linked maps (the order of iteration would be random). Thanks to Søren
Gjesse for reporting this bug.
- Fixed lack of proper licensing in test sources.
- A new NO_SMALL_TYPES makefile variable makes it possible to compile
a version of fastutil for ints, longs and doubles only. Thanks to
Tobias Meggendorfer for implementing this feature.
8.1.0
- WARNING: backward-incompatible name change for a few "compute"
methods.
- Implemented efficient new map methods and new iterable methods
in hash-based maps.
- A number of minor glitches has been fixed.
- FastIterable now has a fastForEach() method.
- Fixed ancient bug in the remove() method of entry sets of
tree-based maps.
- Array-based maps have a working key set and value collection.
8.0.0
- First release for Java 8 only, with implementation of new default
methods for iterators and maps. Thanks to Tobias Meggendorfer and
Salomon Sickert from the Technical University of Munich for help in the
implementation. Structure-specific, more efficient code will be
added in the near future. All wrapper (synchronized, etc.) have
been updated.
- Abstract type-specific comparators are deprecated: their only abstract
method has been pulled up as a default method of the type-specific
interface, which makes it possible to use lambda expressions to define
type-specific comparators.
- The default return value setter/getter are now optional for functions.
In this way, functions can now be defined using lambda expressions (and
they implement java.util.function.Function).
- New static methods in type-specific Maps and SortedMaps make it possible
to use easily fast iterators, even within for loops. Thanks to Tobias
Meggendorfer and Salomon Sickert from the Technical University of Munich
for implementing this feature.
- All hash-based structure now keep track of the size of their backing
array at creation time, and will never rehash below that size. Thanks
to Patrick Julien for suggesting this feature.
- Every deprecated method marked to be removed, or replaced by another
method, has been eliminated.
- Many abstract classes are now obsolete as their abstract methods have
become default methods.
- The type hierarchy of big-list iterators has been fixed.
7.2.0
- Major code cleanup. Several unnecessary method implementations have been
deleted. Several missing methods (e.g., equals()/hashCode() in wrappers)
have been implemented. All methods should now have a reasonable
Javadoc comment.
- Clarified the rem()/remove() conundrum: type-specific collections should
use and override rem(), but type-specific sets should use and override
remove().
- Fixed circular implementation of containsKey() in type-specific
abstract collections.
- Pulled up deprecation at the highest possible (interface) level.
- Collection.*All() methods do not assume anymore that they can
rely on the argument size().
7.1.1
- Fixed decade-old efficiency bug: implementation of RandomAccess
was hidden from synchronized and unmodifiable wrappers. Thanks to
Peter Burka for reporting this bug.
- The defaultReturnValue() getter in unmodifiable maps was throwing
an UnsupportedOperationException instead of delegating the call
to the underlying map. Thanks to Alex Fiennes for reporting this bug.
7.1.0
- Fixed decade-old efficiency bug. Due to a name clash between lists and
......
Welcome to fastutil.
--------------------
# Welcome to fastutil
[fastutil](http://fastutil.di.unimi.it/) is a collection of type-specific
Java classes that extend the Java Collections Framework by providing
several containers, such as maps, sets, lists and prority queues,
implementing the interfaces of the java.util package; it provides also big
(64-bit) arrays, sets and lists, and fast, practical I/O classes for
binary and text files.
[fastutil](http://fastutil.di.unimi.it/) is a collection of type-specific Java
classes that extend the Java Collections Framework by providing several
containers, such as maps, sets, lists and prority queues, implementing the
interfaces of the java.util package; it also provides big (64-bit) arrays,
sets, lists, and fast, practical I/O classes for binary and text files.
fastutil provides a huge collection of specialized classes generated
starting from a parameterized version; the classes are much more compact
and much faster than the general ones. Please read the package
documentation for more information.
fastutil provides a huge collection of specialized classes generated starting
from a parametrized version; the classes are much more compact and much faster
than the general ones. Please read the package documentation for more
information.
The compiled code is contained in the jar file, and should be installed
where you keep Java extensions. Note that the jar file is huge, due to the
large number of classes: if you plan to ship your own jar with some
fastutil classes included, you should look at AutoJar or similar tools to
extract automatically the necessary classes.
Note that the jar file is huge, due to the large number of classes. To
create a small, customized fastutil jar (which you can put in your repo,
local maven, etc.), we provide the `find-deps.sh` shell script. It has
mild prerequisites, as only the `jdeps` tool is required (bundled with JDK
8). It can be used to identify all fastutil classes your project uses and
build a minimized jar only containing the necessary classes. You can also
have a look at AutoJar or similar tools to extract automatically the
necessary classes.
You have to "make sources" to get the actual Java sources; finally, "ant
jar" and "ant javadoc" will generate the jar file and the API
documentation.
## Building
The Java sources are generated using a C preprocessor. The gencsource.sh
script reads in a driver file, that is, a Java source that uses some
preprocessor-defined symbols and some conditional compilation, and
produces a (fake) C source, which includes the driver code and some
definitions that customize the environment.
You have to "make sources" to get the actual Java sources; finally, "ant jar"
and "ant javadoc" will generate the jar file and the API documentation.
The Java sources are generated using a C preprocessor. The `gencsource.sh`
script reads in a driver file, that is, a Java source that uses some
preprocessor-defined symbols and some conditional compilation, and produces a
(fake) C source, which includes the driver code and some definitions that
customize the environment.
* seba (<mailto:sebastiano.vigna@unimi.it>)
* <mailto:fastutil@googlegroups.com>
......@@ -3,7 +3,7 @@ javadoc.base=/usr/share/javadoc
build.sysclasspath=ignore
version=7.1.0
version=8.2.2
dist=dist
src=src
......@@ -16,5 +16,5 @@ docs=docs
build=build
instrumented=instrumented
remote.j2se.apiurl=http://docs.oracle.com/javase/7/docs/api/
remote.j2se.apiurl=http://docs.oracle.com/javase/8/docs/api/
local.j2se.apiurl=file://${javadoc.base}/java
......@@ -3,6 +3,8 @@
xmlns:ivy="antlib:org.apache.ivy.ant">
<property file="build.properties"/>
<property environment="env"/>
<property name="env.JAVA_HOME" value="/usr/java/latest"/>
<!-- ************************************** WARNING: MAVEN SH*T ************************************** -->
......@@ -54,7 +56,6 @@
<jar jarfile="${maven-sources-jar}">
<fileset dir="." includes="README.md,CHANGES,LICENSE-2.0,build.xml,ivy.xml,pom.xml,fastutil.bnd,build.properties,makefile,${drv}/*.drv,gencsource.sh"/>
<fileset dir="src" includes="it/unimi/dsi/fastutil/**/*.java,it/unimi/dsi/fastutil/**/*.html"/>
<fileset dir="test" includes="**/*.java"/>
</jar>
</target>
......@@ -131,9 +132,10 @@
memoryInitialSize="800M"
memoryMaximumSize="800M"
fork="yes"
source="1.7"
target="1.7"
/>
source="1.8"
target="1.8">
<compilerarg value="-Xlint:all"/>
</javac>
</target>
<target name="compile-tests" depends="compile">
......@@ -145,14 +147,17 @@
memoryInitialSize="800M"
memoryMaximumSize="800M"
fork="yes"
source="1.7"
target="1.7"
source="1.8"
target="1.8"
/>
</target>
<target name="jar" depends="compile">
<jar jarfile="fastutil-${version}.jar">
<fileset dir="${build}" excludes="it/unimi/dsi/fastutil/*IndirectDoublePriorityQueue*"/>
<manifest>
<attribute name="Automatic-Module-Name" value="it.unimi.dsi.fastutil"/>
</manifest>
</jar>
</target>
......@@ -173,11 +178,11 @@
<javadoc destdir="${docs}"
packagenames = "it.unimi.dsi.fastutil,it.unimi.dsi.fastutil.*"
overview="${src}/overview.html"
sourcepath="${src}"
sourcepath="${src}:${env.JAVA_HOME}/src"
public="on"
source="${source}"
source="1.8"
windowtitle="fastutil ${version}"
additionalparam="-breakiterator"
additionalparam="-breakiterator -Xmaxwarns 10000"
maxmemory="800M"
>
<link href="${j2se.apiurl}"/>
......
libfastutil-java (8.2.2-1) unstable; urgency=medium
* New upstream version
* debhelper 12
* Point Vcs fields to salsa.debian.org
* Standards-Version: 4.3.0
* Secure URI in copyright format
* Drop useless get-orig-source target
* Remove trailing whitespace in debian/control
* Remove trailing whitespace in debian/copyright
-- Andreas Tille <tille@debian.org> Sat, 12 Jan 2019 09:01:57 +0100
libfastutil-java (7.1.0-2) unstable; urgency=medium
* Upload to unstable.
......
......@@ -4,14 +4,14 @@ Uploaders: Andreas Tille <tille@debian.org>,
tony mancill <tmancill@debian.org>
Section: java
Priority: optional
Build-Depends: debhelper (>= 9),
Build-Depends: debhelper (>= 12~),
javahelper,
default-jdk,
ant,
maven-repo-helper
Standards-Version: 4.0.0
Vcs-Browser: https://anonscm.debian.org/cgit/pkg-java/libfastutil-java.git
Vcs-Git: https://anonscm.debian.org/git/pkg-java/libfastutil-java.git
Standards-Version: 4.3.0
Vcs-Browser: https://salsa.debian.org/java-team/libfastutil-java
Vcs-Git: https://salsa.debian.org/java-team/libfastutil-java.git
Homepage: http://fastutil.di.unimi.it/
Package: libfastutil-java
......
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Contact: Sebastiano Vigna <vigna@acm.org>
Source: http://fastutil.di.unimi.it/
......
......@@ -38,6 +38,3 @@ override_dh_auto_build:
override_dh_builddeb:
dh_builddeb -- -Z xz
get-orig-source:
mkdir -p ../tarballs
uscan --verbose --force-download --destdir ../tarballs
This diff is collapsed.
This diff is collapsed.
/*
* Copyright (C) 2002-2016 Sebastiano Vigna
* Copyright (C) 2002-2017 Sebastiano Vigna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -19,36 +19,11 @@ package PACKAGE;
/** An abstract class facilitating the creation of type-specific {@linkplain it.unimi.dsi.fastutil.BidirectionalIterator bidirectional iterators}.
*
* <P>To create a type-specific bidirectional iterator, besides what is needed
* for an iterator you need both a method returning the previous element as
* primitive type and a method returning the previous element as an
* object. However, if you inherit from this class you need just one (anyone).
*
* <P>This class implements also a trivial version of {@link #back(int)} that
* uses type-specific methods.
* @deprecated As of fastutil 8 this class is no longer necessary, as its previous abstract
* methods are now default methods of the type-specific interface.
*/
@Deprecated
public abstract class KEY_ABSTRACT_BIDI_ITERATOR KEY_GENERIC extends KEY_ABSTRACT_ITERATOR KEY_GENERIC implements KEY_BIDI_ITERATOR KEY_GENERIC {
protected KEY_ABSTRACT_BIDI_ITERATOR() {}
#if KEYS_PRIMITIVE
/** Delegates to the corresponding generic method. */
public KEY_TYPE PREV_KEY() { return previous().KEY_VALUE(); }
/** Delegates to the corresponding type-specific method. */
public KEY_GENERIC_CLASS previous() { return KEY_CLASS.valueOf( PREV_KEY() ); }
#endif
/** This method just iterates the type-specific version of {@link #previous()} for
* at most <code>n</code> times, stopping if {@link
* #hasPrevious()} becomes false. */
public int back( final int n ) {
int i = n;
while( i-- != 0 && hasPrevious() ) PREV_KEY();
return n - i - 1;
}
}
This diff is collapsed.
/*
* Copyright (C) 2002-2016 Sebastiano Vigna
* Copyright (C) 2002-2017 Sebastiano Vigna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,50 +17,13 @@
package PACKAGE;
import java.util.ListIterator;
import it.unimi.dsi.fastutil.BigListIterator;
/** An abstract class facilitating the creation of type-specific {@linkplain it.unimi.dsi.fastutil.BigListIterator big-list iterators}.
*
* <p>This implementation provides (deprecated) implementations of {@link ListIterator#previousIndex()} and {@link ListIterator#nextIndex()} that
* just invoke the corresponding {@link BigListIterator} methods.
*
* @see java.util.ListIterator
* @see it.unimi.dsi.fastutil.BigListIterator
* @deprecated As of fastutil 8 this class is no longer necessary, as its previous abstract
* methods are now default methods of the type-specific interface.
*/
@Deprecated
public abstract class KEY_ABSTRACT_BIG_LIST_ITERATOR KEY_GENERIC extends KEY_ABSTRACT_BIDI_ITERATOR KEY_GENERIC implements KEY_BIG_LIST_ITERATOR KEY_GENERIC {
protected KEY_ABSTRACT_BIG_LIST_ITERATOR() {}
#if KEYS_PRIMITIVE
/** Delegates to the corresponding type-specific method. */
public void set( KEY_GENERIC_CLASS ok ) { set( ok.KEY_VALUE() ); }
/** Delegates to the corresponding type-specific method. */
public void add( KEY_GENERIC_CLASS ok ) { add( ok.KEY_VALUE() ); }
#endif
/** This method just throws an {@link UnsupportedOperationException}. */
public void set( KEY_GENERIC_TYPE k ) { throw new UnsupportedOperationException(); }
/** This method just throws an {@link UnsupportedOperationException}. */
public void add( KEY_GENERIC_TYPE k ) { throw new UnsupportedOperationException(); }
/** This method just iterates the type-specific version of {@code next()} for at most
* <code>n</code> times, stopping if {@link #hasNext()} becomes false.*/
public long skip( final long n ) {
long i = n;
while( i-- != 0 && hasNext() ) NEXT_KEY();
return n - i - 1;
}
/** This method just iterates the type-specific version of {@link #previous()} for
* at most <code>n</code> times, stopping if {@link
* #hasPrevious()} becomes false. */
public long back( final long n ) {
long i = n;
while( i-- != 0 && hasPrevious() ) PREV_KEY();
return n - i - 1;
}
}
/*
* Copyright (C) 2002-2016 Sebastiano Vigna
* Copyright (C) 2002-2017 Sebastiano Vigna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -18,262 +18,151 @@
package PACKAGE;
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Iterator;
/** An abstract class providing basic methods for collections implementing a type-specific interface.
*
* <P>In particular, this class provide {@link #iterator()}, <code>add()</code>, {@link #remove(Object)} and
* <p>In particular, this class provide {@link #iterator()}, {@code add()}, {@link #remove(Object)} and
* {@link #contains(Object)} methods that just call the type-specific counterpart.
*
* <p><strong>Warning</strong>: Because of a name clash between the list and collection interfaces
* the type-specific deletion method of a type-specific abstract
* collection is <code>rem()</code>, rather then <code>remove()</code>. A
* subclass must thus override <code>rem()</code>, rather than
* <code>remove()</code>, to make all inherited methods work properly.
* collection is {@code rem()}, rather then {@code remove()}. A
* subclass must thus override {@code rem()}, rather than
* {@code remove()}, to make all inherited methods work properly.
*/
public abstract class ABSTRACT_COLLECTION KEY_GENERIC extends AbstractCollection<KEY_GENERIC_CLASS> implements COLLECTION KEY_GENERIC {
protected ABSTRACT_COLLECTION() {}
#if KEYS_PRIMITIVE
public KEY_TYPE[] toArray( KEY_TYPE a[] ) {
return TO_KEY_ARRAY( a );
}
public KEY_TYPE[] TO_KEY_ARRAY() {
return TO_KEY_ARRAY( null );
}
@Override
public abstract KEY_ITERATOR KEY_GENERIC iterator();
public KEY_TYPE[] TO_KEY_ARRAY( KEY_TYPE a[] ) {
if ( a == null || a.length < size() ) a = new KEY_TYPE[ size() ];
ITERATORS.unwrap( iterator(), a );
return a;
}
#if KEYS_PRIMITIVE
/** Adds all elements of the given type-specific collection to this collection.
/** {@inheritDoc}
*
* @param c a type-specific collection.
* @return <code>true</code> if this collection changed as a result of the call.
* <p>This implementation always throws an {@link UnsupportedOperationException}.
*/
public boolean addAll( COLLECTION c ) {
boolean retVal = false;
final KEY_ITERATOR i = c.iterator();
int n = c.size();
while( n-- != 0 ) if ( add( i.NEXT_KEY() ) ) retVal = true;
return retVal;
@Override
public boolean add(final KEY_TYPE k) {
throw new UnsupportedOperationException();
}
/** Checks whether this collection contains all elements from the given type-specific collection.
/** {@inheritDoc}
*
* @param c a type-specific collection.
* @return <code>true</code> if this collection contains all elements of the argument.
* <p>This implementation iterates over the elements in the collection,
* looking for the specified element.
*/
public boolean containsAll( COLLECTION c ) {
final KEY_ITERATOR i = c.iterator();
int n = c.size();
while( n-- != 0 ) if ( ! contains( i.NEXT_KEY() ) ) return false;
return true;
@Override
public boolean contains(final KEY_TYPE k) {
final KEY_ITERATOR iterator = iterator();
while (iterator.hasNext()) if (k == iterator.NEXT_KEY()) return true;
return false;
}
/** Retains in this collection only elements from the given type-specific collection.
/** {@inheritDoc}
*
* @param c a type-specific collection.
* @return <code>true</code> if this collection changed as a result of the call.
* <p>This implementation iterates over the elements in the collection,
* looking for the specified element and tries to remove it.
*/
public boolean retainAll( COLLECTION c ) {
boolean retVal = false;
int n = size();
final KEY_ITERATOR i = iterator();
while( n-- != 0 ) {
if ( ! c.contains( i.NEXT_KEY() ) ) {
i.remove();
retVal = true;
}
@Override
public boolean rem(final KEY_TYPE k) {
final KEY_ITERATOR KEY_GENERIC iterator = iterator();
while (iterator.hasNext())
if (k == iterator.NEXT_KEY()) {
iterator.remove();
return true;
}
return retVal;
return false;
}
/** Remove from this collection all elements in the given type-specific collection.
*
* @param c a type-specific collection.
* @return <code>true</code> if this collection changed as a result of the call.
/** {@inheritDoc}
* @deprecated Please use the corresponding type-specific method instead.
*/
public boolean removeAll( COLLECTION c ) {
boolean retVal = false;
int n = c.size();
final KEY_ITERATOR i = c.iterator();
while( n-- != 0 ) if ( rem( i.NEXT_KEY() ) ) retVal = true;
return retVal;
}
#endif
public Object[] toArray() {
final Object[] a = new Object[ size() ];
it.unimi.dsi.fastutil.objects.ObjectIterators.unwrap( iterator(), a );
return a;
}
@SuppressWarnings("unchecked")
public <T> T[] toArray( T[] a ) {
final int size = size();
if ( a.length < size ) a = (T[])java.lang.reflect.Array.newInstance( a.getClass().getComponentType(), size );
it.unimi.dsi.fastutil.objects.ObjectIterators.unwrap( iterator(), a );
if ( size < a.length ) a[ size ] = null;
return a;
@SuppressWarnings("deprecation")
@Deprecated
@Override
public boolean add(final KEY_GENERIC_CLASS key) {
return COLLECTION.super.add(key);
}
/** Adds all elements of the given collection to this collection.
*
* @param c a collection.
* @return <code>true</code> if this collection changed as a result of the call.
/** {@inheritDoc}
* @deprecated Please use the corresponding type-specific method instead.
*/
public boolean addAll( Collection<? extends KEY_GENERIC_CLASS> c ) {
boolean retVal = false;
final Iterator<? extends KEY_GENERIC_CLASS> i = c.iterator();
int n = c.size();
while( n-- != 0 ) if ( add( i.next() ) ) retVal = true;
return retVal;
}
public boolean add( KEY_GENERIC_TYPE k ) {
throw new UnsupportedOperationException();
@Deprecated
@Override
public boolean contains(final Object key) {
return COLLECTION.super.contains(key);
}
/** Delegates to the new covariantly stronger generic method. */
/** {@inheritDoc}
* @deprecated Please use the corresponding type-specific method instead.
*/
@Deprecated
public KEY_ITERATOR KEY_GENERIC KEY_ITERATOR_METHOD() {
return iterator();
@Override
public boolean remove(final Object key) {
return COLLECTION.super.remove(key);
}
public abstract KEY_ITERATOR KEY_GENERIC iterator();
#if KEYS_PRIMITIVE
/** Delegates to the type-specific <code>rem()</code> method. */
public boolean remove( Object ok ) {
if ( ok == null ) return false;
return rem( KEY_OBJ2TYPE( ok ) );
@Override
public KEY_TYPE[] toArray(KEY_TYPE a[]) {
if (a == null || a.length < size()) a = new KEY_TYPE[size()];
ITERATORS.unwrap(iterator(), a);
return a;
}
/** Delegates to the corresponding type-specific method. */
public boolean add( final KEY_CLASS o ) {
return add( o.KEY_VALUE() );
@Override
public KEY_TYPE[] TO_KEY_ARRAY() {
return toArray((KEY_TYPE[]) null);
}
/** Delegates to the corresponding type-specific method. */
public boolean rem( final Object o ) {
if ( o == null ) return false;
return rem( KEY_OBJ2TYPE(o) );
/** {@inheritDoc}
* @deprecated Please use {@code toArray()} instead&mdash;this method is redundant and will be removed in the future.
*/
@Deprecated
@Override
public KEY_TYPE[] TO_KEY_ARRAY(final KEY_TYPE a[]) {
return toArray(a);
}
/** Delegates to the corresponding type-specific method. */
public boolean contains( final Object o ) {
if ( o == null ) return false;
return contains( KEY_OBJ2TYPE(o) );
}
@Override
public boolean addAll(final COLLECTION c) {
boolean retVal = false;
public boolean contains( final KEY_TYPE k ) {
final KEY_ITERATOR iterator = iterator();
while ( iterator.hasNext() ) if ( k == iterator.NEXT_KEY() ) return true;
return false;
for(final KEY_ITERATOR i = c.iterator(); i.hasNext();)
if (add(i.NEXT_KEY())) retVal = true;
return retVal;
}
#else
/** Delegates to {@link #rem(Object)}. */
@Override
public boolean remove( final Object o ) {
return rem(o);
}
#endif
public boolean rem( final KEY_TYPE k ) {
final KEY_ITERATOR iterator = iterator();
while ( iterator.hasNext() )
if ( k == iterator.NEXT_KEY() ) {
iterator.remove();
public boolean containsAll(final COLLECTION c) {
for(final KEY_ITERATOR i = c.iterator(); i.hasNext();)
if (! contains(i.NEXT_KEY())) return false;
return true;
}
return false;
}
/** Checks whether this collection contains all elements from the given collection.
*
* @param c a collection.
* @return <code>true</code> if this collection contains all elements of the argument.
*/
public boolean containsAll( Collection<?> c ) {
int n = c.size();
final Iterator<?> i = c.iterator();
while( n-- != 0 ) if ( ! contains( i.next() ) ) return false;
return true;
@Override
public boolean removeAll(final COLLECTION c) {
boolean retVal = false;
for(final KEY_ITERATOR i = c.iterator(); i.hasNext();)
if (rem(i.NEXT_KEY())) retVal = true;
return retVal;
}
/** Retains in this collection only elements from the given collection.
*
* @param c a collection.
* @return <code>true</code> if this collection changed as a result of the call.
*/
public boolean retainAll( Collection<?> c ) {
@Override
public boolean retainAll(final COLLECTION c) {
boolean retVal = false;
int n = size();
final Iterator<?> i = iterator();
while( n-- != 0 ) {
if ( ! c.contains( i.next() ) ) {
for(final KEY_ITERATOR i = iterator(); i.hasNext();)
if (! c.contains(i.NEXT_KEY())) {
i.remove();
retVal = true;
}
}
return retVal;
}
#endif
/** Remove from this collection all elements in the given collection.
* If the collection is an instance of this class, it uses faster iterators.
*
* @param c a collection.
* @return <code>true</code> if this collection changed as a result of the call.
*/
public boolean removeAll( Collection<?> c ) {
boolean retVal = false;
int n = c.size();
final Iterator<?> i = c.iterator();
while( n-- != 0 ) if ( remove( i.next() ) ) retVal = true;
return retVal;
}
public boolean isEmpty() {
return size() == 0;
}
@Override
public String toString() {
final StringBuilder s = new StringBuilder();
final KEY_ITERATOR KEY_GENERIC i = iterator();
......
/*
* Copyright (C) 2002-2016 Sebastiano Vigna
* Copyright (C) 2002-2017 Sebastiano Vigna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -18,23 +18,14 @@
package PACKAGE;
/** An abstract class facilitating the creation of type-specific {@linkplain java.util.Comparator comparators}.
*
* <P>To create a type-specific comparator you need both a method comparing
* primitive types and a method comparing objects. However, if you have the
* first one you can just inherit from this class and get for free the second
* one.
*
* @see java.util.Comparator
* @deprecated As of fastutil 8 this class is no longer necessary, as its only previous abstract
* method is now a default method of the type-specific interface.
*/
@Deprecated
public abstract class KEY_ABSTRACT_COMPARATOR KEY_GENERIC implements KEY_COMPARATOR KEY_GENERIC, java.io.Serializable {
private static final long serialVersionUID = 0L;
protected KEY_ABSTRACT_COMPARATOR() {}
public int compare( KEY_GENERIC_CLASS ok1, KEY_GENERIC_CLASS ok2 ) {
return compare( ok1.KEY_VALUE(), ok2.KEY_VALUE() );
}
public abstract int compare( KEY_TYPE k1, KEY_TYPE k2 );
}
/*
* Copyright (C) 2002-2016 Sebastiano Vigna
* Copyright (C) 2002-2017 Sebastiano Vigna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -19,19 +19,14 @@ package PACKAGE;
/** An abstract class providing basic methods for functions implementing a type-specific interface.
*
* <P>Optional operations just throw an {@link
* UnsupportedOperationException}. Generic versions of accessors delegate to
* the corresponding type-specific counterparts following the interface rules
* (they take care of returning <code>null</code> on a missing key).
*
* <P>This class handles directly a default return
* <p>This class handles directly a default return
* value (including {@linkplain #defaultReturnValue() methods to access
* it}). Instances of classes inheriting from this class have just to return
* <code>defRetValue</code> to denote lack of a key in type-specific methods. The value
* {@code defRetValue} to denote lack of a key in type-specific methods. The value
* is serialized.
*
* <P>Implementing subclasses have just to provide type-specific <code>get()</code>,
* type-specific <code>containsKey()</code>, and <code>size()</code> methods.
* <p>Implementing subclasses have just to provide type-specific {@code get()},
* type-specific {@code containsKey()}, and {@code size()} methods.
*
*/
......@@ -42,110 +37,19 @@ public abstract class ABSTRACT_FUNCTION KEY_VALUE_GENERIC implements FUNCTION KE
protected ABSTRACT_FUNCTION() {}
/**
* The default return value for <code>get()</code>, <code>put()</code> and
* <code>remove()</code>.
* The default return value for {@code get()}, {@code put()} and
* {@code remove()}.
*/
protected VALUE_GENERIC_TYPE defRetValue;
@Override
public void defaultReturnValue(final VALUE_GENERIC_TYPE rv) {
defRetValue = rv;
}
@Override
public VALUE_GENERIC_TYPE defaultReturnValue() {
return defRetValue;
}
public VALUE_GENERIC_TYPE put( KEY_GENERIC_TYPE key, VALUE_GENERIC_TYPE value ) {
throw new UnsupportedOperationException();
}
public VALUE_GENERIC_TYPE REMOVE_VALUE( KEY_TYPE key ) {
throw new UnsupportedOperationException();
}
public void clear() {
throw new UnsupportedOperationException();
}
#if KEYS_PRIMITIVE
public boolean containsKey( final Object ok ) {
if ( ok == null ) return false;
return containsKey( KEY_OBJ2TYPE( ok ) );
}
#endif
#if KEYS_PRIMITIVE || VALUES_PRIMITIVE
#if VALUES_PRIMITIVE
/** Delegates to the corresponding type-specific method, taking care of returning <code>null</code> on a missing key.
*
* <P>This method must check whether the provided key is in the map using <code>containsKey()</code>. Thus,
* it probes the map <em>twice</em>. Implementors of subclasses should override it with a more efficient method.
*
* @deprecated Please use the corresponding type-specific method instead. */
@Deprecated
#else
/** Delegates to the corresponding type-specific method, taking care of returning <code>null</code> on a missing key.
*
* <P>This method must check whether the provided key is in the map using <code>containsKey()</code>. Thus,
* it probes the map <em>twice</em>. Implementors of subclasses should override it with a more efficient method.
*/
#endif
public VALUE_GENERIC_CLASS get( final Object ok ) {
#if KEYS_PRIMITIVE
if ( ok == null ) return null;
#endif
final KEY_TYPE k = KEY_OBJ2TYPE( ok );
return containsKey( k ) ? VALUE2OBJ( GET_VALUE( k ) ) : null;
}
#if KEYS_PRIMITIVE || VALUES_PRIMITIVE
/** Delegates to the corresponding type-specific method, taking care of returning <code>null</code> on a missing key.
*
* <P>This method must check whether the provided key is in the map using <code>containsKey()</code>. Thus,
* it probes the map <em>twice</em>. Implementors of subclasses should override it with a more efficient method.
*
* @deprecated Please use the corresponding type-specific method instead. */
@Deprecated
#else
/** Delegates to the corresponding type-specific method, taking care of returning <code>null</code> on a missing key.
*
* <P>This method must check whether the provided key is in the map using <code>containsKey()</code>. Thus,
* it probes the map <em>twice</em>. Implementors of subclasses should override it with a more efficient method.
*/
#endif
public VALUE_GENERIC_CLASS put( final KEY_GENERIC_CLASS ok, final VALUE_GENERIC_CLASS ov ) {
final KEY_GENERIC_TYPE k = KEY_CLASS2TYPE( ok );
final boolean containsKey = containsKey( k );
final VALUE_GENERIC_TYPE v = put( k, VALUE_CLASS2TYPE( ov ) );
return containsKey ? VALUE2OBJ( v ) : null;
}
#if VALUES_PRIMITIVE
/** Delegates to the corresponding type-specific method, taking care of returning <code>null</code> on a missing key.
*
* <P>This method must check whether the provided key is in the map using <code>containsKey()</code>. Thus,
* it probes the map <em>twice</em>. Implementors of subclasses should override it with a more efficient method.
*
* @deprecated Please use the corresponding type-specific method instead. */
@Deprecated
#else
/** Delegates to the corresponding type-specific method, taking care of returning <code>null</code> on a missing key.
*
* <P>This method must check whether the provided key is in the map using <code>containsKey()</code>. Thus,
* it probes the map <em>twice</em>. Implementors of subclasses should override it with a more efficient method.
*/
#endif
public VALUE_GENERIC_CLASS remove( final Object ok ) {
#if KEYS_PRIMITIVE
if ( ok == null ) return null;
#endif
final KEY_TYPE k = KEY_OBJ2TYPE( ok );
final boolean containsKey = containsKey( k );
final VALUE_GENERIC_TYPE v = REMOVE_VALUE( k );
return containsKey ? VALUE2OBJ( v ) : null;
}
#endif
}
/*
* Copyright (C) 2002-2016 Sebastiano Vigna
* Copyright (C) 2002-2017 Sebastiano Vigna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -19,42 +19,11 @@ package PACKAGE;
/** An abstract class facilitating the creation of type-specific iterators.
*
* <P>To create a type-specific iterator you need both a method returning the
* next element as primitive type and a method returning the next element as an
* object. However, if you inherit from this class you need just one (anyone).
*
* <P>This class implements also a trivial version of {@link #skip(int)} that uses
* type-specific methods; moreover, {@link #remove()} will throw an {@link
* UnsupportedOperationException}.
*
* @see java.util.Iterator
* @deprecated As of fastutil 8 this class is no longer necessary, as its previous abstract
* methods are now default methods of the type-specific interface.
*/
@Deprecated
public abstract class KEY_ABSTRACT_ITERATOR KEY_GENERIC implements KEY_ITERATOR KEY_GENERIC {
protected KEY_ABSTRACT_ITERATOR() {}
#if KEYS_PRIMITIVE
/** Delegates to the corresponding generic method. */
public KEY_TYPE NEXT_KEY() { return next().KEY_VALUE(); }
/** Delegates to the corresponding type-specific method.
* @deprecated Please use the corresponding type-specific method instead. */
@Deprecated
public KEY_GENERIC_CLASS next() { return KEY_CLASS.valueOf( NEXT_KEY() ); }
#endif
/** This method just throws an {@link UnsupportedOperationException}. */
public void remove() { throw new UnsupportedOperationException(); }
/** This method just iterates the type-specific version of {@link #next()} for at most
* <code>n</code> times, stopping if {@link #hasNext()} becomes false.*/
public int skip( final int n ) {
int i = n;
while( i-- != 0 && hasNext() ) NEXT_KEY();
return n - i - 1;
}
}
This diff is collapsed.
/*
* Copyright (C) 2002-2016 Sebastiano Vigna
* Copyright (C) 2002-2017 Sebastiano Vigna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -19,29 +19,11 @@ package PACKAGE;
/** An abstract class facilitating the creation of type-specific {@linkplain java.util.ListIterator list iterators}.
*
* <P>This class provides trivial type-specific implementations of {@link
* java.util.ListIterator#set(Object) set()} and {@link java.util.ListIterator#add(Object) add()} which
* throw an {@link UnsupportedOperationException}. For primitive types, it also
* provides a trivial implementation of {@link java.util.ListIterator#set(Object) set()} and {@link
* java.util.ListIterator#add(Object) add()} that just invokes the type-specific one.
*
*
* @see java.util.ListIterator
* @deprecated As of fastutil 8 this class is no longer necessary, as its previous abstract
* methods are now default methods of the type-specific interface.
*/
@Deprecated
public abstract class KEY_ABSTRACT_LIST_ITERATOR KEY_GENERIC extends KEY_ABSTRACT_BIDI_ITERATOR KEY_GENERIC implements KEY_LIST_ITERATOR KEY_GENERIC {
protected KEY_ABSTRACT_LIST_ITERATOR() {}
#if KEYS_PRIMITIVE
/** Delegates to the corresponding type-specific method. */
public void set( KEY_GENERIC_CLASS ok ) { set( ok.KEY_VALUE() ); }
/** Delegates to the corresponding type-specific method. */
public void add( KEY_GENERIC_CLASS ok ) { add( ok.KEY_VALUE() ); }
#endif
/** This method just throws an {@link UnsupportedOperationException}. */
public void set( KEY_GENERIC_TYPE k ) { throw new UnsupportedOperationException(); }
/** This method just throws an {@link UnsupportedOperationException}. */
public void add( KEY_GENERIC_TYPE k ) { throw new UnsupportedOperationException(); }
}