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
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 | ||
0 | 12 | 8.4.3 |
1 | 13 | |
2 | 14 | - Implemented andThen/compose methods for type-specific functions. |
8 | 20 | |
9 | 21 | - Static factory methods for immutable sets of primitive scalar types |
10 | 22 | within a given range. |
23 | ||
24 | - .of() factory methods for lists and sets. | |
11 | 25 | |
12 | 26 | 8.4.2 |
13 | 27 |
21 | 21 | |
22 | 22 | ## Building |
23 | 23 | |
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. | |
26 | 27 | |
27 | 28 | The Java sources are generated using a C preprocessor. The `gencsource.sh` |
28 | 29 | script reads in a driver file, that is, a Java source that uses some |
3 | 3 | |
4 | 4 | <property file="build.properties"/> |
5 | 5 | <property environment="env"/> |
6 | <property name="env.JAVA_HOME" value="/usr/java/latest"/> | |
7 | 6 | |
8 | 7 | <!-- ************************************** WARNING: MAVEN SH*T ************************************** --> |
9 | 8 | |
12 | 11 | <property name="artifactId" value="fastutil" /> |
13 | 12 | <property name="version" value="${version}" /> |
14 | 13 | |
14 | <!-- define artifacts' name, which follows the convention of Maven --> | |
15 | 15 | <property name="maven-jar" value="${dist}/lib/${artifactId}-${version}.jar" /> |
16 | ||
17 | <!-- define artifacts' name, which follows the convention of Maven --> | |
18 | ||
19 | 16 | <property name="maven-javadoc-jar" value="${dist}/lib/${artifactId}-${version}-javadoc.jar" /> |
20 | 17 | <property name="maven-sources-jar" value="${dist}/lib/${artifactId}-${version}-sources.jar" /> |
21 | 18 | |
33 | 30 | </target> |
34 | 31 | |
35 | 32 | <target name="osgi" depends="resolve,compile"> |
36 | <delete dir="${build}/*.class"/> | |
37 | 33 | <taskdef resource="aQute/bnd/ant/taskdef.properties" classpath="lib/bnd-2.4.0.jar"/> |
38 | 34 | <bnd |
39 | 35 | classpath="${build}" |
119 | 115 | <target name="init"> |
120 | 116 | <mkdir dir="${build}"/> |
121 | 117 | <mkdir dir="${dist}/lib"/> |
118 | <mkdir dir="${reports}"/> | |
122 | 119 | <symlink link="${dist}/javadoc" resource="../${docs}" overwrite="true"/> |
123 | 120 | </target> |
124 | 121 | |
128 | 125 | deprecation="on" |
129 | 126 | optimize="on" |
130 | 127 | destdir="${build}" |
131 | memoryInitialSize="800M" | |
132 | memoryMaximumSize="800M" | |
128 | memoryMaximumSize="2G" | |
133 | 129 | fork="yes" |
134 | 130 | source="1.8" |
135 | 131 | target="1.8"> |
142 | 138 | debug="on" |
143 | 139 | deprecation="on" |
144 | 140 | optimize="on" |
141 | classpath="lib/junit-4.13.jar:lib" | |
145 | 142 | destdir="${build}" |
146 | memoryInitialSize="800M" | |
147 | memoryMaximumSize="800M" | |
143 | memoryMaximumSize="2G" | |
148 | 144 | fork="yes" |
149 | 145 | source="1.8" |
150 | 146 | target="1.8" |
153 | 149 | |
154 | 150 | <target name="jar" depends="compile"> |
155 | 151 | <jar jarfile="fastutil-${version}.jar"> |
156 | <fileset dir="${build}" excludes="it/unimi/dsi/fastutil/*IndirectDoublePriorityQueue*"/> | |
152 | <fileset dir="${build}"/> | |
157 | 153 | <manifest> |
158 | 154 | <attribute name="Automatic-Module-Name" value="it.unimi.dsi.fastutil"/> |
159 | 155 | </manifest> |
162 | 158 | |
163 | 159 | <target name="jar-tests" depends="compile"> |
164 | 160 | <jar jarfile="fastutil-${version}.jar"> |
165 | <fileset dir="${build}" excludes="it/unimi/dsi/fastutil/*IndirectDoublePriorityQueue*"/> | |
161 | <fileset dir="${build}"/> | |
166 | 162 | </jar> |
167 | 163 | </target> |
168 | 164 | |
181 | 177 | public="on" |
182 | 178 | source="1.8" |
183 | 179 | windowtitle="fastutil ${version}" |
184 | additionalparam="-breakiterator -Xmaxwarns 10000" | |
185 | maxmemory="800M" | |
180 | additionalparam="-breakiterator -Xmaxwarns 10000 -tag "apiNote:a:API Notes:" -tag "implSpec:a:Implementation Specification:" -tag "implNote:a:Implementation Notes:\"" | |
181 | maxmemory="2G" | |
186 | 182 | > |
187 | 183 | <link href="${j2se.apiurl}"/> |
188 | 184 | </javadoc> |
192 | 188 | <junit printsummary="yes" fork="yes" haltonfailure="off" haltonerror="off"> |
193 | 189 | <classpath location="${build}"/> |
194 | 190 | <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> | |
196 | 196 | |
197 | 197 | <formatter type="xml"/> |
198 | 198 | <formatter type="plain"/> |
17 | 17 | package PACKAGE; |
18 | 18 | |
19 | 19 | import java.util.AbstractCollection; |
20 | ||
21 | #if KEYS_PRIMITIVE | |
22 | import java.util.Collection; | |
23 | #endif | |
20 | 24 | |
21 | 25 | /** An abstract class providing basic methods for collections implementing a type-specific interface. |
22 | 26 | * |
133 | 137 | if (add(i.NEXT_KEY())) retVal = true; |
134 | 138 | return retVal; |
135 | 139 | } |
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 | } | |
136 | 153 | |
137 | 154 | @Override |
138 | 155 | public boolean containsAll(final COLLECTION c) { |
139 | 156 | for(final KEY_ITERATOR i = c.iterator(); i.hasNext();) |
140 | 157 | if (! contains(i.NEXT_KEY())) return false; |
141 | 158 | 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); | |
142 | 172 | } |
143 | 173 | |
144 | 174 | @Override |
147 | 177 | for(final KEY_ITERATOR i = c.iterator(); i.hasNext();) |
148 | 178 | if (rem(i.NEXT_KEY())) retVal = true; |
149 | 179 | 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); | |
150 | 193 | } |
151 | 194 | |
152 | 195 | @Override |
159 | 202 | } |
160 | 203 | return retVal; |
161 | 204 | } |
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 | } | |
162 | 218 | #endif |
163 | 219 | |
164 | 220 | @Override |
95 | 95 | /** Adds all of the elements in the specified collection to this list (optional operation). */ |
96 | 96 | @Override |
97 | 97 | 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 | |
98 | 103 | ensureIndex(index); |
99 | 104 | final Iterator<? extends KEY_GENERIC_CLASS> i = c.iterator(); |
100 | 105 | final boolean retVal = i.hasNext(); |
40 | 40 | |
41 | 41 | Set<?> s = (Set<?>) o; |
42 | 42 | if (s.size() != size()) return false; |
43 | #if KEYS_PRIMITIVE | |
44 | if (s instanceof SET) { | |
45 | return containsAll((SET) s); | |
46 | } | |
47 | #endif | |
43 | 48 | return containsAll(s); |
44 | 49 | } |
45 | 50 |
279 | 279 | |
280 | 280 | public static KEY_GENERIC ARRAY_LIST KEY_GENERIC wrap(final KEY_GENERIC_TYPE a[]) { |
281 | 281 | 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); | |
282 | 294 | } |
283 | 295 | |
284 | 296 |
258 | 258 | |
259 | 259 | public static KEY_GENERIC BIG_ARRAY_BIG_LIST KEY_GENERIC wrap(final KEY_GENERIC_TYPE a[][]) { |
260 | 260 | 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)); | |
261 | 273 | } |
262 | 274 | |
263 | 275 |
56 | 56 | |
57 | 57 | /** A class providing static methods and objects that do useful things with {@linkplain BigArrays big arrays}. |
58 | 58 | * |
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 | |
60 | 60 | * {@link BigArrays}, as they can be imported statically in a more convenient way. |
61 | 61 | * |
62 | 62 | * <p>Note that {@link it.unimi.dsi.fastutil.io.BinIO} and {@link it.unimi.dsi.fastutil.io.TextIO} |
255 | 255 | |
256 | 256 | |
257 | 257 | #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) { \ | |
259 | 259 | return k -> after.G_A(GET_VALUE(k)); \ |
260 | 260 | } \ |
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) { \ | |
262 | 262 | return k -> GET_VALUE(before.G_B(k)); \ |
263 | 263 | } |
264 | 264 | |
272 | 272 | 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) |
273 | 273 | 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) |
274 | 274 | |
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 <<var>l</var>,<var>r</var>>. | |
100 | * | |
101 | * @return a string representation of this pair in the form <<var>l</var>,<var>r</var>>. | |
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 | }⏎ |
30 | 30 | * @param iterable an iterable. |
31 | 31 | * @return the number of elements returned by {@code iterable}. |
32 | 32 | */ |
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) { | |
34 | 34 | long c = 0; |
35 | 35 | for (@SuppressWarnings("unused") final KEY_GENERIC_TYPE dummy : iterable) c++; |
36 | 36 | return c; |
314 | 314 | |
315 | 315 | #endif |
316 | 316 | |
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 | |
318 | 329 | /** {@inheritDoc} |
319 | 330 | * @deprecated Please use the corresponding type-specific method instead. |
320 | 331 | */ |
329 | 340 | * <p>Pass {@code null} to sort using natural ordering. |
330 | 341 | * @see List#sort(java.util.Comparator) |
331 | 342 | * |
332 | * @implSpec The default implementation dumps the elements into an array using | |
343 | * @implNote The default implementation dumps the elements into an array using | |
333 | 344 | * {@link #toArray()}, sorts the array, then replaces all elements using the |
334 | 345 | * {@link #setElements} function. |
335 | 346 | * |
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 | |
337 | 348 | * determine that the results of a stable and unstable sort are completely equivalent. |
338 | 349 | * This means if you override {@link #unstableSort}, it should <em>not</em> call this |
339 | 350 | * method unless you override this method as well. |
381 | 392 | * <p>Unless a subclass specifies otherwise, the results of the method if the list is |
382 | 393 | * concurrently modified during the sort are unspecified. |
383 | 394 | * |
384 | * @implSpec The default implementation dumps the elements into an array using | |
395 | * @implNote The default implementation dumps the elements into an array using | |
385 | 396 | * {@link #toArray()}, sorts the array, then replaces all elements using the |
386 | 397 | * {@link #setElements} function. |
387 | 398 | * |
407 | 418 | * <p>Unless a subclass specifies otherwise, the results of the method if the list is |
408 | 419 | * concurrently modified during the sort are unspecified. |
409 | 420 | * |
410 | * @implSpec The default implementation dumps the elements into an array using | |
421 | * @implNote The default implementation dumps the elements into an array using | |
411 | 422 | * {@link #toArray()}, sorts the array, then replaces all elements using the |
412 | 423 | * {@link #setElements} function. |
413 | 424 | * |
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 <<var>l</var>,<var>r</var>>. | |
111 | * | |
112 | * @return a string representation of this pair in the form <<var>l</var>,<var>r</var>>. | |
113 | */ | |
114 | @Override | |
115 | public String toString() { | |
116 | return "<" + PAIR_LEFT() + "," + PAIR_RIGHT() + ">"; | |
117 | } | |
118 | } |
74 | 74 | * Rather, a family of {@linkplain #trim() trimming |
75 | 75 | * methods} lets you control the size of the table; this is particularly useful |
76 | 76 | * 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. | |
77 | 81 | * |
78 | 82 | * <p>Iterators generated by this map will enumerate pairs in the same order in which they |
79 | 83 | * have been added to the map (addition of pairs whose key is already present |
134 | 138 | * methods} lets you control the size of the table; this is particularly useful |
135 | 139 | * if you reuse instances of this class. |
136 | 140 | * |
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 | * | |
137 | 145 | * @see Hash |
138 | 146 | * @see HashCommon |
139 | 147 | */ |
159 | 167 | * methods} lets you control the size of the table; this is particularly useful |
160 | 168 | * if you reuse instances of this class. |
161 | 169 | * |
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 | * | |
162 | 174 | * @see Hash |
163 | 175 | * @see HashCommon |
164 | 176 | */ |
1265 | 1277 | * is necessary so that calls to {@link java.util.Map.Entry#setValue(Object)} are reflected in |
1266 | 1278 | * the map */ |
1267 | 1279 | |
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 { | |
1269 | 1281 | // The table index this entry refers to, or -1 if this entry has been deleted. |
1270 | 1282 | int index; |
1271 | 1283 | |
1281 | 1293 | } |
1282 | 1294 | |
1283 | 1295 | @Override |
1296 | public KEY_GENERIC_TYPE PAIR_LEFT() { | |
1297 | return key[index]; | |
1298 | } | |
1299 | ||
1300 | @Override | |
1284 | 1301 | public VALUE_GENERIC_TYPE ENTRY_GET_VALUE() { |
1302 | return value[index]; | |
1303 | } | |
1304 | ||
1305 | @Override | |
1306 | public VALUE_GENERIC_TYPE PAIR_RIGHT() { | |
1285 | 1307 | return value[index]; |
1286 | 1308 | } |
1287 | 1309 | |
1290 | 1312 | final VALUE_GENERIC_TYPE oldValue = value[index]; |
1291 | 1313 | value[index] = v; |
1292 | 1314 | 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; | |
1293 | 1321 | } |
1294 | 1322 | |
1295 | 1323 | #if KEYS_PRIMITIVE |
556 | 556 | public OPEN_HASH_SET(final KEY_GENERIC_TYPE[] a, final STRATEGY KEY_SUPER_GENERIC strategy) { |
557 | 557 | this(a, DEFAULT_LOAD_FACTOR, strategy); |
558 | 558 | } |
559 | ||
559 | 560 | #else |
560 | 561 | /** Creates a new hash set with {@link Hash#DEFAULT_LOAD_FACTOR} as load factor |
561 | 562 | * copying the elements of an array. |
565 | 566 | |
566 | 567 | public OPEN_HASH_SET(final KEY_GENERIC_TYPE[] a) { |
567 | 568 | 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); | |
568 | 580 | } |
569 | 581 | #endif |
570 | 582 |
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 | } |
94 | 94 | } |
95 | 95 | |
96 | 96 | #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 | ||
97 | 108 | } |
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 | }⏎ |
55 | 55 | VALUE_TYPE_CAP=Object # Just for filling holes |
56 | 56 | |
57 | 57 | if [[ "${rem:0:1}" == "2" ]]; then |
58 | isFunction=true | |
59 | 58 | rem=${rem:1} |
60 | 59 | rem2=${rem##[A-Z]+([a-z])} |
61 | 60 | valuelen=$(( ${#rem} - ${#rem2} )) |
62 | 61 | VALUE_TYPE_CAP=${rem:0:$valuelen} |
63 | 62 | 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} | |
66 | 69 | fi |
67 | 70 | |
68 | 71 | for((k=0; k<${#TYPE_CAP[*]}; k++)); do |
339 | 342 | "#define FUNCTION ${TYPE_CAP[$k]}2${TYPE_CAP[$v]}Function\n"\ |
340 | 343 | "#define MAP ${TYPE_CAP[$k]}2${TYPE_CAP[$v]}Map\n"\ |
341 | 344 | "#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"\ | |
342 | 355 | "#if KEYS_REFERENCE\n"\ |
343 | 356 | "#define STD_SORTED_MAP SortedMap\n"\ |
344 | 357 | "#define STRATEGY Strategy\n"\ |
361 | 374 | "#define KEY_LIST_ITERATOR ${TYPE_CAP2[$k]}ListIterator\n"\ |
362 | 375 | "#define KEY_BIG_LIST_ITERATOR ${TYPE_CAP2[$k]}BigListIterator\n"\ |
363 | 376 | "#define STD_KEY_ITERATOR ${TYPE_STD[$k]}Iterator\n"\ |
377 | "#define STD_KEY_ITERABLE ${TYPE_STD[$k]}Iterable\n"\ | |
364 | 378 | "#define KEY_COMPARATOR ${TYPE_STD[$k]}Comparator\n"\ |
365 | 379 | \ |
366 | 380 | \ |
513 | 527 | "#define FIRST_KEY first${TYPE_STD[$k]}Key\n"\ |
514 | 528 | "#define LAST_KEY last${TYPE_STD[$k]}Key\n"\ |
515 | 529 | "#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"\ | |
516 | 533 | "#define REMOVE_KEY remove${TYPE_STD[$k]}\n"\ |
517 | 534 | "#define READ_KEY read${TYPE_CAP2[$k]}\n"\ |
518 | 535 | "#define WRITE_KEY write${TYPE_CAP2[$k]}\n"\ |
548 | 565 | "#define ENTRY_GET_VALUE get${TYPE_STD[$v]}Value\n"\ |
549 | 566 | "#define REMOVE_FIRST_VALUE removeFirst${TYPE_STD[$v]}\n"\ |
550 | 567 | "#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"\ | |
551 | 571 | \ |
552 | 572 | \ |
553 | 573 | "/* Methods (keys/values) */\n"\ |
85 | 85 | fastutil-$(version)/LICENSE-2.0 \ |
86 | 86 | fastutil-$(version)/makefile \ |
87 | 87 | $(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 \ | |
90 | 90 | fastutil-$(version)/src/overview.html \ |
91 | 91 | $$(find fastutil-$(version)/test -iname \*.java) |
92 | 92 | rm fastutil-$(version) |
93 | 93 | |
94 | 94 | binary: |
95 | 95 | make -s clean sources format |
96 | ant clean osgi javadoc | |
96 | ant clean osgi jar javadoc | |
97 | 97 | -rm -f fastutil-$(version) |
98 | 98 | ln -s . fastutil-$(version) |
99 | 99 | cp dist/lib/fastutil-$(version).jar . |
111 | 111 | (sed -e s/VERSION/$$(grep version build.properties | cut -d= -f2)/ <pom-model.xml >pom.xml) |
112 | 112 | |
113 | 113 | 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} | |
115 | 115 | |
116 | 116 | stage: pom |
117 | 117 | (unset LOCAL_IVY_SETTINGS; ant stage) |
225 | 225 | |
226 | 226 | CSOURCES += $(BIG_LIST_ITERATORS) |
227 | 227 | |
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 | ||
228 | 239 | # |
229 | 240 | # Abstract implementations |
230 | 241 | # |
437 | 448 | $(ARRAY_INDIRECT_PRIORITY_QUEUES): drv/ArrayIndirectPriorityQueue.drv; ./gencsource.sh $< $@ >$@ |
438 | 449 | |
439 | 450 | 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) | |
440 | 466 | |
441 | 467 | |
442 | 468 | # |
601 | 627 | $(SOURCEDIR)/BigList.java \ |
602 | 628 | $(SOURCEDIR)/BigListIterator.java \ |
603 | 629 | $(SOURCEDIR)/PriorityQueue.java \ |
630 | $(SOURCEDIR)/Pair.java \ | |
631 | $(SOURCEDIR)/SortedPair.java \ | |
604 | 632 | $(SOURCEDIR)/IndirectPriorityQueue.java \ |
605 | 633 | $(SOURCEDIR)/Arrays.java \ |
606 | 634 | $(SOURCEDIR)/Swapper.java \ |
636 | 664 | -@find build -name \*.class -exec rm {} \; |
637 | 665 | -@find . -name \*.java~ -exec rm {} \; |
638 | 666 | -@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 | |
640 | 668 | -@rm -f $(GEN_SRCDIR)/$(PKG_PATH)/io/*IO.java |
641 | 669 | -@rm -f $(GEN_SRCDIR)/$(PKG_PATH)/BigArrays.java |
642 | 670 | -@rm -f $(GEN_SRCDIR)/$(PKG_PATH)/*.[chj] $(GEN_SRCDIR)/$(PKG_PATH)/*/*.[chj] |
643 | 671 | -@rm -fr $(DOCSDIR)/* |
644 | 672 | |
645 | 673 | sources: $(JSOURCES) |
674 | rm $(GEN_SRCDIR)/it/unimi/dsi/fastutil/objects/ObjectObjectPair.java | |
646 | 675 | |
647 | 676 | csources: $(CSOURCES) |
3 | 3 | <artifactId>fastutil</artifactId> |
4 | 4 | <packaging>jar</packaging> |
5 | 5 | <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> | |
8 | 8 | <url>http://fastutil.di.unimi.it/</url> |
9 | 9 | <licenses> |
10 | 10 | <license> |
21 | 21 | <developer> |
22 | 22 | <id>vigna</id> |
23 | 23 | <name>Sebastiano Vigna</name> |
24 | <email>vigna@di.unimi.it</email> | |
24 | <email>sebastiano.vigna@unimi.it</email> | |
25 | 25 | </developer> |
26 | 26 | </developers> |
27 | 27 | <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 <<var>l</var>, <var>r</var>>, 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 | <!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 | <!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 | <!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 | <!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 | <!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 | <!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 | <!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 | <!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 | <!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 | <!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> |
456 | 456 | <li>The standard entry-set iterators for hash-based maps use an entry object |
457 | 457 | that refers to the data contained in the hash table. If you retrieve an |
458 | 458 | 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 | |
460 | 460 | apply to fast iterators (see above).</li> |
461 | 461 | |
462 | 462 | <li>A name clash between the list and collection interfaces |
44 | 44 | import java.util.function.Supplier; |
45 | 45 | |
46 | 46 | import org.junit.Before; |
47 | import org.junit.Ignore; | |
47 | 48 | import org.junit.Test; |
48 | 49 | import org.junit.runner.RunWith; |
49 | 50 | import org.junit.runners.Parameterized; |
55 | 56 | import it.unimi.dsi.fastutil.objects.ObjectIterator; |
56 | 57 | import it.unimi.dsi.fastutil.objects.ObjectSet; |
57 | 58 | |
59 | @Ignore | |
58 | 60 | @RunWith(Parameterized.class) |
59 | 61 | @SuppressWarnings("deprecation") |
60 | 62 | public abstract class Int2IntMapGenericTest<M extends Int2IntMap> { |
45 | 45 | import java.util.function.Supplier; |
46 | 46 | |
47 | 47 | import org.junit.Before; |
48 | import org.junit.Ignore; | |
48 | 49 | import org.junit.Test; |
49 | 50 | import org.junit.runner.RunWith; |
50 | 51 | import org.junit.runners.Parameterized; |
57 | 58 | import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; |
58 | 59 | import it.unimi.dsi.fastutil.objects.ObjectSet; |
59 | 60 | |
61 | @Ignore | |
60 | 62 | @SuppressWarnings("deprecation") |
61 | 63 | @RunWith(Parameterized.class) |
62 | 64 | public abstract class Int2ObjectMapGenericTest<M extends Int2ObjectMap<Integer>> { |
50 | 50 | } |
51 | 51 | |
52 | 52 | @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 | |
53 | 73 | public void testRemoveAll() { |
54 | 74 | IntArrayList l = IntArrayList.wrap(new int[] { 0, 1, 1, 2 }); |
55 | 75 | l.removeAll(IntSets.singleton(1)); |
62 | 82 | |
63 | 83 | @Test |
64 | 84 | 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 }); | |
66 | 86 | l.sort(null); |
67 | 87 | assertEquals(IntArrayList.wrap(new int[] { 1, 2, 3, 4 }), l); |
68 | 88 | } |
127 | 147 | l.size(100); |
128 | 148 | } |
129 | 149 | |
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 | } | |
130 | 155 | } |
613 | 613 | final IntBigArrayBigList l = new IntBigArrayBigList(); |
614 | 614 | l.size(100); |
615 | 615 | } |
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 | } | |
616 | 622 | } |
55 | 55 | public void testEquals() { |
56 | 56 | final IntOpenHashSet s = new IntOpenHashSet(new int[] { 1, 2, 3 }); |
57 | 57 | 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 }))); | |
58 | 78 | } |
59 | 79 | |
60 | 80 | @Test |
279 | 299 | assertEquals(8, s.n); |
280 | 300 | } |
281 | 301 | |
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 | } | |
282 | 307 | |
283 | 308 | @SuppressWarnings("boxing") |
284 | 309 | private static void checkTable(final IntOpenHashSet s) { |
347 | 372 | |
348 | 373 | /* Now we check that m actually holds that data. */ |
349 | 374 | |
350 | for (final java.util.Iterator i = t.iterator(); i.hasNext();) { | |
351 | final Object e = i.next(); | |
375 | for (final Object e : t) { | |
352 | 376 | assertTrue("Error: m and t differ on a key (" + e + ") after insertion (iterating on t)", m.contains(e)); |
353 | 377 | } |
354 | 378 | |
397 | 421 | assertTrue("Error: !t.equals(m) after removal", t.equals(m)); |
398 | 422 | /* Now we check that m actually holds that data. */ |
399 | 423 | |
400 | for (final java.util.Iterator i = t.iterator(); i.hasNext();) { | |
401 | final Object e = i.next(); | |
424 | for (final Object e : t) { | |
402 | 425 | assertFalse("Error: m and t differ on a key (" + e + ") after removal (iterating on t)", !m.contains(e)); |
403 | 426 | } |
404 | 427 |
0 | 0 | package it.unimi.dsi.fastutil.ints; |
1 | ||
2 | import org.junit.Ignore; | |
1 | 3 | |
2 | 4 | /* |
3 | 5 | * Copyright (C) 2017-2020 Sebastiano Vigna |
16 | 18 | */ |
17 | 19 | |
18 | 20 | |
21 | @Ignore | |
19 | 22 | public class StripedInt2IntOpenHashMapTest { |
20 | 23 | // |
21 | 24 | // |
25 | 25 | import org.junit.Test; |
26 | 26 | |
27 | 27 | import it.unimi.dsi.fastutil.Hash; |
28 | import it.unimi.dsi.fastutil.longs.LongOpenHashSet; | |
28 | 29 | |
29 | 30 | @SuppressWarnings("rawtypes") |
30 | 31 | public class ObjectOpenHashSetTest { |
34 | 35 | @SuppressWarnings("boxing") |
35 | 36 | public void testStrangeRetainAllCase() { |
36 | 37 | |
37 | ObjectArrayList<Integer> initialElements = ObjectArrayList.wrap(new Integer[] { 586, 940, | |
38 | final ObjectArrayList<Integer> initialElements = ObjectArrayList.wrap(new Integer[] { 586, 940, | |
38 | 39 | 1086, 1110, 1168, 1184, 1185, 1191, 1196, 1229, 1237, 1241, |
39 | 40 | 1277, 1282, 1284, 1299, 1308, 1309, 1310, 1314, 1328, 1360, |
40 | 41 | 1366, 1370, 1378, 1388, 1392, 1402, 1406, 1411, 1426, 1437, |
56 | 57 | 7094, 7379, 7384, 7388, 7394, 7414, 7419, 7458, 7459, 7466, |
57 | 58 | 7467 }); |
58 | 59 | |
59 | ObjectArrayList<Integer> retainElements = ObjectArrayList.wrap(new Integer[] { 586 }); | |
60 | final ObjectArrayList<Integer> retainElements = ObjectArrayList.wrap(new Integer[] { 586 }); | |
60 | 61 | |
61 | 62 | // 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); | |
64 | 65 | |
65 | 66 | instance.retainAll(retainElements); |
66 | 67 | referenceInstance.retainAll(retainElements); |
75 | 76 | assertEquals(referenceInstance, instance); |
76 | 77 | } |
77 | 78 | |
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 | ||
78 | 85 | private static java.util.Random r = new java.util.Random(0); |
79 | 86 | |
80 | 87 | private static Object genKey() { |
81 | 88 | return Integer.toBinaryString(r.nextInt()); |
82 | 89 | } |
83 | 90 | |
84 | private static void checkTable(ObjectOpenHashSet<Integer> s) { | |
91 | private static void checkTable(final ObjectOpenHashSet<Integer> s) { | |
85 | 92 | final Object[] key = s.key; |
86 | 93 | assert (s.n & -s.n) == s.n : "Table length is not a power of two: " + s.n; |
87 | 94 | assert s.n == key.length - 1; |
93 | 100 | if (s.containsNull && ! s.contains(null)) throw new AssertionError("Hash table should contain null by internal state, but it doesn't when queried"); |
94 | 101 | if (! s.containsNull && s.contains(null)) throw new AssertionError("Hash table should not contain null by internal state, but it does when queried"); |
95 | 102 | |
96 | java.util.HashSet<String> t = new java.util.HashSet<>(); | |
103 | final java.util.HashSet<String> t = new java.util.HashSet<>(); | |
97 | 104 | for (int i = s.size(); i-- != 0;) |
98 | 105 | if (key[i] != null && !t.add((String)key[i])) throw new AssertionError("Key " + key[i] + " appears twice"); |
99 | 106 | |
100 | 107 | } |
101 | 108 | |
102 | private static void printProbes(ObjectOpenHashSet m) { | |
109 | private static void printProbes(final ObjectOpenHashSet m) { | |
103 | 110 | long totProbes = 0; |
104 | 111 | double totSquareProbes = 0; |
105 | 112 | int maxProbes = 0; |
128 | 135 | |
129 | 136 | |
130 | 137 | @SuppressWarnings("unchecked") |
131 | private static void test(int n, float f) { | |
138 | private static void test(final int n, final float f) { | |
132 | 139 | int c; |
133 | 140 | 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(); | |
135 | 142 | /* First of all, we fill t with random data. */ |
136 | 143 | for (int i = 0; i < f * n; i++) |
137 | 144 | t.add((genKey())); |
142 | 149 | printProbes(m); |
143 | 150 | checkTable(m); |
144 | 151 | /* 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) { | |
147 | 153 | assertTrue("Error: m and t differ on a key (" + e + ") after insertion (iterating on t)", m.contains(e)); |
148 | 154 | } |
149 | 155 | /* Now we check that m actually holds that data, but iterating on m. */ |
150 | 156 | 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(); | |
153 | 159 | c++; |
154 | 160 | assertTrue("Error: m and t differ on a key (" + e + ") after insertion (iterating on m)", t.contains(e)); |
155 | 161 | } |
159 | 165 | * use the polymorphic method. |
160 | 166 | */ |
161 | 167 | for (int i = 0; i < n; i++) { |
162 | Object T = genKey(); | |
168 | final Object T = genKey(); | |
163 | 169 | assertTrue("Error: divergence in keys between t and m (polymorphic method)", m.contains(T) == t.contains((T))); |
164 | 170 | } |
165 | 171 | /* |
167 | 173 | * m we use the standard method. |
168 | 174 | */ |
169 | 175 | for (int i = 0; i < n; i++) { |
170 | Object T = genKey(); | |
176 | final Object T = genKey(); | |
171 | 177 | assertTrue("Error: divergence between t and m (standard method)", m.contains((T)) == t.contains((T))); |
172 | 178 | } |
173 | 179 | /* |
174 | 180 | * Check that addOrGet does indeed return the original instance, not a copy |
175 | 181 | */ |
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! | |
179 | 185 | assertTrue("addOrGet does not return the same object", e == e2); |
180 | 186 | } |
181 | 187 | /* This should not have modified the table */ |
198 | 204 | /* |
199 | 205 | * Now we check that m actually holds that data. |
200 | 206 | */ |
201 | for (java.util.Iterator i = t.iterator(); i.hasNext();) { | |
202 | Object e = i.next(); | |
207 | for (final Object e : t) { | |
203 | 208 | assertTrue("Error: m and t differ on a key (" + e + ") after removal (iterating on t)", m.contains(e)); |
204 | 209 | } |
205 | 210 | /* 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(); | |
208 | 213 | assertTrue("Error: m and t differ on a key (" + e + ") after removal (iterating on m)", t.contains(e)); |
209 | 214 | } |
210 | 215 | /* 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(); | |
212 | 217 | assertTrue("Error: toArray() output (or array-based constructor) is not OK", new ObjectOpenHashSet(a).equals(m)); |
213 | 218 | /* Now we check cloning. */ |
214 | 219 | assertTrue("Error: m does not equal m.clone()", m.equals(m.clone())); |
215 | 220 | assertTrue("Error: m.clone() does not equal m", m.clone().equals(m)); |
216 | int h = m.hashCode(); | |
221 | final int h = m.hashCode(); | |
217 | 222 | /* Now we save and read m. */ |
218 | 223 | 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); | |
222 | 227 | oos.writeObject(m); |
223 | 228 | 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); | |
226 | 231 | m = (ObjectOpenHashSet)ois.readObject(); |
227 | 232 | ois.close(); |
228 | 233 | ff.delete(); |
229 | 234 | } |
230 | catch (Exception e) { | |
235 | catch (final Exception e) { | |
231 | 236 | e.printStackTrace(); |
232 | 237 | System.exit(1); |
233 | 238 | } |
235 | 240 | checkTable(m); |
236 | 241 | printProbes(m); |
237 | 242 | /* 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(); | |
240 | 245 | assertTrue("Error: m and t differ on a key (" + e + ") after save/read", t.contains(e)); |
241 | 246 | } |
242 | 247 | /* Now we put and remove random data in m and t, checking that the result is the same. */ |
251 | 256 | /* |
252 | 257 | * Now we take out of m everything , and check that it is empty. |
253 | 258 | */ |
254 | for (java.util.Iterator i = m.iterator(); i.hasNext();) { | |
259 | for (final java.util.Iterator i = m.iterator(); i.hasNext();) { | |
255 | 260 | i.next(); |
256 | 261 | i.remove(); |
257 | 262 | } |
291 | 296 | @Test |
292 | 297 | public void testGet() { |
293 | 298 | final ObjectOpenHashSet<String> s = new ObjectOpenHashSet<>(); |
294 | String a = "a"; | |
299 | final String a = "a"; | |
295 | 300 | assertTrue(s.add(a)); |
296 | 301 | assertSame(a, s.get("a")); |
297 | 302 | assertNull(s.get("b")); |