MCPcopy Index your code
hub / github.com/jankotek/mapdb / bashSubMap

Method bashSubMap

src/test/java/org/mapdb/jsr166Tests/TreeMapTest.java:884–960  ·  view source on GitHub ↗
(NavigableMap<Integer, Integer> map,
                    int min, int max, boolean ascending)

Source from the content-addressed store, hash-verified

882 }
883
884 void bashSubMap(NavigableMap<Integer, Integer> map,
885 int min, int max, boolean ascending) {
886 check(map, min, max, ascending);
887 check(map.descendingMap(), min, max, !ascending);
888
889 mutateSubMap(map, min, max);
890 check(map, min, max, ascending);
891 check(map.descendingMap(), min, max, !ascending);
892
893 // Recurse
894 if (max - min < 2)
895 return;
896 int midPoint = (min + max) / 2;
897
898 // headMap - pick direction and endpoint inclusion randomly
899 boolean incl = rnd.nextBoolean();
900 NavigableMap<Integer,Integer> hm = map.headMap(midPoint, incl);
901 if (ascending) {
902 if (rnd.nextBoolean())
903 bashSubMap(hm, min, midPoint - (incl ? 0 : 1), true);
904 else
905 bashSubMap(hm.descendingMap(), min, midPoint - (incl ? 0 : 1),
906 false);
907 } else {
908 if (rnd.nextBoolean())
909 bashSubMap(hm, midPoint + (incl ? 0 : 1), max, false);
910 else
911 bashSubMap(hm.descendingMap(), midPoint + (incl ? 0 : 1), max,
912 true);
913 }
914
915 // tailMap - pick direction and endpoint inclusion randomly
916 incl = rnd.nextBoolean();
917 NavigableMap<Integer,Integer> tm = map.tailMap(midPoint,incl);
918 if (ascending) {
919 if (rnd.nextBoolean())
920 bashSubMap(tm, midPoint + (incl ? 0 : 1), max, true);
921 else
922 bashSubMap(tm.descendingMap(), midPoint + (incl ? 0 : 1), max,
923 false);
924 } else {
925 if (rnd.nextBoolean()) {
926 bashSubMap(tm, min, midPoint - (incl ? 0 : 1), false);
927 } else {
928 bashSubMap(tm.descendingMap(), min, midPoint - (incl ? 0 : 1),
929 true);
930 }
931 }
932
933 // subMap - pick direction and endpoint inclusion randomly
934 int rangeSize = max - min + 1;
935 int[] endpoints = new int[2];
936 endpoints[0] = min + rnd.nextInt(rangeSize);
937 endpoints[1] = min + rnd.nextInt(rangeSize);
938 Arrays.sort(endpoints);
939 boolean lowIncl = rnd.nextBoolean();
940 boolean highIncl = rnd.nextBoolean();
941 if (ascending) {

Callers 1

testRecursiveSubMapsMethod · 0.95

Calls 6

checkMethod · 0.95
mutateSubMapMethod · 0.95
descendingMapMethod · 0.45
headMapMethod · 0.45
tailMapMethod · 0.45
subMapMethod · 0.45

Tested by

no test coverage detected