-
Notifications
You must be signed in to change notification settings - Fork 391
/
Int2IntHashMap.java
1273 lines (1104 loc) · 32 KB
/
Int2IntHashMap.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-2021 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.util.*;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.IntUnaryOperator;
import static org.agrona.BitUtil.findNextPositivePowerOfTwo;
import static org.agrona.collections.CollectionUtil.validateLoadFactor;
/**
* An open-addressing with linear probing hash map specialised for primitive key and value pairs.
*/
public class Int2IntHashMap implements Map<Integer, Integer>
{
@DoNotSub static final int MIN_CAPACITY = 8;
private final float loadFactor;
private final int missingValue;
@DoNotSub private int resizeThreshold;
@DoNotSub private int size = 0;
private final boolean shouldAvoidAllocation;
private int[] entries;
private KeySet keySet;
private ValueCollection values;
private EntrySet entrySet;
/**
* @param missingValue for the map that represents null.
*/
public Int2IntHashMap(final int missingValue)
{
this(MIN_CAPACITY, Hashing.DEFAULT_LOAD_FACTOR, missingValue);
}
/**
* @param initialCapacity for the map to override {@link #MIN_CAPACITY}
* @param loadFactor for the map to override {@link Hashing#DEFAULT_LOAD_FACTOR}.
* @param missingValue for the map that represents null.
*/
public Int2IntHashMap(
@DoNotSub final int initialCapacity,
@DoNotSub final float loadFactor,
final int missingValue)
{
this(initialCapacity, loadFactor, missingValue, true);
}
/**
* @param initialCapacity for the map to override {@link #MIN_CAPACITY}
* @param loadFactor for the map to override {@link Hashing#DEFAULT_LOAD_FACTOR}.
* @param missingValue for the map that represents null.
* @param shouldAvoidAllocation should allocation be avoided by caching iterators and map entries.
*/
public Int2IntHashMap(
@DoNotSub final int initialCapacity,
@DoNotSub final float loadFactor,
final int missingValue,
final boolean shouldAvoidAllocation)
{
validateLoadFactor(loadFactor);
this.loadFactor = loadFactor;
this.missingValue = missingValue;
this.shouldAvoidAllocation = shouldAvoidAllocation;
capacity(findNextPositivePowerOfTwo(Math.max(MIN_CAPACITY, initialCapacity)));
}
/**
* The value to be used as a null marker in the map.
*
* @return value to be used as a null marker in the map.
*/
public int missingValue()
{
return missingValue;
}
/**
* Get the load factor applied for resize operations.
*
* @return the load factor applied for resize operations.
*/
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 entries.length >> 1;
}
/**
* 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 size == 0;
}
/**
* Get a value using provided key avoiding boxing.
*
* @param key lookup key.
* @return value associated with the key or {@link #missingValue()} if key is not found in the map.
*/
public int get(final int key)
{
@DoNotSub final int mask = entries.length - 1;
@DoNotSub int index = Hashing.evenHash(key, mask);
int value = missingValue;
while (entries[index + 1] != missingValue)
{
if (entries[index] == key)
{
value = entries[index + 1];
break;
}
index = next(index, mask);
}
return value;
}
/**
* Put a key value pair in the map.
*
* @param key lookup key
* @param value new value, must not be {@link #missingValue()}
* @return previous value associated with the key, or {@link #missingValue()} if none found
* @throws IllegalArgumentException if value is {@link #missingValue()}
*/
public int put(final int key, final int value)
{
if (value == missingValue)
{
throw new IllegalArgumentException("cannot accept missingValue");
}
@DoNotSub final int mask = entries.length - 1;
@DoNotSub int index = Hashing.evenHash(key, mask);
int oldValue = missingValue;
while (entries[index + 1] != missingValue)
{
if (entries[index] == key)
{
oldValue = entries[index + 1];
break;
}
index = next(index, mask);
}
if (oldValue == missingValue)
{
++size;
entries[index] = key;
}
entries[index + 1] = value;
increaseCapacity();
return oldValue;
}
private void increaseCapacity()
{
if (size > resizeThreshold)
{
// entries.length = 2 * capacity
@DoNotSub final int newCapacity = entries.length;
rehash(newCapacity);
}
}
private void rehash(@DoNotSub final int newCapacity)
{
final int[] oldEntries = entries;
@DoNotSub final int length = entries.length;
capacity(newCapacity);
final int[] newEntries = entries;
@DoNotSub final int mask = entries.length - 1;
for (@DoNotSub int keyIndex = 0; keyIndex < length; keyIndex += 2)
{
final int value = oldEntries[keyIndex + 1];
if (value != missingValue)
{
final int key = oldEntries[keyIndex];
@DoNotSub int index = Hashing.evenHash(key, mask);
while (newEntries[index + 1] != missingValue)
{
index = next(index, mask);
}
newEntries[index] = key;
newEntries[index + 1] = value;
}
}
}
/**
* Primitive specialised forEach implementation.
* <p>
* NB: Renamed from forEach to avoid overloading on parameter types of lambda
* expression, which doesn't play well with type inference in lambda expressions.
*
* @param consumer a callback called for each key/value pair in the map.
*/
public void intForEach(final IntIntConsumer consumer)
{
@DoNotSub final int length = entries.length;
@DoNotSub int remaining = size;
for (@DoNotSub int valueIndex = 1; remaining > 0 && valueIndex < length; valueIndex += 2)
{
if (entries[valueIndex] != missingValue)
{
consumer.accept(entries[valueIndex - 1], entries[valueIndex]);
--remaining;
}
}
}
/**
* Int primitive specialised containsKey.
*
* @param key the key to check.
* @return true if the map contains key as a key, false otherwise.
*/
public boolean containsKey(final int key)
{
return get(key) != missingValue;
}
/**
* Does the map contain the value.
*
* @param value to be tested against contained values.
* @return true if contained otherwise value.
*/
public boolean containsValue(final int value)
{
boolean found = false;
if (value != missingValue)
{
@DoNotSub final int length = entries.length;
@DoNotSub int remaining = size;
for (@DoNotSub int valueIndex = 1; remaining > 0 && valueIndex < length; valueIndex += 2)
{
if (missingValue != entries[valueIndex])
{
if (value == entries[valueIndex])
{
found = true;
break;
}
--remaining;
}
}
}
return found;
}
/**
* {@inheritDoc}
*/
public void clear()
{
if (size > 0)
{
Arrays.fill(entries, missingValue);
size = 0;
}
}
/**
* Compact the 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)));
}
/**
* Primitive specialised version of {@link #computeIfAbsent(Object, Function)}
*
* @param key to search on.
* @param mappingFunction to provide a value if the get returns null.
* @return the value if found otherwise the missing value.
*/
public int computeIfAbsent(final int key, final IntUnaryOperator mappingFunction)
{
int value = get(key);
if (value == missingValue)
{
value = mappingFunction.applyAsInt(key);
if (value != missingValue)
{
put(key, value);
}
}
return value;
}
// ---------------- Boxed Versions Below ----------------
/**
* {@inheritDoc}
*/
public Integer get(final Object key)
{
return valOrNull(get((int)key));
}
/**
* {@inheritDoc}
*/
public Integer put(final Integer key, final Integer value)
{
return valOrNull(put((int)key, (int)value));
}
/**
* {@inheritDoc}
*/
public void forEach(final BiConsumer<? super Integer, ? super Integer> action)
{
intForEach(action::accept);
}
/**
* {@inheritDoc}
*/
public boolean containsKey(final Object key)
{
return containsKey((int)key);
}
/**
* {@inheritDoc}
*/
public boolean containsValue(final Object value)
{
return containsValue((int)value);
}
/**
* {@inheritDoc}
*/
public void putAll(final Map<? extends Integer, ? extends Integer> map)
{
for (final Map.Entry<? extends Integer, ? extends Integer> 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 == values)
{
values = new ValueCollection();
}
return values;
}
/**
* {@inheritDoc}
*/
public EntrySet entrySet()
{
if (null == entrySet)
{
entrySet = new EntrySet();
}
return entrySet;
}
/**
* {@inheritDoc}
*/
public Integer remove(final Object key)
{
return valOrNull(remove((int)key));
}
/**
* Remove value from the map using given key avoiding boxing.
*
* @param key whose mapping is to be removed from the map.
* @return removed value or {@link #missingValue()} if key was not found in the map.
*/
public int remove(final int key)
{
@DoNotSub final int mask = entries.length - 1;
@DoNotSub int keyIndex = Hashing.evenHash(key, mask);
int oldValue = missingValue;
while (entries[keyIndex + 1] != missingValue)
{
if (entries[keyIndex] == key)
{
oldValue = entries[keyIndex + 1];
entries[keyIndex + 1] = missingValue;
size--;
compactChain(keyIndex);
break;
}
keyIndex = next(keyIndex, mask);
}
return oldValue;
}
@SuppressWarnings("FinalParameters")
private void compactChain(@DoNotSub int deleteKeyIndex)
{
@DoNotSub final int mask = entries.length - 1;
@DoNotSub int keyIndex = deleteKeyIndex;
while (true)
{
keyIndex = next(keyIndex, mask);
if (entries[keyIndex + 1] == missingValue)
{
break;
}
@DoNotSub final int hash = Hashing.evenHash(entries[keyIndex], mask);
if ((keyIndex < hash && (hash <= deleteKeyIndex || deleteKeyIndex <= keyIndex)) ||
(hash <= deleteKeyIndex && deleteKeyIndex <= keyIndex))
{
entries[deleteKeyIndex] = entries[keyIndex];
entries[deleteKeyIndex + 1] = entries[keyIndex + 1];
entries[keyIndex + 1] = missingValue;
deleteKeyIndex = keyIndex;
}
}
}
/**
* Get the minimum value stored in the map. If the map is empty then it will return {@link #missingValue()}
*
* @return the minimum value stored in the map.
*/
public int minValue()
{
final int missingValue = this.missingValue;
int min = size == 0 ? missingValue : Integer.MAX_VALUE;
@DoNotSub final int length = entries.length;
for (@DoNotSub int valueIndex = 1; valueIndex < length; valueIndex += 2)
{
final int value = entries[valueIndex];
if (value != missingValue)
{
min = Math.min(min, value);
}
}
return min;
}
/**
* Get the maximum value stored in the map. If the map is empty then it will return {@link #missingValue()}
*
* @return the maximum value stored in the map.
*/
public int maxValue()
{
final int missingValue = this.missingValue;
int max = size == 0 ? missingValue : Integer.MIN_VALUE;
@DoNotSub final int length = entries.length;
for (@DoNotSub int valueIndex = 1; valueIndex < length; valueIndex += 2)
{
final int value = entries[valueIndex];
if (value != missingValue)
{
max = Math.max(max, value);
}
}
return max;
}
/**
* {@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(entryIterator.getIntValue());
if (!entryIterator.hasNext())
{
return sb.append('}').toString();
}
sb.append(',').append(' ');
}
}
/**
* 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
* {@link #missingValue()} if there was no mapping for the key.
*/
public int replace(final int key, final int value)
{
int currentValue = get(key);
if (currentValue != missingValue)
{
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 int oldValue, final int newValue)
{
final int curValue = get(key);
if (curValue != oldValue || curValue == missingValue)
{
return false;
}
put(key, newValue);
return true;
}
/**
* {@inheritDoc}
*/
public boolean equals(final Object o)
{
if (this == o)
{
return true;
}
if (!(o instanceof Map))
{
return false;
}
final Map<?, ?> that = (Map<?, ?>)o;
return size == that.size() && entrySet().equals(that.entrySet());
}
/**
* {@inheritDoc}
*/
@DoNotSub public int hashCode()
{
return entrySet().hashCode();
}
@DoNotSub private static int next(final int index, final int mask)
{
return (index + 2) & mask;
}
private void capacity(@DoNotSub final int newCapacity)
{
@DoNotSub final int entriesLength = newCapacity * 2;
if (entriesLength < 0)
{
throw new IllegalStateException("max capacity reached at size=" + size);
}
/*@DoNotSub*/ resizeThreshold = (int)(newCapacity * loadFactor);
entries = new int[entriesLength];
Arrays.fill(entries, missingValue);
}
private Integer valOrNull(final int value)
{
return value == missingValue ? null : value;
}
// ---------------- Utility Classes ----------------
/**
* Base iterator implementation.
*/
abstract class AbstractIterator
{
/**
* Is current position valid.
*/
protected boolean isPositionValid = false;
@DoNotSub private int remaining;
@DoNotSub private int positionCounter;
@DoNotSub private int stopCounter;
final void reset()
{
isPositionValid = false;
remaining = Int2IntHashMap.this.size;
final int missingValue = Int2IntHashMap.this.missingValue;
final int[] entries = Int2IntHashMap.this.entries;
@DoNotSub final int capacity = entries.length;
@DoNotSub int keyIndex = capacity;
if (entries[capacity - 1] != missingValue)
{
for (@DoNotSub int i = 1; i < capacity; i += 2)
{
if (entries[i] == missingValue)
{
keyIndex = i - 1;
break;
}
}
}
stopCounter = keyIndex;
positionCounter = keyIndex + capacity;
}
/**
* Returns position of the key of the current entry.
*
* @return key position.
*/
@DoNotSub protected final int keyPosition()
{
return positionCounter & entries.length - 1;
}
/**
* Number of remaining elements.
*
* @return number of remaining elements.
*/
@DoNotSub public int remaining()
{
return remaining;
}
/**
* Check if there are more elements remaining.
*
* @return {@code true} if {@code remaining > 0}.
*/
public boolean hasNext()
{
return remaining > 0;
}
/**
* Advance to the next entry.
*
* @throws NoSuchElementException if no more entries available.
*/
protected final void findNext()
{
if (!hasNext())
{
throw new NoSuchElementException();
}
final int[] entries = Int2IntHashMap.this.entries;
final int missingValue = Int2IntHashMap.this.missingValue;
@DoNotSub final int mask = entries.length - 1;
for (@DoNotSub int keyIndex = positionCounter - 2; keyIndex >= stopCounter; keyIndex -= 2)
{
@DoNotSub final int index = keyIndex & mask;
if (entries[index + 1] != missingValue)
{
isPositionValid = true;
positionCounter = keyIndex;
--remaining;
return;
}
}
isPositionValid = false;
throw new IllegalStateException();
}
/**
* {@inheritDoc}
*/
public void remove()
{
if (isPositionValid)
{
@DoNotSub final int position = keyPosition();
entries[position + 1] = missingValue;
--size;
compactChain(position);
isPositionValid = false;
}
else
{
throw new IllegalStateException();
}
}
}
/**
* Iterator over keys which supports access to unboxed keys via {@link #nextValue()}.
*/
public final class KeyIterator extends AbstractIterator implements Iterator<Integer>
{
/**
* {@inheritDoc}
*/
public Integer next()
{
return nextValue();
}
/**
* Return next key.
*
* @return next key.
*/
public int nextValue()
{
findNext();
return entries[keyPosition()];
}
}
/**
* Iterator over values which supports access to unboxed values.
*/
public final class ValueIterator extends AbstractIterator implements Iterator<Integer>
{
/**
* {@inheritDoc}
*/
public Integer next()
{
return nextValue();
}
/**
* Return next value.
*
* @return next value.
*/
public int nextValue()
{
findNext();
return entries[keyPosition() + 1];
}
}
/**
* Iterator over entries which supports access to unboxed keys and values.
*/
public final class EntryIterator
extends AbstractIterator
implements Iterator<Entry<Integer, Integer>>, Entry<Integer, Integer>
{
/**
* {@inheritDoc}
*/
public Integer getKey()
{
return getIntKey();
}
/**
* Returns the key of the current entry.
*
* @return the key.
*/
public int getIntKey()
{
return entries[keyPosition()];
}
/**
* {@inheritDoc}
*/
public Integer getValue()
{
return getIntValue();
}
/**
* Returns the value of the current entry.
*
* @return the value.
*/
public int getIntValue()
{
return entries[keyPosition() + 1];
}
/**
* {@inheritDoc}
*/
public Integer setValue(final Integer value)
{
return setValue(value.intValue());
}
/**
* Sets the value of the current entry.
*
* @param value to be set.
* @return previous value of the entry.
*/
public int setValue(final int value)
{
if (!isPositionValid)
{
throw new IllegalStateException();
}
if (missingValue == value)
{
throw new IllegalArgumentException();
}
@DoNotSub final int keyPosition = keyPosition();
final int prevValue = entries[keyPosition + 1];
entries[keyPosition + 1] = value;
return prevValue;
}
/**
* {@inheritDoc}
*/
public Entry<Integer, Integer> next()
{
findNext();
if (shouldAvoidAllocation)
{
return this;
}
return allocateDuplicateEntry();
}
private Entry<Integer, Integer> allocateDuplicateEntry()
{
return new MapEntry(getIntKey(), getIntValue());
}
/**
* {@inheritDoc}
*/
@DoNotSub public int hashCode()
{
return Integer.hashCode(getIntKey()) ^ Integer.hashCode(getIntValue());
}
/**
* {@inheritDoc}
*/
public boolean equals(final Object o)
{
if (this == o)
{
return true;
}
if (!(o instanceof Entry))
{
return false;
}
final Entry<?, ?> that = (Entry<?, ?>)o;
return Objects.equals(getKey(), that.getKey()) && Objects.equals(getValue(), that.getValue());
}
/**
* An {@link java.util.Map.Entry} implementation.
*/
public final class MapEntry implements Entry<Integer, Integer>
{
private final int k;
private final int v;
/**
* Constructs entry with given key and value.
*
* @param k key.
* @param v value.
*/
public MapEntry(final int k, final int v)
{
this.k = k;
this.v = v;
}