-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompression.diff
More file actions
193 lines (183 loc) · 6.56 KB
/
Copy pathcompression.diff
File metadata and controls
193 lines (183 loc) · 6.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
--- input/input.java
+++ output/output.java
@@ -338,40 +338,15 @@
private Integer getUid(Object obj) {
Integer uid = uids.get(obj);
if (uid == null) {
- // One or more integer values could be skipped in the event of a race
- // to generate a UID for the same object from multiple threads, but
- // that shouldn't be a problem.
- uid = counter.getAndIncrement();
- Integer alreadySet = uids.putIfAbsent(obj, uid);
- if (alreadySet != null) {
- uid = alreadySet;
- }
- }
+ { … 9 line(s) … ⟦tj:8150a12fd2e885edb4308b3d7161c001⟧ }
return uid;
- }
@Override
public int compare(@CheckForNull Object left, @CheckForNull Object right) {
if (left == right) {
return 0;
- } else if (left == null) {
- return -1;
- } else if (right == null) {
- return 1;
- }
- int leftCode = identityHashCode(left);
- int rightCode = identityHashCode(right);
- if (leftCode != rightCode) {
- return leftCode < rightCode ? -1 : 1;
- }
-
- // identityHashCode collision (rare, but not as rare as you'd think)
- int result = getUid(left).compareTo(getUid(right));
- if (result == 0) {
- throw new AssertionError(); // extremely, extremely unlikely.
- }
+ { … 16 line(s) … ⟦tj:118d26aaf906eb39936fc76f3f752618⟧ }
return result;
- }
@Override
public String toString() {
@@ -534,15 +509,7 @@
// Ordering<Iterable<String>> o =
// Ordering.<String>natural().lexicographical();
public <S extends T> Ordering<Iterable<S>> lexicographical() {
- /*
- * Note that technically the returned ordering should be capable of
- * handling not just {@code Iterable<S>} instances, but also any {@code
- * Iterable<? extends S>}. However, the need for this comes up so rarely
- * that it doesn't justify making everyone else deal with the very ugly
- * wildcard.
- */
- return new LexicographicalOrdering<S>(this);
- }
+ { … 9 line(s) … ⟦tj:dec53e9e0cca2fdf1b6f1afecad636d1⟧ }
// Regular instance methods
@@ -565,16 +532,8 @@
*/
@ParametricNullness
public <E extends T> E min(Iterator<E> iterator) {
- // let this throw NoSuchElementException as necessary
- E minSoFar = iterator.next();
+ { … 9 line(s) … ⟦tj:4ab0b3c00e685ff5bab378b835623a12⟧ }
- while (iterator.hasNext()) {
- minSoFar = this.<E>min(minSoFar, iterator.next());
- }
-
- return minSoFar;
- }
-
/**
* Returns the least of the specified values according to this ordering. If there are multiple
* least values, the first of those is returned.
@@ -656,15 +615,7 @@
*/
@ParametricNullness
public <E extends T> E max(Iterator<E> iterator) {
- // let this throw NoSuchElementException as necessary
- E maxSoFar = iterator.next();
-
- while (iterator.hasNext()) {
- maxSoFar = this.<E>max(maxSoFar, iterator.next());
- }
-
- return maxSoFar;
- }
+ { … 9 line(s) … ⟦tj:d4a4200263a3e56925268f9947e37a36⟧ }
/**
* Returns the greatest of the specified values according to this ordering. If there are multiple
@@ -751,22 +702,8 @@
public <E extends T> List<E> leastOf(Iterable<E> iterable, int k) {
if (iterable instanceof Collection) {
Collection<E> collection = (Collection<E>) iterable;
- if (collection.size() <= 2L * k) {
- // In this case, just dumping the collection to an array and sorting is
- // faster than using the implementation for Iterator, which is
- // specialized for k much smaller than n.
-
- @SuppressWarnings("unchecked") // c only contains E's and doesn't escape
- E[] array = (E[]) collection.toArray();
- Arrays.sort(array, this);
- if (array.length > k) {
- array = Arrays.copyOf(array, k);
- }
- return Collections.unmodifiableList(Arrays.asList(array));
- }
- }
+ { … 14 line(s) … ⟦tj:fec00b31c7c3098b50bd9ff1e4a9d1b1⟧ }
return leastOf(iterable.iterator(), k);
- }
/**
* Returns the {@code k} least elements from the given iterator according to this ordering, in
@@ -787,24 +724,8 @@
public <E extends T> List<E> leastOf(Iterator<E> iterator, int k) {
checkNotNull(iterator);
checkNonnegative(k, "k");
-
- if (k == 0 || !iterator.hasNext()) {
- return Collections.emptyList();
- } else if (k >= Integer.MAX_VALUE / 2) {
- // k is really large; just do a straightforward sorted-copy-and-sublist
- ArrayList<E> list = Lists.newArrayList(iterator);
- Collections.sort(list, this);
- if (list.size() > k) {
- list.subList(k, list.size()).clear();
- }
- list.trimToSize();
- return Collections.unmodifiableList(list);
- } else {
- TopKSelector<E> selector = TopKSelector.least(k, this);
- selector.offerAll(iterator);
- return selector.topK();
+ { … 16 line(s) … ⟦tj:d671efbf7f20d8ff9ceab6145e37f404⟧ }
}
- }
/**
* Returns the {@code k} greatest elements of the given iterable according to this ordering, in
@@ -904,17 +825,8 @@
public boolean isOrdered(Iterable<? extends T> iterable) {
Iterator<? extends T> it = iterable.iterator();
if (it.hasNext()) {
- T prev = it.next();
- while (it.hasNext()) {
- T next = it.next();
- if (compare(prev, next) > 0) {
- return false;
- }
- prev = next;
- }
- }
+ { … 9 line(s) … ⟦tj:35adc95f346373cbdc087d4c4f04f49b⟧ }
return true;
- }
/**
* Returns {@code true} if each element in {@code iterable} after the first is <i>strictly</i>
@@ -928,17 +840,8 @@
public boolean isStrictlyOrdered(Iterable<? extends T> iterable) {
Iterator<? extends T> it = iterable.iterator();
if (it.hasNext()) {
- T prev = it.next();
- while (it.hasNext()) {
- T next = it.next();
- if (compare(prev, next) >= 0) {
- return false;
- }
- prev = next;
- }
- }
+ { … 9 line(s) … ⟦tj:ef0241e4952715a5129d8307ab0f8fdf⟧ }
return true;
- }
/**
* {@link Collections#binarySearch(List, Object, Comparator) Searches} {@code sortedList} for
@@ -975,3 +878,6 @@
static final int LEFT_IS_GREATER = 1;
static final int RIGHT_IS_GREATER = -1;
}
+[omitted blocks are individually retrievable: call tinyjuice_retrieve with the token inside an omission marker to expand just that block]
+
+[PARTIAL view — full original (40352 bytes): call tinyjuice_retrieve with token "1b3ee3fd819be6c455f9cae2ef8b6f87"]
\ No newline at end of file