Codebase list libfastutil-java / 188e674
Update upstream source from tag 'upstream/8.4.4' Update to upstream version '8.4.4' with Debian dir 0e2c0fc807d3833adea19d6a11512d9b44c40ac3 Pierre Gruet 3 years ago
54 changed file(s) with 1333 addition(s) and 206 deletion(s). Raw diff Collapse all Expand all
0 8.4.4
1
2 - Renamed andThen/compose methods for type-specific functions
3 to avoid potential ambiguous calls.
4
5 - Now bulk colletion methods will try to use type-specific methods
6 if available. A side effect is that in case someone implemented
7 type-specific methods using the JDK version an infinite recursion
8 will happen. Thanks to C. Sean Young for this improvement.
9
10 - New Pair and SortedPair implementations, both standard and type-specific.
11
012 8.4.3
113
214 - Implemented andThen/compose methods for type-specific functions.
820
921 - Static factory methods for immutable sets of primitive scalar types
1022 within a given range.
23
24 - .of() factory methods for lists and sets.
1125
1226 8.4.2
1327
2121
2222 ## Building
2323
24 You have to "make sources" to get the actual Java sources; finally, "ant jar"
25 and "ant javadoc" will generate the jar file and the API documentation.
24 You have to "make sources" to get the actual Java sources; finally, "ant
25 jar" will generate the jar file; "ant javadoc" will generate the API
26 documentation; "ant junit" will run the unit tests.
2627
2728 The Java sources are generated using a C preprocessor. The `gencsource.sh`
2829 script reads in a driver file, that is, a Java source that uses some
22
33 build.sysclasspath=ignore
44
5 version=8.4.3
5 version=8.4.4
66
77 dist=dist
88 src=src
33
44 <property file="build.properties"/>
55 <property environment="env"/>
6 <property name="env.JAVA_HOME" value="/usr/java/latest"/>
76
87 <!-- ************************************** WARNING: MAVEN SH*T ************************************** -->
98
1211 <property name="artifactId" value="fastutil" />
1312 <property name="version" value="${version}" />
1413
14 <!-- define artifacts' name, which follows the convention of Maven -->
1515 <property name="maven-jar" value="${dist}/lib/${artifactId}-${version}.jar" />
16
17 <!-- define artifacts' name, which follows the convention of Maven -->
18
1916 <property name="maven-javadoc-jar" value="${dist}/lib/${artifactId}-${version}-javadoc.jar" />
2017 <property name="maven-sources-jar" value="${dist}/lib/${artifactId}-${version}-sources.jar" />
2118
3330 </target>
3431
3532 <target name="osgi" depends="resolve,compile">
36 <delete dir="${build}/*.class"/>
3733 <taskdef resource="aQute/bnd/ant/taskdef.properties" classpath="lib/bnd-2.4.0.jar"/>
3834 <bnd
3935 classpath="${build}"
119115 <target name="init">
120116 <mkdir dir="${build}"/>
121117 <mkdir dir="${dist}/lib"/>
118 <mkdir dir="${reports}"/>
122119 <symlink link="${dist}/javadoc" resource="../${docs}" overwrite="true"/>
123120 </target>
124121
128125 deprecation="on"
129126 optimize="on"
130127 destdir="${build}"
131 memoryInitialSize="800M"
132 memoryMaximumSize="800M"
128 memoryMaximumSize="2G"
133129 fork="yes"
134130 source="1.8"
135131 target="1.8">
142138 debug="on"
143139 deprecation="on"
144140 optimize="on"
141 classpath="lib/junit-4.13.jar:lib"
145142 destdir="${build}"
146 memoryInitialSize="800M"
147 memoryMaximumSize="800M"
143 memoryMaximumSize="2G"
148144 fork="yes"
149145 source="1.8"
150146 target="1.8"
153149
154150 <target name="jar" depends="compile">
155151 <jar jarfile="fastutil-${version}.jar">
156 <fileset dir="${build}" excludes="it/unimi/dsi/fastutil/*IndirectDoublePriorityQueue*"/>
152 <fileset dir="${build}"/>
157153 <manifest>
158154 <attribute name="Automatic-Module-Name" value="it.unimi.dsi.fastutil"/>
159155 </manifest>
162158
163159 <target name="jar-tests" depends="compile">
164160 <jar jarfile="fastutil-${version}.jar">
165 <fileset dir="${build}" excludes="it/unimi/dsi/fastutil/*IndirectDoublePriorityQueue*"/>
161 <fileset dir="${build}"/>
166162 </jar>
167163 </target>
168164
181177 public="on"
182178 source="1.8"
183179 windowtitle="fastutil ${version}"
184 additionalparam="-breakiterator -Xmaxwarns 10000"
185 maxmemory="800M"
180 additionalparam="-breakiterator -Xmaxwarns 10000 -tag &quot;apiNote:a:API Notes:&quot; -tag &quot;implSpec:a:Implementation Specification:&quot; -tag &quot;implNote:a:Implementation Notes:\&quot;"
181 maxmemory="2G"
186182 >
187183 <link href="${j2se.apiurl}"/>
188184 </javadoc>
192188 <junit printsummary="yes" fork="yes" haltonfailure="off" haltonerror="off">
193189 <classpath location="${build}"/>
194190 <classpath location="${src}"/>
195 <jvmarg value="-Xmx1G" />
191 <classpath location="lib/junit-4.13.jar"/>
192 <classpath location="lib/hamcrest-all-1.3.jar"/>
193 <jvmarg value="-Xmx3G" />
194
195 <assertions><enable/></assertions>
196196
197197 <formatter type="xml"/>
198198 <formatter type="plain"/>
1717 package PACKAGE;
1818
1919 import java.util.AbstractCollection;
20
21 #if KEYS_PRIMITIVE
22 import java.util.Collection;
23 #endif
2024
2125 /** An abstract class providing basic methods for collections implementing a type-specific interface.
2226 *
133137 if (add(i.NEXT_KEY())) retVal = true;
134138 return retVal;
135139 }
140
141 /** {@inheritDoc}
142 *
143 * <p>This implementation delegates to the type-specific version if given a type-specific
144 * collection, otherwise is uses the implementation from {@link AbstractCollection}.
145 */
146 @Override
147 public boolean addAll(final Collection<? extends KEY_CLASS> c) {
148 if (c instanceof COLLECTION) {
149 return addAll((COLLECTION) c);
150 }
151 return super.addAll(c);
152 }
136153
137154 @Override
138155 public boolean containsAll(final COLLECTION c) {
139156 for(final KEY_ITERATOR i = c.iterator(); i.hasNext();)
140157 if (! contains(i.NEXT_KEY())) return false;
141158 return true;
159 }
160
161 /** {@inheritDoc}
162 *
163 * <p>This implementation delegates to the type-specific version if given a type-specific
164 * collection, otherwise is uses the implementation from {@link AbstractCollection}.
165 */
166 @Override
167 public boolean containsAll(final Collection<?> c) {
168 if (c instanceof COLLECTION) {
169 return containsAll((COLLECTION) c);
170 }
171 return super.containsAll(c);
142172 }
143173
144174 @Override
147177 for(final KEY_ITERATOR i = c.iterator(); i.hasNext();)
148178 if (rem(i.NEXT_KEY())) retVal = true;
149179 return retVal;
180 }
181
182 /** {@inheritDoc}
183 *
184 * <p>This implementation delegates to the type-specific version if given a type-specific
185 * collection, otherwise is uses the implementation from {@link AbstractCollection}.
186 */
187 @Override
188 public boolean removeAll(final Collection<?> c) {
189 if (c instanceof COLLECTION) {
190 return removeAll((COLLECTION) c);
191 }
192 return super.removeAll(c);
150193 }
151194
152195 @Override
159202 }
160203 return retVal;
161204 }
205
206 /** {@inheritDoc}
207 *
208 * <p>This implementation delegates to the type-specific version if given a type-specific
209 * collection, otherwise is uses the implementation from {@link AbstractCollection}.
210 */
211 @Override
212 public boolean retainAll(final Collection<?> c) {
213 if (c instanceof COLLECTION) {
214 return retainAll((COLLECTION) c);
215 }
216 return super.retainAll(c);
217 }
162218 #endif
163219
164220 @Override
9595 /** Adds all of the elements in the specified collection to this list (optional operation). */
9696 @Override
9797 public boolean addAll(int index, final Collection<? extends KEY_GENERIC_CLASS> c) {
98 #if KEYS_PRIMITIVE
99 if (c instanceof COLLECTION) {
100 return addAll(index, (COLLECTION) c);
101 }
102 #endif
98103 ensureIndex(index);
99104 final Iterator<? extends KEY_GENERIC_CLASS> i = c.iterator();
100105 final boolean retVal = i.hasNext();
4040
4141 Set<?> s = (Set<?>) o;
4242 if (s.size() != size()) return false;
43 #if KEYS_PRIMITIVE
44 if (s instanceof SET) {
45 return containsAll((SET) s);
46 }
47 #endif
4348 return containsAll(s);
4449 }
4550
279279
280280 public static KEY_GENERIC ARRAY_LIST KEY_GENERIC wrap(final KEY_GENERIC_TYPE a[]) {
281281 return wrap(a, a.length);
282 }
283
284
285 /** Creates an array list using a list of elements.
286 *
287 * @param init a list of elements that will be used to initialize the list.
288 * @return a new array list containing the given elements.
289 */
290
291 @SafeVarargs
292 public static KEY_GENERIC ARRAY_LIST KEY_GENERIC of(final KEY_GENERIC_TYPE... init) {
293 return wrap(init);
282294 }
283295
284296
258258
259259 public static KEY_GENERIC BIG_ARRAY_BIG_LIST KEY_GENERIC wrap(final KEY_GENERIC_TYPE a[][]) {
260260 return wrap(a, length(a));
261 }
262
263
264 /** Creates a big array list using a list of elements.
265 *
266 * @param init a list of elements that will be used to initialize the big list.
267 * @return a new big-array big list containing the given elements.
268 */
269
270 @SafeVarargs
271 public static KEY_GENERIC BIG_ARRAY_BIG_LIST KEY_GENERIC of(final KEY_GENERIC_TYPE... init) {
272 return wrap(BigArrays.wrap(init));
261273 }
262274
263275
5656
5757 /** A class providing static methods and objects that do useful things with {@linkplain BigArrays big arrays}.
5858 *
59 * <p><strong>WARNING</strong>: as of 8.3.0, many methods such as {@link #length()} have been moved to
59 * <p><strong>WARNING</strong>: as of 8.3.0, many methods such as {@code length()} have been moved to
6060 * {@link BigArrays}, as they can be imported statically in a more convenient way.
6161 *
6262 * <p>Note that {@link it.unimi.dsi.fastutil.io.BinIO} and {@link it.unimi.dsi.fastutil.io.TextIO}
255255
256256
257257 #define COMPOSITION(K_C, V_C, T_C, T_P, G_A, G_B, T_G, K_T_G, V_T_G, T_V_G, T_K_G) \
258 default T_G PACKAGE.FUNCTION_NAME(K_C, T_C) K_T_G andThen(VALUE_PACKAGE.FUNCTION_NAME(V_C, T_C) V_T_G after) { \
258 default T_G PACKAGE.FUNCTION_NAME(K_C, T_C) K_T_G andThen ## T_C(VALUE_PACKAGE.FUNCTION_NAME(V_C, T_C) V_T_G after) { \
259259 return k -> after.G_A(GET_VALUE(k)); \
260260 } \
261 default T_G it.unimi.dsi.fastutil.T_P.FUNCTION_NAME(T_C, V_C) T_V_G compose(it.unimi.dsi.fastutil.T_P.FUNCTION_NAME(T_C, K_C) T_K_G before) { \
261 default T_G it.unimi.dsi.fastutil.T_P.FUNCTION_NAME(T_C, V_C) T_V_G compose ## T_C(it.unimi.dsi.fastutil.T_P.FUNCTION_NAME(T_C, K_C) T_K_G before) { \
262262 return k -> GET_VALUE(before.G_B(k)); \
263263 }
264264
272272 COMPOSITION(KEY_TYPE_CAP, VALUE_TYPE_CAP, Object, objects, get, GET_BEFORE, <T>, K_T_G, V_T_G, T_V_G, T_K_G)
273273 COMPOSITION(KEY_TYPE_CAP, VALUE_TYPE_CAP, Reference, objects, get, GET_BEFORE, <T>, K_T_G, V_T_G, T_V_G, T_K_G)
274274
275 }
275 }
0 /*
1 * Copyright (C) 2002-2020 Sebastiano Vigna
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16
17 package PACKAGE;
18
19 /** A type-specific immutable {@link it.unimi.dsi.fastutil.Pair Pair}; provides some additional methods that use polymorphism to avoid (un)boxing. */
20
21 public class IMMUTABLE_PAIR KEY_VALUE_GENERIC implements PAIR KEY_VALUE_GENERIC, java.io.Serializable {
22 private static final long serialVersionUID = 0L;
23
24 protected final KEY_GENERIC_TYPE left;
25 protected final VALUE_GENERIC_TYPE right;
26
27 /** Creates a new type-specific immutable {@link it.unimi.dsi.fastutil.Pair Pair} with given left and right value.
28 * @param left the left value.
29 * @param right the right value.
30 */
31 public IMMUTABLE_PAIR(final KEY_GENERIC_TYPE left, final VALUE_GENERIC_TYPE right) {
32 this.left = left;
33 this.right = right;
34 }
35
36 /** Returns a new type-specific immutable {@link it.unimi.dsi.fastutil.Pair Pair} with given left and right value.
37 * @param left the left value.
38 * @param right the right value.
39 *
40 * @implNote This factory method delegates to the constructor.
41 */
42 public static KEY_VALUE_GENERIC IMMUTABLE_PAIR KEY_VALUE_GENERIC of(final KEY_GENERIC_TYPE left, final VALUE_GENERIC_TYPE right) {
43 return new IMMUTABLE_PAIR KEY_VALUE_GENERIC(left, right);
44 }
45
46 @Override
47 public KEY_GENERIC_TYPE PAIR_LEFT() {
48 return left;
49 }
50
51 @Override
52 public VALUE_GENERIC_TYPE PAIR_RIGHT() {
53 return right;
54 }
55
56 @Override
57 @SuppressWarnings("rawtypes")
58 public boolean equals(Object other) {
59 if (other == null) return false;
60
61 #if KEYS_PRIMITIVE || VALUES_PRIMITIVE
62 if (other instanceof PAIR) {
63 return
64
65 #if KEY_CLASS_Object
66 java.util.Objects.equals(left, ((PAIR)other).PAIR_LEFT())
67 #else
68 left == ((PAIR)other).PAIR_LEFT()
69 #endif
70 #if VALUE_CLASS_Object
71 && java.util.Objects.equals(right, ((PAIR)other).PAIR_RIGHT());
72 #else
73 && right == ((PAIR)other).PAIR_RIGHT();
74 #endif
75 }
76 #endif
77
78 if (other instanceof it.unimi.dsi.fastutil.Pair) {
79 return
80 #if KEY_CLASS_Reference
81 left == ((it.unimi.dsi.fastutil.Pair)other).left()
82 #else
83 java.util.Objects.equals(KEY2OBJ(left), ((it.unimi.dsi.fastutil.Pair)other).left())
84 #endif
85 #if VALUE_CLASS_Reference
86 && right == ((it.unimi.dsi.fastutil.Pair)other).right();
87 #else
88 && java.util.Objects.equals(VALUE2OBJ(right), ((it.unimi.dsi.fastutil.Pair)other).right());
89 #endif
90 }
91
92 return false;
93 }
94
95 public int hashCode() {
96 return KEY2JAVAHASH(left) * 19 + VALUE2JAVAHASH(right);
97 }
98
99 /** Returns a string representation of this pair in the form &lt;<var>l</var>,<var>r</var>&gt;.
100 *
101 * @return a string representation of this pair in the form &lt;<var>l</var>,<var>r</var>&gt;.
102 */
103 @Override
104 public String toString() {
105 return "<" + PAIR_LEFT() + "," + PAIR_RIGHT() + ">";
106 }
107 }
0 /*
1 * Copyright (C) 2002-2020 Sebastiano Vigna
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16
17 package PACKAGE;
18
19 /** A type-specific immutable {@link it.unimi.dsi.fastutil.SortedPair SortedPair}; provides some additional methods that use polymorphism to avoid (un)boxing. */
20
21 #if KEYS_PRIMITIVE
22 public class IMMUTABLE_SORTED_PAIR extends IMMUTABLE_PAIR implements SORTED_PAIR, java.io.Serializable {
23 #else
24 public class IMMUTABLE_SORTED_PAIR <K extends Comparable<K>> extends IMMUTABLE_PAIR <K, K> implements it.unimi.dsi.fastutil.SortedPair<K>, java.io.Serializable {
25 #endif
26 private static final long serialVersionUID = 0L;
27
28 private IMMUTABLE_SORTED_PAIR(final KEY_GENERIC_TYPE left, final KEY_GENERIC_TYPE right) {
29 super(left, right);
30 }
31
32 /** Returns a new type-specific immutable {@link it.unimi.dsi.fastutil.SortedPair SortedPair} with given left and right value.
33 *
34 * <p>Note that if {@code left} and {@code right} are in the wrong order, they will be exchanged.
35 *
36 * @param left the left value.
37 * @param right the right value.
38 *
39 * @implNote This factory method delegates to the constructor.
40 */
41 #if KEYS_PRIMITIVE
42 public static IMMUTABLE_SORTED_PAIR of(final KEY_GENERIC_TYPE left, final KEY_GENERIC_TYPE right) {
43 if (left <= right) return new IMMUTABLE_SORTED_PAIR(left, right);
44 else return new IMMUTABLE_SORTED_PAIR(right, left);
45 #else
46 public static <K extends Comparable<K>> IMMUTABLE_SORTED_PAIR <K> of(final KEY_GENERIC_TYPE left, final KEY_GENERIC_TYPE right) {
47 if (left.compareTo(right) <= 0) return new IMMUTABLE_SORTED_PAIR <K>(left, right);
48 else return new IMMUTABLE_SORTED_PAIR <K>(right, left);
49 #endif
50 }
51
52 @Override
53 @SuppressWarnings("rawtypes")
54 public boolean equals(Object other) {
55 if (other == null) return false;
56
57 #if KEYS_PRIMITIVE || VALUES_PRIMITIVE
58 if (other instanceof SORTED_PAIR) {
59 return
60
61 #if KEY_CLASS_Object
62 java.util.Objects.equals(left, ((SORTED_PAIR)other).PAIR_LEFT())
63 #else
64 left == ((SORTED_PAIR)other).PAIR_LEFT()
65 #endif
66 #if VALUE_CLASS_Object
67 && java.util.Objects.equals(right, ((SORTED_PAIR)other).PAIR_RIGHT());
68 #else
69 && right == ((SORTED_PAIR)other).PAIR_RIGHT();
70 #endif
71 }
72 #endif
73
74 if (other instanceof it.unimi.dsi.fastutil.SortedPair) {
75 return
76 #if KEY_CLASS_Reference
77 left == ((it.unimi.dsi.fastutil.SortedPair)other).left()
78 #else
79 java.util.Objects.equals(KEY2OBJ(left), ((it.unimi.dsi.fastutil.SortedPair)other).left())
80 #endif
81 #if VALUE_CLASS_Reference
82 && right == ((it.unimi.dsi.fastutil.SortedPair)other).right();
83 #else
84 && java.util.Objects.equals(VALUE2OBJ(right), ((it.unimi.dsi.fastutil.SortedPair)other).right());
85 #endif
86 }
87
88 return false;
89 }
90
91 /** Returns a string representation of this sorted pair in the form {<var>l</var>,<var>r</var>}.
92 *
93 * @return a string representation of this pair sorted in the form {<var>l</var>,<var>r</var>}.
94 */
95 @Override
96 public String toString() {
97 return "{" + PAIR_LEFT() + "," + PAIR_RIGHT() + "}";
98 }
99 }
3030 * @param iterable an iterable.
3131 * @return the number of elements returned by {@code iterable}.
3232 */
33 public static KEY_GENERIC long size(final KEY_ITERABLE KEY_GENERIC iterable) {
33 public static KEY_GENERIC long size(final STD_KEY_ITERABLE KEY_GENERIC iterable) {
3434 long c = 0;
3535 for (@SuppressWarnings("unused") final KEY_GENERIC_TYPE dummy : iterable) c++;
3636 return c;
314314
315315 #endif
316316
317 #if defined KEY_COMPARATOR && KEYS_PRIMITIVE
317 /** Creates an array list using a list of elements.
318 *
319 * @param init a list of elements that will be used to initialize the list.
320 * @return a new array list containing the given elements.
321 */
322
323 @SafeVarargs
324 public static KEY_GENERIC LIST KEY_GENERIC of(final KEY_GENERIC_TYPE... init) {
325 return ARRAY_LIST.wrap(init);
326 }
327
328 #if defined(KEY_COMPARATOR) && KEYS_PRIMITIVE
318329 /** {@inheritDoc}
319330 * @deprecated Please use the corresponding type-specific method instead.
320331 */
329340 * <p>Pass {@code null} to sort using natural ordering.
330341 * @see List#sort(java.util.Comparator)
331342 *
332 * @implSpec The default implementation dumps the elements into an array using
343 * @implNote The default implementation dumps the elements into an array using
333344 * {@link #toArray()}, sorts the array, then replaces all elements using the
334345 * {@link #setElements} function.
335346 *
336 * @implneNote It is possible for this method to call {@link #unstableSort} if it can
347 * <p>It is possible for this method to call {@link #unstableSort} if it can
337348 * determine that the results of a stable and unstable sort are completely equivalent.
338349 * This means if you override {@link #unstableSort}, it should <em>not</em> call this
339350 * method unless you override this method as well.
381392 * <p>Unless a subclass specifies otherwise, the results of the method if the list is
382393 * concurrently modified during the sort are unspecified.
383394 *
384 * @implSpec The default implementation dumps the elements into an array using
395 * @implNote The default implementation dumps the elements into an array using
385396 * {@link #toArray()}, sorts the array, then replaces all elements using the
386397 * {@link #setElements} function.
387398 *
407418 * <p>Unless a subclass specifies otherwise, the results of the method if the list is
408419 * concurrently modified during the sort are unspecified.
409420 *
410 * @implSpec The default implementation dumps the elements into an array using
421 * @implNote The default implementation dumps the elements into an array using
411422 * {@link #toArray()}, sorts the array, then replaces all elements using the
412423 * {@link #setElements} function.
413424 *
0 /*
1 * Copyright (C) 2002-2020 Sebastiano Vigna
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16
17 package PACKAGE;
18
19 /** A type-specific mutable {@link it.unimi.dsi.fastutil.Pair Pair}; provides some additional methods that use polymorphism to avoid (un)boxing. */
20
21 public class MUTABLE_PAIR KEY_VALUE_GENERIC implements PAIR KEY_VALUE_GENERIC, java.io.Serializable {
22 private static final long serialVersionUID = 0L;
23
24 protected KEY_GENERIC_TYPE left;
25 protected VALUE_GENERIC_TYPE right;
26
27 /** Creates a new type-specific mutable {@link it.unimi.dsi.fastutil.Pair Pair} with given left and right value.
28 * @param left the left value.
29 * @param right the right value.
30 */
31 public MUTABLE_PAIR(final KEY_GENERIC_TYPE left, final VALUE_GENERIC_TYPE right) {
32 this.left = left;
33 this.right = right;
34 }
35
36 /** Returns a new type-specific mutable {@link it.unimi.dsi.fastutil.Pair Pair} with given left and right value.
37 * @param left the left value.
38 * @param right the right value.
39 *
40 * @implNote This factory method delegates to the constructor.
41 */
42 public static KEY_VALUE_GENERIC MUTABLE_PAIR KEY_VALUE_GENERIC of(final KEY_GENERIC_TYPE left, final VALUE_GENERIC_TYPE right) {
43 return new MUTABLE_PAIR KEY_VALUE_GENERIC(left, right);
44 }
45
46 @Override
47 public KEY_GENERIC_TYPE PAIR_LEFT() {
48 return left;
49 }
50
51 public MUTABLE_PAIR KEY_VALUE_GENERIC left(final KEY_GENERIC_TYPE l) {
52 left = l;
53 return this;
54 }
55
56 @Override
57 public VALUE_GENERIC_TYPE PAIR_RIGHT() {
58 return right;
59 }
60
61 public MUTABLE_PAIR KEY_VALUE_GENERIC right(final VALUE_GENERIC_TYPE r) {
62 right = r;
63 return this;
64 }
65
66
67 @Override
68 @SuppressWarnings("rawtypes")
69 public boolean equals(Object other) {
70 if (other == null) return false;
71
72 #if KEYS_PRIMITIVE || VALUES_PRIMITIVE
73 if (other instanceof PAIR) {
74 return
75
76 #if KEY_CLASS_Object
77 java.util.Objects.equals(left, ((PAIR)other).PAIR_LEFT())
78 #else
79 left == ((PAIR)other).PAIR_LEFT()
80 #endif
81 #if VALUE_CLASS_Object
82 && java.util.Objects.equals(right, ((PAIR)other).PAIR_RIGHT());
83 #else
84 && right == ((PAIR)other).PAIR_RIGHT();
85 #endif
86 }
87 #endif
88
89 if (other instanceof it.unimi.dsi.fastutil.Pair) {
90 return
91 #if KEY_CLASS_Reference
92 left == ((it.unimi.dsi.fastutil.Pair)other).left()
93 #else
94 java.util.Objects.equals(KEY2OBJ(left), ((it.unimi.dsi.fastutil.Pair)other).left())
95 #endif
96 #if VALUE_CLASS_Reference
97 && right == ((it.unimi.dsi.fastutil.Pair)other).right();
98 #else
99 && java.util.Objects.equals(VALUE2OBJ(right), ((it.unimi.dsi.fastutil.Pair)other).right());
100 #endif
101 }
102
103 return false;
104 }
105
106 public int hashCode() {
107 return KEY2JAVAHASH(left) * 19 + VALUE2JAVAHASH(right);
108 }
109
110 /** Returns a string representation of this pair in the form &lt;<var>l</var>,<var>r</var>&gt;.
111 *
112 * @return a string representation of this pair in the form &lt;<var>l</var>,<var>r</var>&gt;.
113 */
114 @Override
115 public String toString() {
116 return "<" + PAIR_LEFT() + "," + PAIR_RIGHT() + ">";
117 }
118 }
7474 * Rather, a family of {@linkplain #trim() trimming
7575 * methods} lets you control the size of the table; this is particularly useful
7676 * if you reuse instances of this class.
77 *
78 * <p>Entries returned by the type-specific {@link #entrySet()} method implement
79 * the suitable type-specific {@link it.unimi.dsi.fastutil.Pair Pair} interface;
80 * only values are mutable.
7781 *
7882 * <p>Iterators generated by this map will enumerate pairs in the same order in which they
7983 * have been added to the map (addition of pairs whose key is already present
134138 * methods} lets you control the size of the table; this is particularly useful
135139 * if you reuse instances of this class.
136140 *
141 * <p>Entries returned by the type-specific {@link #entrySet()} method implement
142 * the suitable type-specific {@link it.unimi.dsi.fastutil.Pair Pair} interface;
143 * only values are mutable.
144 *
137145 * @see Hash
138146 * @see HashCommon
139147 */
159167 * methods} lets you control the size of the table; this is particularly useful
160168 * if you reuse instances of this class.
161169 *
170 * <p>Entries returned by the type-specific {@link #entrySet()} method implement
171 * the suitable type-specific {@link it.unimi.dsi.fastutil.Pair Pair} interface;
172 * only values are mutable.
173 *
162174 * @see Hash
163175 * @see HashCommon
164176 */
12651277 * is necessary so that calls to {@link java.util.Map.Entry#setValue(Object)} are reflected in
12661278 * the map */
12671279
1268 final class MapEntry implements MAP.Entry KEY_VALUE_GENERIC, Map.Entry<KEY_GENERIC_CLASS, VALUE_GENERIC_CLASS> {
1280 final class MapEntry implements MAP.Entry KEY_VALUE_GENERIC, Map.Entry<KEY_GENERIC_CLASS, VALUE_GENERIC_CLASS>, PAIR KEY_VALUE_GENERIC {
12691281 // The table index this entry refers to, or -1 if this entry has been deleted.
12701282 int index;
12711283
12811293 }
12821294
12831295 @Override
1296 public KEY_GENERIC_TYPE PAIR_LEFT() {
1297 return key[index];
1298 }
1299
1300 @Override
12841301 public VALUE_GENERIC_TYPE ENTRY_GET_VALUE() {
1302 return value[index];
1303 }
1304
1305 @Override
1306 public VALUE_GENERIC_TYPE PAIR_RIGHT() {
12851307 return value[index];
12861308 }
12871309
12901312 final VALUE_GENERIC_TYPE oldValue = value[index];
12911313 value[index] = v;
12921314 return oldValue;
1315 }
1316
1317 @Override
1318 public PAIR KEY_VALUE_GENERIC right(final VALUE_GENERIC_TYPE v) {
1319 value[index] = v;
1320 return this;
12931321 }
12941322
12951323 #if KEYS_PRIMITIVE
556556 public OPEN_HASH_SET(final KEY_GENERIC_TYPE[] a, final STRATEGY KEY_SUPER_GENERIC strategy) {
557557 this(a, DEFAULT_LOAD_FACTOR, strategy);
558558 }
559
559560 #else
560561 /** Creates a new hash set with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor
561562 * copying the elements of an array.
565566
566567 public OPEN_HASH_SET(final KEY_GENERIC_TYPE[] a) {
567568 this(a, DEFAULT_LOAD_FACTOR);
569 }
570
571 /** Creates a new hash set with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor
572 * using a list of elements.
573 *
574 * @param a a list of elements that will be used to initialize the new hash set.
575 */
576
577 @SafeVarargs
578 public static KEY_GENERIC OPEN_HASH_SET KEY_GENERIC of(final KEY_GENERIC_TYPE... a) {
579 return new OPEN_HASH_SET KEY_GENERIC(a, DEFAULT_LOAD_FACTOR);
568580 }
569581 #endif
570582
0 /*
1 * Copyright (C) 2002-2020 Sebastiano Vigna
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16
17 package PACKAGE;
18
19 /** A type-specific {@link it.unimi.dsi.fastutil.Pair Pair}; provides some additional methods that use polymorphism to avoid (un)boxing. */
20
21 public interface PAIR KEY_VALUE_GENERIC extends it.unimi.dsi.fastutil.Pair<KEY_GENERIC_CLASS, VALUE_GENERIC_CLASS> {
22 #if KEYS_PRIMITIVE
23
24 /**
25 * Returns the left element of this pair.
26 *
27 * @return the left element of this pair.
28 */
29 public KEY_TYPE PAIR_LEFT();
30
31 /** {@inheritDoc}
32 * @deprecated Please use the corresponding type-specific method instead.
33 */
34 @SuppressWarnings("deprecation")
35 @Deprecated
36 @Override
37 public default KEY_CLASS left() {
38 return KEY2OBJ(PAIR_LEFT());
39 }
40
41 /**
42 * Sets the left element of this pair (optional operation).
43 *
44 * @param l a new value for the left element.
45 *
46 * @implNote This implementation throws an {@link UnsupportedOperationException}.
47 */
48 public default PAIR KEY_VALUE_GENERIC left(final KEY_TYPE l) {
49 throw new UnsupportedOperationException();
50 }
51
52 /** {@inheritDoc}
53 * @deprecated Please use the corresponding type-specific method instead.
54 */
55 @SuppressWarnings("deprecation")
56 @Deprecated
57 @Override
58 public default PAIR KEY_VALUE_GENERIC left(final KEY_CLASS l) {
59 return left(KEY_CLASS2TYPE(l));
60 }
61
62 /**
63 * Returns the left element of this pair.
64 *
65 * @return the left element of this pair.
66 *
67 * @implNote This implementation delegates to {@link #left()}.
68 *
69 */
70 public default KEY_TYPE PAIR_FIRST() {
71 return PAIR_LEFT();
72 }
73
74 /** {@inheritDoc}
75 * @deprecated Please use the corresponding type-specific method instead.
76 */
77 @SuppressWarnings("deprecation")
78 @Deprecated
79 @Override
80 public default KEY_CLASS first() {
81 return KEY2OBJ(PAIR_FIRST());
82 }
83
84 /**
85 * Sets the left element of this pair (optional operation).
86 *
87 * @param l a new value for the left element.
88 *
89 * @implNote This implementation delegates to {@link #left(Object)}.
90 */
91 public default PAIR KEY_VALUE_GENERIC first(final KEY_TYPE l) {
92 return left(l);
93 }
94
95 /** {@inheritDoc}
96 * @deprecated Please use the corresponding type-specific method instead.
97 */
98 @SuppressWarnings("deprecation")
99 @Deprecated
100 @Override
101 public default PAIR KEY_VALUE_GENERIC first(final KEY_CLASS l) {
102 return first(KEY_CLASS2TYPE(l));
103 }
104
105 /**
106 * Returns the left element of this pair.
107 *
108 * @return the left element of this pair.
109 *
110 * @implNote This implementation delegates to {@link #left()}.
111 *
112 */
113 public default KEY_TYPE PAIR_KEY() {
114 return PAIR_FIRST();
115 }
116
117 /** {@inheritDoc}
118 * @deprecated Please use the corresponding type-specific method instead.
119 */
120 @SuppressWarnings("deprecation")
121 @Deprecated
122 @Override
123 public default KEY_CLASS key() {
124 return KEY2OBJ(PAIR_KEY());
125 }
126
127 /**
128 * Sets the left element of this pair (optional operation).
129 *
130 * @param l a new value for the left element.
131 *
132 * @implNote This implementation delegates to {@link #left(Object)}.
133 */
134 public default PAIR KEY_VALUE_GENERIC key(final KEY_TYPE l) {
135 return left(l);
136 }
137
138 @Deprecated
139 public default PAIR KEY_VALUE_GENERIC key(KEY_CLASS l) {
140 return key(KEY_CLASS2TYPE(l));
141 }
142
143 #endif
144
145 #if VALUES_PRIMITIVE
146
147 /**
148 * Returns the right element of this pair.
149 *
150 * @return the right element of this pair.
151 */
152 public VALUE_TYPE PAIR_RIGHT();
153
154 /** {@inheritDoc}
155 * @deprecated Please use the corresponding type-specific method instead.
156 */
157 @SuppressWarnings("deprecation")
158 @Deprecated
159 @Override
160 public default VALUE_CLASS right() {
161 return VALUE2OBJ(PAIR_RIGHT());
162 }
163
164
165 /**
166 * Sets the right element of this pair (optional operation).
167 *
168 * @param r a new value for the right element.
169 *
170 * @implNote This implementation throws an {@link UnsupportedOperationException}.
171 */
172 public default PAIR KEY_VALUE_GENERIC right(final VALUE_TYPE r) {
173 throw new UnsupportedOperationException();
174 }
175
176 /** {@inheritDoc}
177 * @deprecated Please use the corresponding type-specific method instead.
178 */
179 @SuppressWarnings("deprecation")
180 @Deprecated
181 @Override
182 public default PAIR KEY_VALUE_GENERIC right(final VALUE_CLASS l) {
183 return right(VALUE_CLASS2TYPE(l));
184 }
185
186 /**
187 * Returns the right element of this pair.
188 *
189 * @return the right element of this pair.
190 *
191 * @implNote This implementation delegates to {@link #right()}.
192 *
193 */
194 public default VALUE_TYPE PAIR_SECOND() {
195 return PAIR_RIGHT();
196 }
197
198 /** {@inheritDoc}
199 * @deprecated Please use the corresponding type-specific method instead.
200 */
201 @SuppressWarnings("deprecation")
202 @Deprecated
203 @Override
204 public default VALUE_CLASS second() {
205 return VALUE2OBJ(PAIR_SECOND());
206 }
207
208 /**
209 * Sets the right element of this pair (optional operation).
210 *
211 * @param r a new value for the right element.
212 *
213 * @implNote This implementation delegates to {@link #right(Object)}.
214 */
215 public default PAIR KEY_VALUE_GENERIC second(final VALUE_TYPE r) {
216 return right(r);
217 }
218
219 /** {@inheritDoc}
220 * @deprecated Please use the corresponding type-specific method instead.
221 */
222 @SuppressWarnings("deprecation")
223 @Deprecated
224 @Override
225 public default PAIR KEY_VALUE_GENERIC second(final VALUE_CLASS l) {
226 return second(VALUE_CLASS2TYPE(l));
227 }
228
229 /**
230 * Returns the right element of this pair.
231 *
232 * @return the right element of this pair.
233 *
234 * @implNote This implementation delegates to {@link #right()}.
235 *
236 */
237 public default VALUE_TYPE PAIR_VALUE() {
238 return PAIR_RIGHT();
239 }
240
241 /** {@inheritDoc}
242 * @deprecated Please use the corresponding type-specific method instead.
243 */
244 @SuppressWarnings("deprecation")
245 @Deprecated
246 @Override
247 public default VALUE_CLASS value() {
248 return VALUE2OBJ(PAIR_VALUE());
249 }
250
251 /**
252 * Sets the right element of this pair (optional operation).
253 *
254 * @param r a new value for the right element.
255 *
256 * @implNote This implementation delegates to {@link #right(Object)}.
257 */
258 public default PAIR KEY_VALUE_GENERIC value(final VALUE_TYPE r) {
259 return right(r);
260 }
261
262 /** {@inheritDoc}
263 * @deprecated Please use the corresponding type-specific method instead.
264 */
265 @SuppressWarnings("deprecation")
266 @Deprecated
267 @Override
268 public default PAIR KEY_VALUE_GENERIC value(final VALUE_CLASS l) {
269 return value(VALUE_CLASS2TYPE(l));
270 }
271
272
273 #endif
274
275 /** Returns a new type-specific immutable {@link it.unimi.dsi.fastutil.Pair Pair} with given left and right value.
276 * @param left the left value.
277 * @param right the right value.
278 */
279 public static KEY_VALUE_GENERIC PAIR KEY_VALUE_GENERIC of(final KEY_GENERIC_TYPE left, final VALUE_GENERIC_TYPE right) {
280 return new IMMUTABLE_PAIR KEY_VALUE_GENERIC(left, right);
281 }
282 }
9494 }
9595
9696 #endif
97
98 /** Creates a new set using a list of elements.
99 *
100 * @param a a list of elements that will be used to initialize the new set.
101 */
102
103 @SafeVarargs
104 public static KEY_GENERIC SET KEY_GENERIC of(final KEY_GENERIC_TYPE... a) {
105 return new OPEN_HASH_SET KEY_GENERIC(a);
106 }
107
97108 }
0 /*
1 * Copyright (C) 2002-2020 Sebastiano Vigna
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16
17 package PACKAGE;
18
19 /** A type-specific immutable {@link it.unimi.dsi.fastutil.SortedPair SortedPair}. */
20
21 #if KEYS_PRIMITIVE
22 public interface SORTED_PAIR extends PAIR, it.unimi.dsi.fastutil.SortedPair<KEY_CLASS>, java.io.Serializable {
23 #else
24 public interface SORTED_PAIR <K extends Comparable<K>> extends PAIR <K, K>, it.unimi.dsi.fastutil.SortedPair<K>, java.io.Serializable {
25 #endif
26
27 /** Returns a new type-specific immutable {@link it.unimi.dsi.fastutil.SortedPair SortedPair} with given left and right value.
28 *
29 * <p>Note that if {@code left} and {@code right} are in the wrong order, they will be exchanged.
30 *
31 * @param left the left value.
32 * @param right the right value.
33 *
34 * @implNote This factory method delegates to the factory method of the corresponding immutable implementation.
35 */
36 #if KEYS_PRIMITIVE
37 public static SORTED_PAIR of(final KEY_GENERIC_TYPE left, final KEY_GENERIC_TYPE right) {
38 return IMMUTABLE_SORTED_PAIR.of(left, right);
39 #else
40 public static <K extends Comparable<K>> SORTED_PAIR <K> of(final KEY_GENERIC_TYPE left, final KEY_GENERIC_TYPE right) {
41 return IMMUTABLE_SORTED_PAIR.of(left, right);
42 #endif
43 }
44 }
5555 VALUE_TYPE_CAP=Object # Just for filling holes
5656
5757 if [[ "${rem:0:1}" == "2" ]]; then
58 isFunction=true
5958 rem=${rem:1}
6059 rem2=${rem##[A-Z]+([a-z])}
6160 valuelen=$(( ${#rem} - ${#rem2} ))
6261 VALUE_TYPE_CAP=${rem:0:$valuelen}
6362 root=$rem2
64 else
65 isFunction=false
63 fi
64
65 if [[ "$class" == *Pair ]]; then
66 rem2=${rem##[A-Z]+([a-z])}
67 valuelen=$(( ${#rem} - ${#rem2} ))
68 VALUE_TYPE_CAP=${rem:0:$valuelen}
6669 fi
6770
6871 for((k=0; k<${#TYPE_CAP[*]}; k++)); do
339342 "#define FUNCTION ${TYPE_CAP[$k]}2${TYPE_CAP[$v]}Function\n"\
340343 "#define MAP ${TYPE_CAP[$k]}2${TYPE_CAP[$v]}Map\n"\
341344 "#define SORTED_MAP ${TYPE_CAP[$k]}2${TYPE_CAP[$v]}SortedMap\n"\
345 "#if KEY_CLASS_Object && VALUE_CLASS_Object\n"\
346 "#define PAIR it.unimi.dsi.fastutil.Pair\n"\
347 "#define SORTED_PAIR it.unimi.dsi.fastutil.SortedPair\n"\
348 "#else\n"\
349 "#define PAIR ${TYPE_CAP[$k]}${TYPE_CAP[$v]}Pair\n"\
350 "#define SORTED_PAIR ${TYPE_CAP[$k]}${TYPE_CAP[$v]}SortedPair\n"\
351 "#endif\n"\
352 "#define MUTABLE_PAIR ${TYPE_CAP[$k]}${TYPE_CAP[$v]}MutablePair\n"\
353 "#define IMMUTABLE_PAIR ${TYPE_CAP[$k]}${TYPE_CAP[$v]}ImmutablePair\n"\
354 "#define IMMUTABLE_SORTED_PAIR ${TYPE_CAP[$k]}${TYPE_CAP[$k]}ImmutableSortedPair\n"\
342355 "#if KEYS_REFERENCE\n"\
343356 "#define STD_SORTED_MAP SortedMap\n"\
344357 "#define STRATEGY Strategy\n"\
361374 "#define KEY_LIST_ITERATOR ${TYPE_CAP2[$k]}ListIterator\n"\
362375 "#define KEY_BIG_LIST_ITERATOR ${TYPE_CAP2[$k]}BigListIterator\n"\
363376 "#define STD_KEY_ITERATOR ${TYPE_STD[$k]}Iterator\n"\
377 "#define STD_KEY_ITERABLE ${TYPE_STD[$k]}Iterable\n"\
364378 "#define KEY_COMPARATOR ${TYPE_STD[$k]}Comparator\n"\
365379 \
366380 \
513527 "#define FIRST_KEY first${TYPE_STD[$k]}Key\n"\
514528 "#define LAST_KEY last${TYPE_STD[$k]}Key\n"\
515529 "#define GET_KEY get${TYPE_STD[$k]}\n"\
530 "#define PAIR_LEFT left${TYPE_STD[$k]}\n"\
531 "#define PAIR_FIRST first${TYPE_STD[$k]}\n"\
532 "#define PAIR_KEY key${TYPE_STD[$k]}\n"\
516533 "#define REMOVE_KEY remove${TYPE_STD[$k]}\n"\
517534 "#define READ_KEY read${TYPE_CAP2[$k]}\n"\
518535 "#define WRITE_KEY write${TYPE_CAP2[$k]}\n"\
548565 "#define ENTRY_GET_VALUE get${TYPE_STD[$v]}Value\n"\
549566 "#define REMOVE_FIRST_VALUE removeFirst${TYPE_STD[$v]}\n"\
550567 "#define REMOVE_LAST_VALUE removeLast${TYPE_STD[$v]}\n"\
568 "#define PAIR_RIGHT right${TYPE_STD[$v]}\n"\
569 "#define PAIR_SECOND second${TYPE_STD[$v]}\n"\
570 "#define PAIR_VALUE value${TYPE_STD[$v]}\n"\
551571 \
552572 \
553573 "/* Methods (keys/values) */\n"\
8585 fastutil-$(version)/LICENSE-2.0 \
8686 fastutil-$(version)/makefile \
8787 $(foreach f, $(SOURCES), fastutil-$(version)/$(f)) \
88 fastutil-$(version)/$(SOURCEDIR)/{boolean,byte,char,short,int,long,float,double,object}s/package.html \
89 fastutil-$(version)/$(SOURCEDIR)/io/package.html \
88 fastutil-$(version)/$(SOURCEDIR)/{boolean,byte,char,short,int,long,float,double,object}s/package-info.java \
89 fastutil-$(version)/$(SOURCEDIR)/io/package-info.java \
9090 fastutil-$(version)/src/overview.html \
9191 $$(find fastutil-$(version)/test -iname \*.java)
9292 rm fastutil-$(version)
9393
9494 binary:
9595 make -s clean sources format
96 ant clean osgi javadoc
96 ant clean osgi jar javadoc
9797 -rm -f fastutil-$(version)
9898 ln -s . fastutil-$(version)
9999 cp dist/lib/fastutil-$(version).jar .
111111 (sed -e s/VERSION/$$(grep version build.properties | cut -d= -f2)/ <pom-model.xml >pom.xml)
112112
113113 format:
114 $(ECLIPSE) -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter -verbose -config $(CURDIR)/.settings/org.eclipse.jdt.core.prefs $(CURDIR)/src/it/unimi/dsi/fastutil/{booleans,bytes,shorts,chars,ints,floats,longs,doubles,objects}
114 $(ECLIPSE) -data workspace -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter -verbose -config $(CURDIR)/.settings/org.eclipse.jdt.core.prefs $(CURDIR)/src/it/unimi/dsi/fastutil/{booleans,bytes,shorts,chars,ints,floats,longs,doubles,objects}
115115
116116 stage: pom
117117 (unset LOCAL_IVY_SETTINGS; ant stage)
225225
226226 CSOURCES += $(BIG_LIST_ITERATORS)
227227
228 PAIRS := $(foreach k,$(TYPE), $(foreach v,$(TYPE), $(GEN_SRCDIR)/$(PKG_PATH)/$(PACKAGE_$(k))/$(k)$(v)Pair.c))
229 $(PAIRS): drv/Pair.drv; ./gencsource.sh $< $@ >$@
230
231 CSOURCES += $(PAIRS)
232
233 SORTED_PAIRS := $(foreach k,$(TYPE_NOBOOL_NOOBJ), $(GEN_SRCDIR)/$(PKG_PATH)/$(PACKAGE_$(k))/$(k)$(k)SortedPair.c)
234 $(SORTED_PAIRS): drv/SortedPair.drv; ./gencsource.sh $< $@ >$@
235
236 CSOURCES += $(SORTED_PAIRS)
237
238
228239 #
229240 # Abstract implementations
230241 #
437448 $(ARRAY_INDIRECT_PRIORITY_QUEUES): drv/ArrayIndirectPriorityQueue.drv; ./gencsource.sh $< $@ >$@
438449
439450 CSOURCES += $(ARRAY_INDIRECT_PRIORITY_QUEUES)
451
452 MUTABLE_PAIRS := $(foreach k,$(TYPE), $(foreach v,$(TYPE), $(GEN_SRCDIR)/$(PKG_PATH)/$(PACKAGE_$(k))/$(k)$(v)MutablePair.c))
453 $(MUTABLE_PAIRS): drv/MutablePair.drv; ./gencsource.sh $< $@ >$@
454
455 CSOURCES += $(MUTABLE_PAIRS)
456
457 IMMUTABLE_PAIRS := $(foreach k,$(TYPE), $(foreach v,$(TYPE), $(GEN_SRCDIR)/$(PKG_PATH)/$(PACKAGE_$(k))/$(k)$(v)ImmutablePair.c))
458 $(IMMUTABLE_PAIRS): drv/ImmutablePair.drv; ./gencsource.sh $< $@ >$@
459
460 CSOURCES += $(IMMUTABLE_PAIRS)
461
462 IMMUTABLE_SORTED_PAIRS := $(foreach k,$(TYPE_NOBOOL_NOREF), $(GEN_SRCDIR)/$(PKG_PATH)/$(PACKAGE_$(k))/$(k)$(k)ImmutableSortedPair.c)
463 $(IMMUTABLE_SORTED_PAIRS): drv/ImmutableSortedPair.drv; ./gencsource.sh $< $@ >$@
464
465 CSOURCES += $(IMMUTABLE_SORTED_PAIRS)
440466
441467
442468 #
601627 $(SOURCEDIR)/BigList.java \
602628 $(SOURCEDIR)/BigListIterator.java \
603629 $(SOURCEDIR)/PriorityQueue.java \
630 $(SOURCEDIR)/Pair.java \
631 $(SOURCEDIR)/SortedPair.java \
604632 $(SOURCEDIR)/IndirectPriorityQueue.java \
605633 $(SOURCEDIR)/Arrays.java \
606634 $(SOURCEDIR)/Swapper.java \
636664 -@find build -name \*.class -exec rm {} \;
637665 -@find . -name \*.java~ -exec rm {} \;
638666 -@find . -name \*.html~ -exec rm {} \;
639 -@rm -f $(foreach k, $(sort $(TYPE)), $(GEN_SRCDIR)/$(PKG_PATH)/$(PACKAGE_$(k))/*.java)
667 -@$(foreach k, $(sort $(TYPE)), find $(GEN_SRCDIR)/$(PKG_PATH)/$(PACKAGE_$(k)) -iname \*.java -and -not -iname \*-info.java -delete &&) true
640668 -@rm -f $(GEN_SRCDIR)/$(PKG_PATH)/io/*IO.java
641669 -@rm -f $(GEN_SRCDIR)/$(PKG_PATH)/BigArrays.java
642670 -@rm -f $(GEN_SRCDIR)/$(PKG_PATH)/*.[chj] $(GEN_SRCDIR)/$(PKG_PATH)/*/*.[chj]
643671 -@rm -fr $(DOCSDIR)/*
644672
645673 sources: $(JSOURCES)
674 rm $(GEN_SRCDIR)/it/unimi/dsi/fastutil/objects/ObjectObjectPair.java
646675
647676 csources: $(CSOURCES)
33 <artifactId>fastutil</artifactId>
44 <packaging>jar</packaging>
55 <name>fastutil</name>
6 <version>8.4.3</version>
7 <description>fastutil extends the Java Collections Framework by providing type-specific maps, sets, lists and priority queues with a small memory footprint and fast access and insertion; provides also big (64-bit) arrays, sets and lists, and fast, practical I/O classes for binary and text files.</description>
6 <version>8.4.4</version>
7 <description>fastutil extends the Java Collections Framework by providing type-specific maps, sets, lists and priority queues with a small memory footprint and fast access and insertion; provides also big (64-bit) arrays, sets and lists, sorting algorithms, and fast, practical I/O classes for binary and text files.</description>
88 <url>http://fastutil.di.unimi.it/</url>
99 <licenses>
1010 <license>
2121 <developer>
2222 <id>vigna</id>
2323 <name>Sebastiano Vigna</name>
24 <email>vigna@di.unimi.it</email>
24 <email>sebastiano.vigna@unimi.it</email>
2525 </developer>
2626 </developers>
2727 <properties>
0 /*
1 * Copyright (C) 2002-2020 Sebastiano Vigna
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 package it.unimi.dsi.fastutil;
17
18 import it.unimi.dsi.fastutil.objects.ObjectObjectImmutablePair;
19
20 /**
21 * A pair of elements.
22 *
23 * <p>
24 * This inferface gives access to a pair of elements &lt;<var>l</var>, <var>r</var>&gt;, where
25 * <var>l</var> is the {@linkplain #left() <em>left element</em>} and <var>r</var> is the
26 * {@linkplain #right() <em>right element</em>}. Mutability is optional.
27 *
28 * <p>
29 * Since pairs have many different interpretation depending on the context, this interface offers
30 * alternative but equivalent access methods based on {@linkplain #first()
31 * first}/{@linkplain #second() second} and {@linkplain #key() key}/{@linkplain #value() value}. All
32 * such methods have default implementations that delegates to the standard methods. Implementations
33 * need only to provide {@link #left()} and {@link #right()}, and possibly {@link #left(Object)} and
34 * {@link #right(Object)} for mutability.
35 *
36 * <p>
37 * Setters return the instance, and are thus chainable. You can write
38 *
39 * <pre>
40 * pair.left(0).right(1)
41 * </pre>
42 *
43 * and, if necessary, pass this value to a method.
44 *
45 * @param <L> the type of the left element.
46 * @param <R> the type of the right element.
47 */
48
49 public interface Pair<L, R> {
50
51 /**
52 * Returns the left element of this pair.
53 *
54 * @return the left element of this pair.
55 */
56 public L left();
57
58 /**
59 * Returns the right element of this pair.
60 *
61 * @return the right element of this pair.
62 */
63 public R right();
64
65 /**
66 * Sets the left element of this pair (optional operation).
67 *
68 * @param l a new value for the left element.
69 *
70 * @implNote This implementation throws an {@link UnsupportedOperationException}.
71 */
72 public default Pair<L, R> left(final L l) {
73 throw new UnsupportedOperationException();
74 }
75
76 /**
77 * Sets the right element of this pair (optional operation).
78 *
79 * @param r a new value for the right element.
80 *
81 * @implNote This implementation throws an {@link UnsupportedOperationException}.
82 */
83 public default Pair<L, R> right(final R r) {
84 throw new UnsupportedOperationException();
85 }
86
87 /**
88 * Returns the left element of this pair.
89 *
90 * @return the left element of this pair.
91 *
92 * @implNote This implementation delegates to {@link #left()}.
93 *
94 */
95 public default L first() {
96 return left();
97 }
98
99 /**
100 * Returns the right element of this pair.
101 *
102 * @return the right element of this pair.
103 *
104 * @implNote This implementation delegates to {@link #right()}.
105 *
106 */
107 public default R second() {
108 return right();
109 }
110
111 /**
112 * Sets the left element of this pair (optional operation).
113 *
114 * @param l a new value for the left element.
115 *
116 * @implNote This implementation delegates to {@link #left(Object)}.
117 */
118 public default Pair<L, R> first(final L l) {
119 return left(l);
120 }
121
122 /**
123 * Sets the right element of this pair (optional operation).
124 *
125 * @param r a new value for the right element.
126 *
127 * @implNote This implementation delegates to {@link #right(Object)}.
128 */
129 public default Pair<L, R> second(final R r) {
130 return right(r);
131 }
132
133 /**
134 * Sets the left element of this pair (optional operation).
135 *
136 * @param l a new value for the left element.
137 *
138 * @implNote This implementation delegates to {@link #left(Object)}.
139 */
140 public default Pair<L, R> key(final L l) {
141 return left(l);
142 }
143
144 /**
145 * Sets the right element of this pair (optional operation).
146 *
147 * @param r a new value for the right element.
148 *
149 * @implNote This implementation delegates to {@link #right(Object)}.
150 */
151 public default Pair<L, R> value(final R r) {
152 return right(r);
153 }
154
155 /**
156 * Returns the left element of this pair.
157 *
158 * @return the left element of this pair.
159 *
160 * @implNote This implementation delegates to {@link #left()}.
161 *
162 */
163 public default L key() {
164 return left();
165 }
166
167 /**
168 * Returns the right element of this pair.
169 *
170 * @return the right element of this pair.
171 *
172 * @implNote This implementation delegates to {@link #right()}.
173 *
174 */
175 public default R value() {
176 return right();
177 }
178
179 /**
180 * Returns a new immutable {@link it.unimi.dsi.fastutil.Pair Pair} with given left and right
181 * value.
182 *
183 * @param l the left value.
184 * @param r the right value.
185 *
186 * @implNote This factory method returns an instance of {@link ObjectObjectImmutablePair}.
187 */
188 public static <L, R> Pair<L, R> of(final L l, final R r) {
189 return new ObjectObjectImmutablePair<>(l, r);
190 }
191 }
0 /*
1 * Copyright (C) 2002-2020 Sebastiano Vigna
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 package it.unimi.dsi.fastutil;
17
18 import it.unimi.dsi.fastutil.objects.ObjectObjectImmutablePair;
19 import it.unimi.dsi.fastutil.objects.ObjectObjectImmutableSortedPair;
20
21 /**
22 * A pair of sorted elements.
23 *
24 * <p>
25 * This interface strengthen {@link Pair}, without adding methods. It assumes that both elements of
26 * the pair are of the same type, and that they are primitive or comparable. It guarantees that the
27 * {@linkplain #left() left element} is smaller than or equal to the {@linkplain #right() right
28 * element}.
29 *
30 * <p>
31 * Implementations of this class can be used to represent <em>unordered pairs</em> by
32 * canonicalization. Note that, in particular, if you build a sorted pair using a left and right
33 * element in the wrong order they will be exchanged.
34 *
35 * @param <K> the type of the elements.
36 */
37
38 public interface SortedPair<K extends Comparable<K>> extends Pair<K, K> {
39
40 /**
41 * Returns a new immutable {@link it.unimi.dsi.fastutil.SortedPair SortedPair} with given left
42 * and right value.
43 *
44 * <p>
45 * Note that if {@code left} and {@code right} are in the wrong order, they will be exchanged.
46 *
47 * @param l the left value.
48 * @param r the right value.
49 *
50 * @implNote This factory method delegates to
51 * {@link ObjectObjectImmutablePair#of(Object, Object)}.
52 */
53 public static <K extends Comparable<K>> SortedPair<K> of(final K l, final K r) {
54 return ObjectObjectImmutableSortedPair.of(l, r);
55 }
56 }
0 /**
1 * Type-specific classes for boolean elements or keys.
2 *
3 * <p>
4 * Not all classes are provided in a boolean-specific version: sorted sets and
5 * maps not generated, as they are useless. Unsorted sets and maps are kept
6 * around for orthogonality, whereas
7 * {@link it.unimi.dsi.fastutil.booleans.BooleanCollection} is used by maps with
8 * boolean values.
9 */
10 package it.unimi.dsi.fastutil.booleans;
+0
-15
src/it/unimi/dsi/fastutil/booleans/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
1 <html>
2 <head>
3 <title>fastutil</title>
4 </head>
5
6 <body>
7 <p>Provides type-specific classes for boolean elements or keys.
8
9 <p>Not all classes are provided in a boolean-specific version: sorted
10 sets and maps not generated (as they are completely
11 useless). Unsorted sets and maps are kept for orthogonality, whereas
12 {@link it.unimi.dsi.fastutil.booleans.BooleanCollection} is used by maps with boolean values.
13 </body>
14 </html>
0 /**
1 * Type-specific classes for byte elements or keys.
2 */
3 package it.unimi.dsi.fastutil.bytes;
+0
-10
src/it/unimi/dsi/fastutil/bytes/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
1 <html>
2 <head>
3 <title>fastutil</title>
4 </head>
5
6 <body>
7 <p>Provides type-specific classes for byte elements or keys.
8 </body>
9 </html>
0 /**
1 * Type-specific classes for character elements or keys.
2 */
3 package it.unimi.dsi.fastutil.chars;
+0
-10
src/it/unimi/dsi/fastutil/chars/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
1 <html>
2 <head>
3 <title>fastutil</title>
4 </head>
5
6 <body>
7 <p>Provides type-specific classes for character elements or keys.
8 </body>
9 </html>
0 /**
1 * Type-specific classes for double elements or keys.
2 */
3 package it.unimi.dsi.fastutil.doubles;
+0
-10
src/it/unimi/dsi/fastutil/doubles/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
1 <html>
2 <head>
3 <title>fastutil</title>
4 </head>
5
6 <body>
7 <p>Provides type-specific classes for double elements or keys.
8 </body>
9 </html>
0 /**
1 * Type-specific classes for float elements or keys.
2 */
3 package it.unimi.dsi.fastutil.floats;
+0
-10
src/it/unimi/dsi/fastutil/floats/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
1 <html>
2 <head>
3 <title>fastutil</title>
4 </head>
5
6 <body>
7 <p>Provides type-specific classes for float elements or keys.
8 </body>
9 </html>
0 /**
1 * Type-specific classes for integer elements or keys.
2 */
3 package it.unimi.dsi.fastutil.ints;
+0
-10
src/it/unimi/dsi/fastutil/ints/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
1 <html>
2 <head>
3 <title>fastutil</title>
4 </head>
5
6 <body>
7 <p>Provides type-specific classes for integer elements or keys.
8 </body>
9 </html>
0 /**
1 * Classes and static methods that make object and primitive-type I/O easier and faster.
2 *
3 * <p>
4 * Classes in this package provide very efficient, unsynchronized buffered
5 * {@linkplain it.unimi.dsi.fastutil.io.FastBufferedInputStream input} and
6 * {@linkplain it.unimi.dsi.fastutil.io.FastBufferedOutputStream output} streams (with support for
7 * {@linkplain it.unimi.dsi.fastutil.io.RepositionableStream repositioning}, too) and
8 * {@linkplain it.unimi.dsi.fastutil.io.FastByteArrayInputStream fast streams} based on byte arrays.
9 *
10 * <p>
11 * Static containers provide instead a wealth of methods that can be used to
12 * {@linkplain BinIO#storeObject(Object, CharSequence) serialize} or
13 * {@linkplain BinIO#loadObject(CharSequence) deserialize} very easily objects and
14 * {@linkplain BinIO#storeInts(int[], CharSequence) arrays}, even
15 * {@linkplain TextIO#storeInts(int[], CharSequence) in text form}.
16 */
17 package it.unimi.dsi.fastutil.io;
+0
-19
src/it/unimi/dsi/fastutil/io/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
1 <html>
2 <head>
3 <title>fastutil</title>
4 </head>
5
6 <body>
7
8 <p>Provides classes and static methods that make object and primitive-type I/O easier and faster.
9
10
11 <h2>PackageSpecificaton</h2>
12 <p>Classes in this package provide very efficient, unsynchronised buffered
13 input and output stream (with support for repositioning, too) and fast streams
14 based on byte arrays. Static containers
15 provide instead a wealth of methods that can be used to serialize/deserialize
16 very easily objects and arrays.
17 </body>
18 </html>
0 /**
1 * Type-specific classes for long elements or keys.
2 */
3 package it.unimi.dsi.fastutil.longs;
+0
-12
src/it/unimi/dsi/fastutil/longs/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
1 <html>
2 <head>
3 <title>fastutil</title>
4 </head>
5
6 <body>
7
8 <p>Provides type-specific classes for long elements or keys.
9
10 </body>
11 </html>
0 /**
1 * Type-specific classes for object elements or keys.
2 *
3 * <p>
4 * Whenever possible and useful, {@code fastutil} provides both typical
5 * collections, which compare objects using {@code equals()}, and
6 * {@linkplain it.unimi.dsi.fastutil.objects.ReferenceSet
7 * <em>reference-based</em> collections}, which use identity ({@code ==}). See
8 * the related comments in the overview.
9 */
10 package it.unimi.dsi.fastutil.objects;
+0
-19
src/it/unimi/dsi/fastutil/objects/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
1 <html>
2 <head>
3 <title>fastutil</title>
4 </head>
5
6 <body>
7
8 <p>Provides type-specific classes for object elements or keys.
9
10 <p>Whenever possible, {@code fastutil} provides both typical
11 collections, which compare objects using {@code equals()}, and
12 <em>reference-based</em> collections, which use equality
13 ({@code ==}). See the related comments in the overview.
14
15 <p>Of course, reference-based sorted sets and maps make no
16 sense, and are not generated.
17 </body>
18 </html>
0 /**
1 * Type-specific classes for short elements or keys.
2 */
3 package it.unimi.dsi.fastutil.shorts;
+0
-12
src/it/unimi/dsi/fastutil/shorts/package.html less more
0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
1 <html>
2 <head>
3 <title>fastutil</title>
4 </head>
5
6 <body>
7
8 <p>Provides type-specific classes for short elements or keys.
9
10 </body>
11 </html>
456456 <li>The standard entry-set iterators for hash-based maps use an entry object
457457 that refers to the data contained in the hash table. If you retrieve an
458458 entry and delete it, the entry object will become invalid and will throw
459 an {@link java.util.ArrayIndexOutOfBoundsException} exception. This does not
459 an {@link java.lang.ArrayIndexOutOfBoundsException} exception. This does not
460460 apply to fast iterators (see above).</li>
461461
462462 <li>A name clash between the list and collection interfaces
4444 import java.util.function.Supplier;
4545
4646 import org.junit.Before;
47 import org.junit.Ignore;
4748 import org.junit.Test;
4849 import org.junit.runner.RunWith;
4950 import org.junit.runners.Parameterized;
5556 import it.unimi.dsi.fastutil.objects.ObjectIterator;
5657 import it.unimi.dsi.fastutil.objects.ObjectSet;
5758
59 @Ignore
5860 @RunWith(Parameterized.class)
5961 @SuppressWarnings("deprecation")
6062 public abstract class Int2IntMapGenericTest<M extends Int2IntMap> {
4545 import java.util.function.Supplier;
4646
4747 import org.junit.Before;
48 import org.junit.Ignore;
4849 import org.junit.Test;
4950 import org.junit.runner.RunWith;
5051 import org.junit.runners.Parameterized;
5758 import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
5859 import it.unimi.dsi.fastutil.objects.ObjectSet;
5960
61 @Ignore
6062 @SuppressWarnings("deprecation")
6163 @RunWith(Parameterized.class)
6264 public abstract class Int2ObjectMapGenericTest<M extends Int2ObjectMap<Integer>> {
5050 }
5151
5252 @Test
53 public void testAddAll() {
54 final IntArrayList l = IntArrayList.wrap(new int[] { 0, 1 });
55 l.addAll(IntArrayList.wrap(new int[] { 2, 3 } ));
56 assertEquals(IntArrayList.wrap(new int[] { 0, 1, 2, 3 }), l);
57 // Test object based lists still work too.
58 l.addAll(java.util.Arrays.asList(Integer.valueOf(4), Integer.valueOf(5)));
59 assertEquals(IntArrayList.wrap(new int[] { 0, 1, 2, 3, 4, 5 }), l);
60 }
61
62 @Test
63 public void testAddAllAtIndex() {
64 final IntArrayList l = IntArrayList.wrap(new int[] { 0, 3 });
65 l.addAll(1, IntArrayList.wrap(new int[] { 1, 2 } ));
66 assertEquals(IntArrayList.wrap(new int[] { 0, 1, 2, 3 }), l);
67 // Test object based lists still work too.
68 l.addAll(2, java.util.Arrays.asList(Integer.valueOf(4), Integer.valueOf(5)));
69 assertEquals(IntArrayList.wrap(new int[] { 0, 1, 4, 5, 2, 3 }), l);
70 }
71
72 @Test
5373 public void testRemoveAll() {
5474 IntArrayList l = IntArrayList.wrap(new int[] { 0, 1, 1, 2 });
5575 l.removeAll(IntSets.singleton(1));
6282
6383 @Test
6484 public void testSort() {
65 IntArrayList l = IntArrayList.wrap(new int[] { 4, 2, 1, 3 });
85 final IntArrayList l = IntArrayList.wrap(new int[] { 4, 2, 1, 3 });
6686 l.sort(null);
6787 assertEquals(IntArrayList.wrap(new int[] { 1, 2, 3, 4 }), l);
6888 }
127147 l.size(100);
128148 }
129149
150 @Test
151 public void testOf() {
152 final IntArrayList l = IntArrayList.of(0, 1, 2);
153 assertEquals(IntArrayList.wrap(new int[] { 0, 1, 2 }), l);
154 }
130155 }
613613 final IntBigArrayBigList l = new IntBigArrayBigList();
614614 l.size(100);
615615 }
616
617 @Test
618 public void testOf() {
619 final IntBigArrayBigList l = IntBigArrayBigList.of(0, 1, 2);
620 assertEquals(IntBigArrayBigList.wrap(BigArrays.wrap(new int[] { 0, 1, 2 })), l);
621 }
616622 }
5555 public void testEquals() {
5656 final IntOpenHashSet s = new IntOpenHashSet(new int[] { 1, 2, 3 });
5757 assertFalse(s.equals(new ObjectOpenHashSet<>(new Integer[] { 1, null })));
58 }
59
60 @Test
61 public void testEqualsSameType() {
62 final IntOpenHashSet s = new IntOpenHashSet(new int[] { 1, 2, 3 });
63 assertTrue(s.equals(new IntOpenHashSet(new int[] { 1, 2, 3 })));
64 }
65
66 @SuppressWarnings("unlikely-arg-type")
67 @Test
68 public void testEqualsIntSetType() {
69 final IntOpenHashSet s = new IntOpenHashSet(new int[] { 1, 2, 3 });
70 assertTrue(s.equals(new IntArraySet(new int[] { 1, 2, 3 })));
71 }
72
73 @SuppressWarnings({ "boxing", "unlikely-arg-type" })
74 @Test
75 public void testEqualsObjectSet() {
76 final IntOpenHashSet s = new IntOpenHashSet(new int[] { 1, 2, 3 });
77 assertTrue(s.equals(new ObjectOpenHashSet<>(new Integer[] { 1, 2, 3 })));
5878 }
5979
6080 @Test
279299 assertEquals(8, s.n);
280300 }
281301
302 @Test
303 public void testOf() {
304 final IntOpenHashSet s = IntOpenHashSet.of(0, 1, 2);
305 assertEquals(new IntOpenHashSet(new int[] { 0, 1, 2 }), s);
306 }
282307
283308 @SuppressWarnings("boxing")
284309 private static void checkTable(final IntOpenHashSet s) {
347372
348373 /* Now we check that m actually holds that data. */
349374
350 for (final java.util.Iterator i = t.iterator(); i.hasNext();) {
351 final Object e = i.next();
375 for (final Object e : t) {
352376 assertTrue("Error: m and t differ on a key (" + e + ") after insertion (iterating on t)", m.contains(e));
353377 }
354378
397421 assertTrue("Error: !t.equals(m) after removal", t.equals(m));
398422 /* Now we check that m actually holds that data. */
399423
400 for (final java.util.Iterator i = t.iterator(); i.hasNext();) {
401 final Object e = i.next();
424 for (final Object e : t) {
402425 assertFalse("Error: m and t differ on a key (" + e + ") after removal (iterating on t)", !m.contains(e));
403426 }
404427
00 package it.unimi.dsi.fastutil.ints;
1
2 import org.junit.Ignore;
13
24 /*
35 * Copyright (C) 2017-2020 Sebastiano Vigna
1618 */
1719
1820
21 @Ignore
1922 public class StripedInt2IntOpenHashMapTest {
2023 //
2124 //
2525 import org.junit.Test;
2626
2727 import it.unimi.dsi.fastutil.Hash;
28 import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
2829
2930 @SuppressWarnings("rawtypes")
3031 public class ObjectOpenHashSetTest {
3435 @SuppressWarnings("boxing")
3536 public void testStrangeRetainAllCase() {
3637
37 ObjectArrayList<Integer> initialElements = ObjectArrayList.wrap(new Integer[] { 586, 940,
38 final ObjectArrayList<Integer> initialElements = ObjectArrayList.wrap(new Integer[] { 586, 940,
3839 1086, 1110, 1168, 1184, 1185, 1191, 1196, 1229, 1237, 1241,
3940 1277, 1282, 1284, 1299, 1308, 1309, 1310, 1314, 1328, 1360,
4041 1366, 1370, 1378, 1388, 1392, 1402, 1406, 1411, 1426, 1437,
5657 7094, 7379, 7384, 7388, 7394, 7414, 7419, 7458, 7459, 7466,
5758 7467 });
5859
59 ObjectArrayList<Integer> retainElements = ObjectArrayList.wrap(new Integer[] { 586 });
60 final ObjectArrayList<Integer> retainElements = ObjectArrayList.wrap(new Integer[] { 586 });
6061
6162 // Initialize both implementations with the same data
62 ObjectOpenHashSet<Integer> instance = new ObjectOpenHashSet<>(initialElements);
63 ObjectRBTreeSet<Integer> referenceInstance = new ObjectRBTreeSet<>(initialElements);
63 final ObjectOpenHashSet<Integer> instance = new ObjectOpenHashSet<>(initialElements);
64 final ObjectRBTreeSet<Integer> referenceInstance = new ObjectRBTreeSet<>(initialElements);
6465
6566 instance.retainAll(retainElements);
6667 referenceInstance.retainAll(retainElements);
7576 assertEquals(referenceInstance, instance);
7677 }
7778
79 @Test
80 public void testOf() {
81 final ObjectOpenHashSet<Long> s = ObjectOpenHashSet.of(Long.valueOf(0), Long.valueOf(1), Long.valueOf(2));
82 assertEquals(new LongOpenHashSet(new long[] { 0, 1, 2 }), s);
83 }
84
7885 private static java.util.Random r = new java.util.Random(0);
7986
8087 private static Object genKey() {
8188 return Integer.toBinaryString(r.nextInt());
8289 }
8390
84 private static void checkTable(ObjectOpenHashSet<Integer> s) {
91 private static void checkTable(final ObjectOpenHashSet<Integer> s) {
8592 final Object[] key = s.key;
8693 assert (s.n & -s.n) == s.n : "Table length is not a power of two: " + s.n;
8794 assert s.n == key.length - 1;
93100 if (s.containsNull && ! s.contains(null)) throw new AssertionError("Hash table should contain null by internal state, but it doesn't when queried");
94101 if (! s.containsNull && s.contains(null)) throw new AssertionError("Hash table should not contain null by internal state, but it does when queried");
95102
96 java.util.HashSet<String> t = new java.util.HashSet<>();
103 final java.util.HashSet<String> t = new java.util.HashSet<>();
97104 for (int i = s.size(); i-- != 0;)
98105 if (key[i] != null && !t.add((String)key[i])) throw new AssertionError("Key " + key[i] + " appears twice");
99106
100107 }
101108
102 private static void printProbes(ObjectOpenHashSet m) {
109 private static void printProbes(final ObjectOpenHashSet m) {
103110 long totProbes = 0;
104111 double totSquareProbes = 0;
105112 int maxProbes = 0;
128135
129136
130137 @SuppressWarnings("unchecked")
131 private static void test(int n, float f) {
138 private static void test(final int n, final float f) {
132139 int c;
133140 ObjectOpenHashSet m = new ObjectOpenHashSet(Hash.DEFAULT_INITIAL_SIZE, f);
134 java.util.Set t = new java.util.HashSet();
141 final java.util.Set t = new java.util.HashSet();
135142 /* First of all, we fill t with random data. */
136143 for (int i = 0; i < f * n; i++)
137144 t.add((genKey()));
142149 printProbes(m);
143150 checkTable(m);
144151 /* Now we check that m actually holds that data. */
145 for (java.util.Iterator i = t.iterator(); i.hasNext();) {
146 Object e = i.next();
152 for (final Object e : t) {
147153 assertTrue("Error: m and t differ on a key (" + e + ") after insertion (iterating on t)", m.contains(e));
148154 }
149155 /* Now we check that m actually holds that data, but iterating on m. */
150156 c = 0;
151 for (java.util.Iterator i = m.iterator(); i.hasNext();) {
152 Object e = i.next();
157 for (final java.util.Iterator i = m.iterator(); i.hasNext();) {
158 final Object e = i.next();
153159 c++;
154160 assertTrue("Error: m and t differ on a key (" + e + ") after insertion (iterating on m)", t.contains(e));
155161 }
159165 * use the polymorphic method.
160166 */
161167 for (int i = 0; i < n; i++) {
162 Object T = genKey();
168 final Object T = genKey();
163169 assertTrue("Error: divergence in keys between t and m (polymorphic method)", m.contains(T) == t.contains((T)));
164170 }
165171 /*
167173 * m we use the standard method.
168174 */
169175 for (int i = 0; i < n; i++) {
170 Object T = genKey();
176 final Object T = genKey();
171177 assertTrue("Error: divergence between t and m (standard method)", m.contains((T)) == t.contains((T)));
172178 }
173179 /*
174180 * Check that addOrGet does indeed return the original instance, not a copy
175181 */
176 for (java.util.Iterator i = m.iterator(); i.hasNext();) {
177 Object e = i.next();
178 Object e2 = m.addOrGet(new StringBuilder((String)e).toString()); // Make a new object!
182 for (final java.util.Iterator i = m.iterator(); i.hasNext();) {
183 final Object e = i.next();
184 final Object e2 = m.addOrGet(new StringBuilder((String)e).toString()); // Make a new object!
179185 assertTrue("addOrGet does not return the same object", e == e2);
180186 }
181187 /* This should not have modified the table */
198204 /*
199205 * Now we check that m actually holds that data.
200206 */
201 for (java.util.Iterator i = t.iterator(); i.hasNext();) {
202 Object e = i.next();
207 for (final Object e : t) {
203208 assertTrue("Error: m and t differ on a key (" + e + ") after removal (iterating on t)", m.contains(e));
204209 }
205210 /* Now we check that m actually holds that data, but iterating on m. */
206 for (java.util.Iterator i = m.iterator(); i.hasNext();) {
207 Object e = i.next();
211 for (final java.util.Iterator i = m.iterator(); i.hasNext();) {
212 final Object e = i.next();
208213 assertTrue("Error: m and t differ on a key (" + e + ") after removal (iterating on m)", t.contains(e));
209214 }
210215 /* Now we make m into an array, make it again a set and check it is OK. */
211 Object a[] = m.toArray();
216 final Object a[] = m.toArray();
212217 assertTrue("Error: toArray() output (or array-based constructor) is not OK", new ObjectOpenHashSet(a).equals(m));
213218 /* Now we check cloning. */
214219 assertTrue("Error: m does not equal m.clone()", m.equals(m.clone()));
215220 assertTrue("Error: m.clone() does not equal m", m.clone().equals(m));
216 int h = m.hashCode();
221 final int h = m.hashCode();
217222 /* Now we save and read m. */
218223 try {
219 java.io.File ff = new java.io.File("it.unimi.dsi.fastutil.test.junit." + m.getClass().getSimpleName() + "." + n);
220 java.io.OutputStream os = new java.io.FileOutputStream(ff);
221 java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream(os);
224 final java.io.File ff = new java.io.File("it.unimi.dsi.fastutil.test.junit." + m.getClass().getSimpleName() + "." + n);
225 final java.io.OutputStream os = new java.io.FileOutputStream(ff);
226 final java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream(os);
222227 oos.writeObject(m);
223228 oos.close();
224 java.io.InputStream is = new java.io.FileInputStream(ff);
225 java.io.ObjectInputStream ois = new java.io.ObjectInputStream(is);
229 final java.io.InputStream is = new java.io.FileInputStream(ff);
230 final java.io.ObjectInputStream ois = new java.io.ObjectInputStream(is);
226231 m = (ObjectOpenHashSet)ois.readObject();
227232 ois.close();
228233 ff.delete();
229234 }
230 catch (Exception e) {
235 catch (final Exception e) {
231236 e.printStackTrace();
232237 System.exit(1);
233238 }
235240 checkTable(m);
236241 printProbes(m);
237242 /* Now we check that m actually holds that data, but iterating on m. */
238 for (java.util.Iterator i = m.iterator(); i.hasNext();) {
239 Object e = i.next();
243 for (final java.util.Iterator i = m.iterator(); i.hasNext();) {
244 final Object e = i.next();
240245 assertTrue("Error: m and t differ on a key (" + e + ") after save/read", t.contains(e));
241246 }
242247 /* Now we put and remove random data in m and t, checking that the result is the same. */
251256 /*
252257 * Now we take out of m everything , and check that it is empty.
253258 */
254 for (java.util.Iterator i = m.iterator(); i.hasNext();) {
259 for (final java.util.Iterator i = m.iterator(); i.hasNext();) {
255260 i.next();
256261 i.remove();
257262 }
291296 @Test
292297 public void testGet() {
293298 final ObjectOpenHashSet<String> s = new ObjectOpenHashSet<>();
294 String a = "a";
299 final String a = "a";
295300 assertTrue(s.add(a));
296301 assertSame(a, s.get("a"));
297302 assertNull(s.get("b"));