-
Notifications
You must be signed in to change notification settings - Fork 391
/
Int2ObjectHashMap.java
1148 lines (987 loc) · 29 KB
/
Int2ObjectHashMap.java
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2014-2020 Real Logic Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.agrona.collections;
import org.agrona.generation.DoNotSub;
import java.io.Serializable;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.IntFunction;
import static java.util.Objects.requireNonNull;
import static org.agrona.BitUtil.findNextPositivePowerOfTwo;
import static org.agrona.collections.CollectionUtil.validateLoadFactor;
/**
* {@link java.util.Map} implementation specialised for int keys using open addressing and
* linear probing for cache efficient access.
*
* @param <V> type of values stored in the {@link java.util.Map}
*/
public class Int2ObjectHashMap<V>
implements Map<Integer, V>, Serializable
{
@DoNotSub static final int MIN_CAPACITY = 8;
private final float loadFactor;
@DoNotSub private int resizeThreshold;
@DoNotSub private int size;
private final boolean shouldAvoidAllocation;
private int[] keys;
private Object[] values;
private ValueCollection valueCollection;
private KeySet keySet;
private EntrySet entrySet;
/**
* Constructs map with {@link #MIN_CAPACITY}, {@link Hashing#DEFAULT_LOAD_FACTOR} and enables caching of iterators.
*/
public Int2ObjectHashMap()
{
this(MIN_CAPACITY, Hashing.DEFAULT_LOAD_FACTOR, true);
}
/**
* Constructs map with given initial capacity and load factory and enables caching of iterators.
*
* @param initialCapacity for the backing array
* @param loadFactor limit for resizing on puts
*/
public Int2ObjectHashMap(
@DoNotSub final int initialCapacity,
final float loadFactor)
{
this(initialCapacity, loadFactor, true);
}
/**
* Construct a new map allowing a configuration for initial capacity and load factor.
*
* @param initialCapacity for the backing array
* @param loadFactor limit for resizing on puts
* @param shouldAvoidAllocation should allocation be avoided by caching iterators and map entries.
*/
public Int2ObjectHashMap(
@DoNotSub final int initialCapacity,
final float loadFactor,
final boolean shouldAvoidAllocation)
{
validateLoadFactor(loadFactor);
this.loadFactor = loadFactor;
this.shouldAvoidAllocation = shouldAvoidAllocation;
/* @DoNotSub */ final int capacity = findNextPositivePowerOfTwo(Math.max(MIN_CAPACITY, initialCapacity));
/* @DoNotSub */ resizeThreshold = (int)(capacity * loadFactor);
keys = new int[capacity];
values = new Object[capacity];
}
/**
* Copy construct a new map from an existing one.
*
* @param mapToCopy for construction.
*/
public Int2ObjectHashMap(final Int2ObjectHashMap<V> mapToCopy)
{
this.loadFactor = mapToCopy.loadFactor;
this.resizeThreshold = mapToCopy.resizeThreshold;
this.size = mapToCopy.size;
this.shouldAvoidAllocation = mapToCopy.shouldAvoidAllocation;
keys = mapToCopy.keys.clone();
values = mapToCopy.values.clone();
}
/**
* Get the load factor beyond which the map will increase size.
*
* @return load factor for when the map should increase size.
*/
public float loadFactor()
{
return loadFactor;
}
/**
* Get the total capacity for the map to which the load factor will be a fraction of.
*
* @return the total capacity for the map.
*/
@DoNotSub public int capacity()
{
return values.length;
}
/**
* Get the actual threshold which when reached the map will resize.
* This is a function of the current capacity and load factor.
*
* @return the threshold when the map will resize.
*/
@DoNotSub public int resizeThreshold()
{
return resizeThreshold;
}
/**
* {@inheritDoc}
*/
@DoNotSub public int size()
{
return size;
}
/**
* {@inheritDoc}
*/
public boolean isEmpty()
{
return 0 == size;
}
/**
* {@inheritDoc}
*/
public boolean containsKey(final Object key)
{
return containsKey(((Integer)key).intValue());
}
/**
* Overloaded version of {@link Map#containsKey(Object)} that takes a primitive int key.
*
* @param key for indexing the {@link Map}
* @return true if the key is found otherwise false.
*/
public boolean containsKey(final int key)
{
@DoNotSub final int mask = values.length - 1;
@DoNotSub int index = Hashing.hash(key, mask);
boolean found = false;
while (null != values[index])
{
if (key == keys[index])
{
found = true;
break;
}
index = ++index & mask;
}
return found;
}
/**
* {@inheritDoc}
*/
public boolean containsValue(final Object value)
{
boolean found = false;
final Object val = mapNullValue(value);
if (null != val)
{
@DoNotSub int remaining =
Int2ObjectHashMap.this.size;
for (@DoNotSub int i = 0, length = values.length; remaining > 0 && i < length; i++)
{
if (null != values[i])
{
if (val.equals(values[i]))
{
found = true;
break;
}
--remaining;
}
}
}
return found;
}
/**
* {@inheritDoc}
*/
public V get(final Object key)
{
return get(((Integer)key).intValue());
}
/**
* Overloaded version of {@link Map#get(Object)} that takes a primitive int key.
*
* @param key for indexing the {@link Map}
* @return the value if found otherwise null
*/
public V get(final int key)
{
return unmapNullValue(getMapped(key));
}
/**
* Get mapped value without boxing the key.
*
* @param key to get value by.
* @return mapped value or {@code null}.
*/
@SuppressWarnings("unchecked")
protected V getMapped(final int key)
{
@DoNotSub final int mask = values.length - 1;
@DoNotSub int index = Hashing.hash(key, mask);
Object value;
while (null != (value = values[index]))
{
if (key == keys[index])
{
break;
}
index = ++index & mask;
}
return (V)value;
}
/**
* Get a value for a given key, or if it does not exist then default the value via a
* {@link java.util.function.IntFunction} and put it in the map.
* <p>
* Primitive specialized version of {@link java.util.Map#computeIfAbsent}.
*
* @param key to search on.
* @param mappingFunction to provide a value if the get returns null.
* @return the value if found otherwise the default.
*/
public V computeIfAbsent(final int key, final IntFunction<? extends V> mappingFunction)
{
V value = getMapped(key);
if (value == null)
{
value = mappingFunction.apply(key);
if (value != null)
{
put(key, value);
}
}
else
{
value = unmapNullValue(value);
}
return value;
}
/**
* {@inheritDoc}
*/
public V put(final Integer key, final V value)
{
return put(key.intValue(), value);
}
/**
* Overloaded version of {@link Map#put(Object, Object)} that takes a primitive int key.
*
* @param key for indexing the {@link Map}
* @param value to be inserted in the {@link Map}
* @return the previous value if found otherwise null
*/
@SuppressWarnings("unchecked")
public V put(final int key, final V value)
{
final V val = (V)mapNullValue(value);
requireNonNull(val, "value cannot be null");
V oldValue = null;
@DoNotSub final int mask = values.length - 1;
@DoNotSub int index = Hashing.hash(key, mask);
while (null != values[index])
{
if (key == keys[index])
{
oldValue = (V)values[index];
break;
}
index = ++index & mask;
}
if (null == oldValue)
{
++size;
keys[index] = key;
}
values[index] = val;
if (size > resizeThreshold)
{
increaseCapacity();
}
return unmapNullValue(oldValue);
}
/**
* {@inheritDoc}
*/
public V remove(final Object key)
{
return remove(((Integer)key).intValue());
}
/**
* Overloaded version of {@link Map#remove(Object)} that takes a primitive int key.
*
* @param key for indexing the {@link Map}
* @return the value if found otherwise null
*/
public V remove(final int key)
{
@DoNotSub final int mask = values.length - 1;
@DoNotSub int index = Hashing.hash(key, mask);
Object value;
while (null != (value = values[index]))
{
if (key == keys[index])
{
values[index] = null;
--size;
compactChain(index);
break;
}
index = ++index & mask;
}
return unmapNullValue(value);
}
/**
* {@inheritDoc}
*/
public void clear()
{
if (size > 0)
{
Arrays.fill(values, null);
size = 0;
}
}
/**
* Compact the {@link Map} backing arrays by rehashing with a capacity just larger than current size
* and giving consideration to the load factor.
*/
public void compact()
{
@DoNotSub final int idealCapacity = (int)Math.round(size() * (1.0d / loadFactor));
rehash(findNextPositivePowerOfTwo(Math.max(MIN_CAPACITY, idealCapacity)));
}
/**
* {@inheritDoc}
*/
public void putAll(final Map<? extends Integer, ? extends V> map)
{
for (final Entry<? extends Integer, ? extends V> entry : map.entrySet())
{
put(entry.getKey(), entry.getValue());
}
}
/**
* {@inheritDoc}
*/
public KeySet keySet()
{
if (null == keySet)
{
keySet = new KeySet();
}
return keySet;
}
/**
* {@inheritDoc}
*/
public ValueCollection values()
{
if (null == valueCollection)
{
valueCollection = new ValueCollection();
}
return valueCollection;
}
/**
* {@inheritDoc}
*/
public EntrySet entrySet()
{
if (null == entrySet)
{
entrySet = new EntrySet();
}
return entrySet;
}
/**
* {@inheritDoc}
*/
public String toString()
{
if (isEmpty())
{
return "{}";
}
final EntryIterator entryIterator = new EntryIterator();
entryIterator.reset();
final StringBuilder sb = new StringBuilder().append('{');
while (true)
{
entryIterator.next();
sb.append(entryIterator.getIntKey()).append('=').append(unmapNullValue(entryIterator.getValue()));
if (!entryIterator.hasNext())
{
return sb.append('}').toString();
}
sb.append(',').append(' ');
}
}
/**
* {@inheritDoc}
*/
public boolean equals(final Object o)
{
if (this == o)
{
return true;
}
if (!(o instanceof Map))
{
return false;
}
final Map<?, ?> that = (Map<?, ?>)o;
if (size != that.size())
{
return false;
}
for (@DoNotSub int i = 0, length = values.length; i < length; i++)
{
final Object thisValue = values[i];
if (null != thisValue)
{
final Object thatValue = that.get(keys[i]);
if (!thisValue.equals(mapNullValue(thatValue)))
{
return false;
}
}
}
return true;
}
/**
* {@inheritDoc}
*/
@DoNotSub public int hashCode()
{
@DoNotSub int result = 0;
for (@DoNotSub int i = 0, length = values.length; i < length; i++)
{
final Object value = values[i];
if (null != value)
{
result += (Integer.hashCode(keys[i]) ^ value.hashCode());
}
}
return result;
}
/**
* Interceptor for masking null values.
*
* @param value value to mask.
* @return masked value.
*/
protected Object mapNullValue(final Object value)
{
return value;
}
/**
* Interceptor for unmasking null values.
*
* @param value value to unmask.
* @return unmasked value.
*/
@SuppressWarnings("unchecked")
protected V unmapNullValue(final Object value)
{
return (V)value;
}
/**
* Primitive specialised version of {@link #replace(Object, Object)}
*
* @param key key with which the specified value is associated
* @param value value to be associated with the specified key
* @return the previous value associated with the specified key, or
* {@code null} if there was no mapping for the key.
*/
public V replace(final int key, final V value)
{
V currentValue = get(key);
if (currentValue != null)
{
currentValue = put(key, value);
}
return currentValue;
}
/**
* Primitive specialised version of {@link #replace(Object, Object, Object)}
*
* @param key key with which the specified value is associated
* @param oldValue value expected to be associated with the specified key
* @param newValue value to be associated with the specified key
* @return {@code true} if the value was replaced
*/
public boolean replace(final int key, final V oldValue, final V newValue)
{
final Object curValue = get(key);
if (curValue == null || !Objects.equals(unmapNullValue(curValue), oldValue))
{
return false;
}
put(key, newValue);
return true;
}
private void increaseCapacity()
{
@DoNotSub final int newCapacity = values.length << 1;
if (newCapacity < 0)
{
throw new IllegalStateException("max capacity reached at size=" + size);
}
rehash(newCapacity);
}
private void rehash(@DoNotSub final int newCapacity)
{
@DoNotSub final int mask = newCapacity - 1;
/* @DoNotSub */ resizeThreshold = (int)(newCapacity * loadFactor);
final int[] tempKeys = new int[newCapacity];
final Object[] tempValues = new Object[newCapacity];
for (@DoNotSub int i = 0, size = values.length; i < size; i++)
{
final Object value = values[i];
if (null != value)
{
final int key = keys[i];
@DoNotSub int index = Hashing.hash(key, mask);
while (null != tempValues[index])
{
index = ++index & mask;
}
tempKeys[index] = key;
tempValues[index] = value;
}
}
keys = tempKeys;
values = tempValues;
}
@SuppressWarnings("FinalParameters")
private void compactChain(@DoNotSub int deleteIndex)
{
@DoNotSub final int mask = values.length - 1;
@DoNotSub int index = deleteIndex;
while (true)
{
index = ++index & mask;
if (null == values[index])
{
break;
}
@DoNotSub final int hash = Hashing.hash(keys[index], mask);
if ((index < hash && (hash <= deleteIndex || deleteIndex <= index)) ||
(hash <= deleteIndex && deleteIndex <= index))
{
keys[deleteIndex] = keys[index];
values[deleteIndex] = values[index];
values[index] = null;
deleteIndex = index;
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
// Sets and Collections
///////////////////////////////////////////////////////////////////////////////////////////////
/**
* Set of keys which supports optionally cached iterators to avoid allocation.
*/
public final class KeySet extends AbstractSet<Integer> implements Serializable
{
private final KeyIterator keyIterator = shouldAvoidAllocation ? new KeyIterator() : null;
/**
* {@inheritDoc}
*/
public KeyIterator iterator()
{
KeyIterator keyIterator = this.keyIterator;
if (null == keyIterator)
{
keyIterator = new KeyIterator();
}
keyIterator.reset();
return keyIterator;
}
@DoNotSub public int size()
{
return Int2ObjectHashMap.this.size();
}
public boolean contains(final Object o)
{
return Int2ObjectHashMap.this.containsKey(o);
}
/**
* Checks if the key is contained in the map.
*
* @param key to check.
* @return {@code true} if the key is contained in the map.
*/
public boolean contains(final int key)
{
return Int2ObjectHashMap.this.containsKey(key);
}
public boolean remove(final Object o)
{
return null != Int2ObjectHashMap.this.remove(o);
}
/**
* Removes key and the corresponding value from the map.
*
* @param key to be removed.
* @return {@code true} if the mapping was removed.
*/
public boolean remove(final int key)
{
return null != Int2ObjectHashMap.this.remove(key);
}
public void clear()
{
Int2ObjectHashMap.this.clear();
}
}
/**
* Collection of values which supports optionally cached iterators to avoid allocation.
*/
public final class ValueCollection extends AbstractCollection<V> implements Serializable
{
private final ValueIterator valueIterator = shouldAvoidAllocation ? new ValueIterator() : null;
/**
* {@inheritDoc}
*/
public ValueIterator iterator()
{
ValueIterator valueIterator = this.valueIterator;
if (null == valueIterator)
{
valueIterator = new ValueIterator();
}
valueIterator.reset();
return valueIterator;
}
@DoNotSub public int size()
{
return Int2ObjectHashMap.this.size();
}
public boolean contains(final Object o)
{
return Int2ObjectHashMap.this.containsValue(o);
}
public void clear()
{
Int2ObjectHashMap.this.clear();
}
public void forEach(final Consumer<? super V> action)
{
@DoNotSub int remaining =
Int2ObjectHashMap.this.size;
for (@DoNotSub int i = 0, length = values.length; remaining > 0 && i < length; i++)
{
if (null != values[i])
{
action.accept(unmapNullValue(values[i]));
--remaining;
}
}
}
}
/**
* Set of entries which supports access via an optionally cached iterator to avoid allocation.
*/
public final class EntrySet extends AbstractSet<Map.Entry<Integer, V>> implements Serializable
{
private final EntryIterator entryIterator = shouldAvoidAllocation ? new EntryIterator() : null;
/**
* {@inheritDoc}
*/
public EntryIterator iterator()
{
EntryIterator entryIterator = this.entryIterator;
if (null == entryIterator)
{
entryIterator = new EntryIterator();
}
entryIterator.reset();
return entryIterator;
}
@DoNotSub public int size()
{
return Int2ObjectHashMap.this.size();
}
public void clear()
{
Int2ObjectHashMap.this.clear();
}
/**
* {@inheritDoc}
*/
public boolean contains(final Object o)
{
if (!(o instanceof Entry))
{
return false;
}
final Entry<?, ?> entry = (Entry<?, ?>)o;
final int key = (Integer)entry.getKey();
final V value = getMapped(key);
return value != null && value.equals(mapNullValue(entry.getValue()));
}
/**
* {@inheritDoc}
*/
public Object[] toArray()
{
return toArray(new Object[size()]);
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public <T> T[] toArray(final T[] a)
{
final T[] array = a.length >= size ?
a : (T[])java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size);
final EntryIterator it = iterator();
for (@DoNotSub int i = 0; i < array.length; i++)
{
if (it.hasNext())
{
it.next();
array[i] = (T)it.allocateDuplicateEntry();
}
else
{
array[i] = null;
break;
}
}
return array;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
// Iterators
///////////////////////////////////////////////////////////////////////////////////////////////
/**
* Base iterator implementation that contains basic logic of traversing the element in the backing array.
*
* @param <T> type of elements.
*/
abstract class AbstractIterator<T> implements Iterator<T>, Serializable
{
@DoNotSub private int posCounter;
@DoNotSub private int stopCounter;
@DoNotSub private int remaining;
boolean isPositionValid = false;
/**
* Position of the current element.
*
* @return position of the current element.
*/
@DoNotSub protected final int position()
{
return posCounter & (values.length - 1);
}
/**
* Number of remaining elements.
*
* @return number of remaining elements.
*/
@DoNotSub public int remaining()
{
return remaining;
}
public boolean hasNext()
{
return remaining > 0;
}
/**
* Find the next element.
*
* @throws NoSuchElementException if no more elements.
*/
protected final void findNext()
{
if (!hasNext())
{
throw new NoSuchElementException();
}
final Object[] values = Int2ObjectHashMap.this.values;
@DoNotSub final int mask = values.length - 1;
for (@DoNotSub int i = posCounter - 1; i >= stopCounter; i--)
{
@DoNotSub final int index = i & mask;
if (null != values[index])
{
posCounter = i;
isPositionValid = true;
--remaining;
return;
}
}
isPositionValid = false;
throw new IllegalStateException();
}
public abstract T next();
public void remove()
{
if (isPositionValid)
{
@DoNotSub final int position = position();
values[position] = null;
--size;
compactChain(position);
isPositionValid = false;
}
else
{
throw new IllegalStateException();
}
}
final void reset()
{
remaining = Int2ObjectHashMap.this.size;
final Object[] values = Int2ObjectHashMap.this.values;
@DoNotSub final int capacity = values.length;
@DoNotSub int i = capacity;
if (null != values[capacity - 1])
{
for (i = 0; i < capacity; i++)
{
if (null == values[i])
{
break;
}
}
}
stopCounter = i;
posCounter = i + capacity;
isPositionValid = false;
}
}
/**
* Iterator over values.
*/
public class ValueIterator extends AbstractIterator<V>
{
public V next()
{