Lines Matching defs:segment
33 import com.google.common.collect.MapMakerInternalMap.Segment;
164 // share capacity over each segment, then round up to nearest power of two
383 Segment<Object, Object> segment = map.segments[0];
395 ReferenceEntry<Object, Object> entry = segment.getEntry(one, hash);
433 // Segment core tests
519 Segment<Object, Object> segment = map.segments[0];
525 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
532 assertNull(segment.get(key, hash));
536 assertNull(segment.get(key, hash));
537 assertFalse(segment.containsKey(key, hash));
538 assertFalse(segment.containsValue(value));
541 segment.count++;
542 assertSame(value, segment.get(key, hash));
543 assertTrue(segment.containsKey(key, hash));
544 assertTrue(segment.containsValue(value));
546 assertNull(segment.get(new Object(), hash));
555 assertSame(value, segment.get(key, hash));
556 assertTrue(segment.containsKey(key, hash));
557 assertTrue(segment.containsValue(value));
558 assertFalse(segment.containsValue(nullValue));
566 assertSame(value, segment.get(key, hash));
567 assertTrue(segment.containsKey(key, hash));
568 assertTrue(segment.containsValue(value));
569 assertTrue(segment.containsValue(dummyValue));
578 assertSame(dummyValue, segment.get(key, hash));
579 assertTrue(segment.containsKey(key, hash));
580 assertTrue(segment.containsValue(value));
581 assertTrue(segment.containsValue(dummyValue));
585 assertNull(segment.get(key, hash));
586 assertFalse(segment.containsKey(key, hash));
587 assertTrue(segment.containsValue(value));
588 assertFalse(segment.containsValue(dummyValue));
594 Segment<Object, Object> segment = map.segments[0];
601 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
609 assertFalse(segment.replace(key, hash, oldValue, newValue));
610 assertEquals(0, segment.count);
614 segment.count++;
615 assertEquals(1, segment.count);
616 assertSame(oldValue, segment.get(key, hash));
617 assertTrue(segment.replace(key, hash, oldValue, newValue));
618 assertEquals(1, segment.count);
619 assertSame(newValue, segment.get(key, hash));
622 assertFalse(segment.replace(key, hash, oldValue, newValue));
623 assertEquals(1, segment.count);
624 assertSame(newValue, segment.get(key, hash));
628 assertSame(oldValue, segment.get(key, hash));
630 assertFalse(segment.replace(key, hash, oldValue, newValue));
631 assertEquals(0, segment.count);
632 assertNull(segment.get(key, hash));
638 Segment<Object, Object> segment = map.segments[0];
645 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
653 assertNull(segment.replace(key, hash, newValue));
654 assertEquals(0, segment.count);
658 segment.count++;
659 assertEquals(1, segment.count);
660 assertSame(oldValue, segment.get(key, hash));
661 assertSame(oldValue, segment.replace(key, hash, newValue));
662 assertEquals(1, segment.count);
663 assertSame(newValue, segment.get(key, hash));
667 assertSame(oldValue, segment.get(key, hash));
669 assertNull(segment.replace(key, hash, newValue));
670 assertEquals(0, segment.count);
671 assertNull(segment.get(key, hash));
677 Segment<Object, Object> segment = map.segments[0];
686 assertEquals(0, segment.count);
687 assertNull(segment.put(key, hash, oldValue, false));
688 assertEquals(1, segment.count);
691 assertSame(oldValue, segment.put(key, hash, newValue, false));
692 assertEquals(1, segment.count);
693 assertSame(newValue, segment.get(key, hash));
696 ReferenceEntry<Object, Object> entry = segment.getEntry(key, hash);
699 assertSame(oldValue, segment.get(key, hash));
701 assertNull(segment.put(key, hash, newValue, false));
702 assertEquals(1, segment.count);
703 assertSame(newValue, segment.get(key, hash));
709 Segment<Object, Object> segment = map.segments[0];
718 assertEquals(0, segment.count);
719 assertNull(segment.put(key, hash, oldValue, true));
720 assertEquals(1, segment.count);
723 assertSame(oldValue, segment.put(key, hash, newValue, true));
724 assertEquals(1, segment.count);
725 assertSame(oldValue, segment.get(key, hash));
728 ReferenceEntry<Object, Object> entry = segment.getEntry(key, hash);
731 assertSame(oldValue, segment.get(key, hash));
733 assertNull(segment.put(key, hash, newValue, true));
734 assertEquals(1, segment.count);
735 assertSame(newValue, segment.get(key, hash));
741 Segment<Object, Object> segment = map.segments[0];
742 assertEquals(1, segment.table.length());
749 assertNull(segment.put(key, hash, value, false));
750 assertTrue(segment.table.length() > i);
778 Segment<Object, Object> segment = map.segments[0];
783 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
791 assertEquals(0, segment.count);
792 assertNull(segment.remove(key, hash));
793 assertEquals(0, segment.count);
797 segment.count++;
798 assertEquals(1, segment.count);
799 assertSame(oldValue, segment.get(key, hash));
800 assertSame(oldValue, segment.remove(key, hash));
801 assertEquals(0, segment.count);
802 assertNull(segment.get(key, hash));
806 segment.count++;
807 assertEquals(1, segment.count);
808 assertSame(oldValue, segment.get(key, hash));
810 assertNull(segment.remove(key, hash));
811 assertEquals(0, segment.count);
812 assertNull(segment.get(key, hash));
817 Segment<Object, Object> segment = map.segments[0];
823 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
831 assertEquals(0, segment.count);
832 assertNull(segment.remove(key, hash));
833 assertEquals(0, segment.count);
837 segment.count++;
838 assertEquals(1, segment.count);
839 assertSame(oldValue, segment.get(key, hash));
840 assertTrue(segment.remove(key, hash, oldValue));
841 assertEquals(0, segment.count);
842 assertNull(segment.get(key, hash));
846 segment.count++;
847 assertEquals(1, segment.count);
848 assertSame(oldValue, segment.get(key, hash));
849 assertFalse(segment.remove(key, hash, newValue));
850 assertEquals(1, segment.count);
851 assertSame(oldValue, segment.get(key, hash));
854 assertSame(oldValue, segment.get(key, hash));
856 assertFalse(segment.remove(key, hash, oldValue));
857 assertEquals(0, segment.count);
858 assertNull(segment.get(key, hash));
864 Segment<Object, Object> segment = map.segments[0];
865 assertEquals(1, segment.table.length());
879 segment.table.set(0, entry);
880 segment.count = originalCount;
887 segment.expand();
889 assertEquals(i, segment.table.length());
891 assertEquals(originalCount, segment.count);
905 Segment<Object, Object> segment = map.segments[0];
906 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
926 assertFalse(segment.reclaimKey(entryOne, hashOne));
929 assertFalse(segment.reclaimKey(entryTwo, hashTwo));
932 assertFalse(segment.reclaimKey(entryThree, hashThree));
937 segment.count = 1;
938 assertTrue(segment.reclaimKey(entryOne, hashOne));
943 assertFalse(segment.evictionQueue.contains(entryOne));
944 assertFalse(segment.expirationQueue.contains(entryOne));
945 assertEquals(0, segment.count);
951 Segment<Object, Object> segment = map.segments[0];
969 assertNull(segment.removeFromChain(entryOne, entryOne));
972 assertSame(entryOne, segment.removeFromChain(entryTwo, entryTwo));
975 ReferenceEntry<Object, Object> newFirst = segment.removeFromChain(entryThree, entryTwo);
982 newFirst = segment.removeFromChain(entryThree, entryOne);
996 Segment<Object, Object> segment = map.segments[0];
997 assertEquals(1, segment.table.length());
1015 segment.table.set(0, entry);
1016 segment.count = originalCount;
1018 assertEquals(1, segment.table.length());
1026 segment.expand();
1028 assertEquals(i, segment.table.length());
1031 assertTrue(segment.count >= liveCount);
1032 assertTrue(segment.count <= originalCount);
1039 for (Segment<K, V> segment : map.segments) {
1040 AtomicReferenceArray<ReferenceEntry<K, V>> table = segment.table;
1058 Segment<Object, Object> segment = map.segments[0];
1059 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1066 segment.recordWrite(entry);
1067 segment.table.set(0, entry);
1068 segment.readCount.incrementAndGet();
1069 segment.count = 1;
1072 assertSame(entry, segment.evictionQueue.peek());
1073 assertSame(entry, segment.expirationQueue.peek());
1075 segment.clear();
1077 assertTrue(segment.evictionQueue.isEmpty());
1078 assertTrue(segment.expirationQueue.isEmpty());
1079 assertEquals(0, segment.readCount.get());
1080 assertEquals(0, segment.count);
1090 Segment<Object, Object> segment = map.segments[0];
1091 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1100 assertFalse(segment.removeEntry(entry, hash, RemovalCause.COLLECTED));
1103 segment.recordWrite(entry);
1105 segment.count = 1;
1106 assertTrue(segment.removeEntry(entry, hash, RemovalCause.COLLECTED));
1109 assertFalse(segment.evictionQueue.contains(entry));
1110 assertFalse(segment.expirationQueue.contains(entry));
1111 assertEquals(0, segment.count);
1124 Segment<Object, Object> segment = map.segments[0];
1125 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1136 assertFalse(segment.reclaimValue(key, hash, valueRef));
1139 segment.recordWrite(entry);
1141 segment.count = 1;
1142 assertTrue(segment.reclaimValue(key, hash, valueRef));
1147 assertFalse(segment.evictionQueue.contains(entry));
1148 assertFalse(segment.expirationQueue.contains(entry));
1149 assertEquals(0, segment.count);
1156 assertFalse(segment.reclaimValue(key, hash, valueRef));
1158 assertTrue(segment.reclaimValue(key, hash, otherValueRef));
1171 Segment<Object, Object> segment = map.segments[0];
1172 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1183 assertFalse(segment.clearValue(key, hash, valueRef));
1186 segment.recordWrite(entry);
1189 assertTrue(segment.clearValue(key, hash, valueRef));
1192 assertFalse(segment.evictionQueue.contains(entry));
1193 assertFalse(segment.expirationQueue.contains(entry));
1194 assertEquals(0, segment.count);
1201 assertFalse(segment.clearValue(key, hash, valueRef));
1203 assertTrue(segment.clearValue(key, hash, valueRef));
1213 // Segment eviction tests
1218 Segment<Object, Object> segment = map.segments[0];
1220 if (segment.recencyQueue != DISCARDING_QUEUE) {
1227 assertTrue(segment.recencyQueue.isEmpty());
1232 assertFalse(segment.recencyQueue.isEmpty());
1235 assertTrue(segment.recencyQueue.isEmpty());
1243 Segment<Object, Object> segment = map.segments[0];
1245 if (segment.recencyQueue != DISCARDING_QUEUE) {
1252 assertTrue(segment.recencyQueue.isEmpty());
1257 assertFalse(segment.recencyQueue.isEmpty());
1261 assertTrue(segment.recencyQueue.size() <= DRAIN_THRESHOLD);
1269 assertTrue(segment.recencyQueue.isEmpty());
1274 assertFalse(segment.recencyQueue.isEmpty());
1278 assertTrue(segment.recencyQueue.size() <= DRAIN_THRESHOLD);
1287 Segment<Object, Object> segment = map.segments[0];
1297 segment.recordWrite(entry);
1302 checkEvictionQueues(map, segment, readOrder, writeOrder);
1312 segment.recordRead(entry);
1317 checkAndDrainRecencyQueue(map, segment, reads);
1320 checkEvictionQueues(map, segment, readOrder, writeOrder);
1328 Segment<Object, Object> segment = map.segments[0];
1337 ReferenceEntry<Object, Object> entry = segment.getEntry(key, hash);
1342 checkEvictionQueues(map, segment, readOrder, writeOrder);
1344 assertTrue(segment.recencyQueue.isEmpty());
1356 assertTrue(segment.recencyQueue.size() <= DRAIN_THRESHOLD);
1359 int undrainedIndex = reads.size() - segment.recencyQueue.size();
1360 checkAndDrainRecencyQueue(map, segment, reads.subList(undrainedIndex, reads.size()));
1363 checkEvictionQueues(map, segment, readOrder, writeOrder);
1371 Segment<Object, Object> segment = map.segments[0];
1380 segment.recordWrite(entry);
1384 checkEvictionQueues(map, segment, writeOrder, writeOrder);
1394 segment.recordWrite(entry);
1401 checkEvictionQueues(map, segment, writeOrder, writeOrder);
1407 Segment<K, V> segment, List<ReferenceEntry<K, V>> reads) {
1409 assertSameEntries(reads, ImmutableList.copyOf(segment.recencyQueue));
1411 segment.drainRecencyQueue();
1415 Segment<K, V> segment, List<ReferenceEntry<K, V>> readOrder,
1418 assertSameEntries(readOrder, ImmutableList.copyOf(segment.evictionQueue));
1421 assertSameEntries(readOrder, ImmutableList.copyOf(segment.expirationQueue));
1424 assertSameEntries(writeOrder, ImmutableList.copyOf(segment.expirationQueue));
1445 for (Segment<K, V> segment : map.segments) {
1447 for (ReferenceEntry<K, V> e : segment.recencyQueue) {
1454 for (ReferenceEntry<K, V> e : segment.expirationQueue) {
1466 Segment<Object, Object> segment = map.segments[0];
1475 AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
1482 segment.recordWrite(entry);
1486 segment.count = originalCount;
1491 assertTrue(segment.evictEntries());
1497 assertFalse(segment.evictEntries());
1507 Segment<Object, Object> segment = map.segments[0];
1516 ReferenceEntry<Object, Object> entry = segment.getEntry(keyOne, hashOne);
1527 assertNull(segment.keyReferenceQueue.poll());
1537 Segment<Object, Object> segment = map.segments[0];
1546 ReferenceEntry<Object, Object> entry = segment.getEntry(keyOne, hashOne);
1558 assertNull(segment.valueReferenceQueue.poll());
1568 Segment<Object, Object> segment = map.segments[0];
1576 ReferenceEntry<Object, Object> entry = segment.getEntry(keyOne, hashOne);
1589 assertNull(segment.keyReferenceQueue.poll());
1599 Segment<Object, Object> segment = map.segments[0];
1607 ReferenceEntry<Object, Object> entry = segment.getEntry(keyOne, hashOne);
1621 assertNull(segment.valueReferenceQueue.poll());