|
48 | 48 | import accord.primitives.TxnId;
|
49 | 49 | import accord.primitives.Unseekable;
|
50 | 50 | import accord.primitives.Unseekables;
|
| 51 | +import accord.utils.AsymmetricComparator; |
51 | 52 | import accord.utils.Invariants;
|
| 53 | +import accord.utils.SymmetricComparator; |
52 | 54 | import accord.utils.UnhandledEnum;
|
53 | 55 | import org.agrona.collections.Object2ObjectHashMap;
|
54 | 56 | import org.apache.cassandra.service.accord.api.TokenKey;
|
55 | 57 | import org.apache.cassandra.utils.btree.IntervalBTree;
|
56 | 58 |
|
57 | 59 | import static accord.local.CommandSummaries.SummaryStatus.NOT_DIRECTLY_WITNESSED;
|
58 |
| -import static org.apache.cassandra.utils.btree.IntervalBTree.InclusiveEndKeyComparatorHelper.intervalEndWithKeyEnd; |
59 |
| -import static org.apache.cassandra.utils.btree.IntervalBTree.InclusiveEndKeyComparatorHelper.intervalEndWithKeyStart; |
60 |
| -import static org.apache.cassandra.utils.btree.IntervalBTree.InclusiveEndKeyComparatorHelper.intervalStartWithKeyEnd; |
61 |
| -import static org.apache.cassandra.utils.btree.IntervalBTree.InclusiveEndKeyComparatorHelper.intervalStartWithKeyStart; |
62 |
| -import static org.apache.cassandra.utils.btree.IntervalBTree.InclusiveEndKeyComparatorHelper.keyEndWithIntervalEnd; |
63 |
| -import static org.apache.cassandra.utils.btree.IntervalBTree.InclusiveEndKeyComparatorHelper.keyEndWithIntervalStart; |
64 |
| -import static org.apache.cassandra.utils.btree.IntervalBTree.InclusiveEndKeyComparatorHelper.keyStartWithIntervalEnd; |
65 |
| -import static org.apache.cassandra.utils.btree.IntervalBTree.InclusiveEndKeyComparatorHelper.keyStartWithIntervalStart; |
| 60 | +import static org.apache.cassandra.utils.btree.IntervalBTree.InclusiveEndHelper.endWithStart; |
| 61 | +import static org.apache.cassandra.utils.btree.IntervalBTree.InclusiveEndHelper.keyEndWithStart; |
| 62 | +import static org.apache.cassandra.utils.btree.IntervalBTree.InclusiveEndHelper.keyStartWithEnd; |
| 63 | +import static org.apache.cassandra.utils.btree.IntervalBTree.InclusiveEndHelper.keyStartWithStart; |
| 64 | +import static org.apache.cassandra.utils.btree.IntervalBTree.InclusiveEndHelper.startWithEnd; |
| 65 | +import static org.apache.cassandra.utils.btree.IntervalBTree.InclusiveEndHelper.startWithStart; |
66 | 66 |
|
67 | 67 | // TODO (expected): move to accord-core, merge with existing logic there
|
68 | 68 | public class CommandsForRanges extends TreeMap<Timestamp, Summary> implements CommandSummaries.ByTxnIdSnapshot
|
@@ -101,47 +101,18 @@ public int compareTo(TxnIdInterval that)
|
101 | 101 | static class IntervalComparators implements IntervalBTree.IntervalComparators<TxnIdInterval>
|
102 | 102 | {
|
103 | 103 | @Override public Comparator<TxnIdInterval> totalOrder() { return TxnIdInterval::compareTo; }
|
104 |
| - @Override public Comparator<TxnIdInterval> startWithStartComparator() { return (a, b) -> a.start.compareTo(b.start); } |
105 |
| - @Override public Comparator<TxnIdInterval> startWithEndComparator() { return (a, b) -> a.start.compareTo(b.end); } |
106 |
| - @Override public Comparator<TxnIdInterval> endWithStartComparator() { return (a, b) -> a.end.compareTo(b.start); } |
107 |
| - @Override public Comparator<TxnIdInterval> endWithEndComparator() { return (a, b) -> a.end.compareTo(b.end); } |
| 104 | + @Override public Comparator<TxnIdInterval> endWithEndSorter() { return (a, b) -> a.end.compareTo(b.end); } |
| 105 | + |
| 106 | + @Override public SymmetricComparator<TxnIdInterval> startWithStartSeeker() { return (a, b) -> startWithStart(a.start.compareTo(b.start)); } |
| 107 | + @Override public SymmetricComparator<TxnIdInterval> startWithEndSeeker() { return (a, b) -> startWithEnd(a.start.compareTo(b.end)); } |
| 108 | + @Override public SymmetricComparator<TxnIdInterval> endWithStartSeeker() { return (a, b) -> endWithStart(a.end.compareTo(b.start)); } |
108 | 109 | }
|
109 | 110 |
|
110 |
| - static class IntervalKeyComparators implements IntervalBTree.IntervalComparators<Object> |
| 111 | + static class IntervalKeyComparators implements IntervalBTree.WithIntervalComparators<RoutingKey, TxnIdInterval> |
111 | 112 | {
|
112 |
| - @Override public Comparator<Object> totalOrder() { throw new UnsupportedOperationException(); } |
113 |
| - |
114 |
| - @Override |
115 |
| - public Comparator<Object> startWithStartComparator() |
116 |
| - { |
117 |
| - return (a, b) -> a.getClass() == TxnIdInterval.class |
118 |
| - ? intervalStartWithKeyStart(((TxnIdInterval) a).start.compareTo((RoutingKey)b)) |
119 |
| - : keyStartWithIntervalStart(((RoutingKey)a).compareTo(((TxnIdInterval)b).start)); |
120 |
| - } |
121 |
| - |
122 |
| - @Override |
123 |
| - public Comparator<Object> startWithEndComparator() |
124 |
| - { |
125 |
| - return (a, b) -> a.getClass() == TxnIdInterval.class |
126 |
| - ? intervalStartWithKeyEnd(((TxnIdInterval)a).start.compareTo((RoutingKey)b)) |
127 |
| - : keyStartWithIntervalEnd(((RoutingKey)a).compareTo(((TxnIdInterval)b).end)); |
128 |
| - } |
129 |
| - |
130 |
| - @Override |
131 |
| - public Comparator<Object> endWithStartComparator() |
132 |
| - { |
133 |
| - return (a, b) -> a.getClass() == TxnIdInterval.class |
134 |
| - ? intervalEndWithKeyStart(((TxnIdInterval)a).end.compareTo((RoutingKey)b)) |
135 |
| - : keyEndWithIntervalStart(((RoutingKey)a).compareTo(((TxnIdInterval)b).start)); |
136 |
| - } |
137 |
| - |
138 |
| - @Override |
139 |
| - public Comparator<Object> endWithEndComparator() |
140 |
| - { |
141 |
| - return (a, b) -> a.getClass() == TxnIdInterval.class |
142 |
| - ? intervalEndWithKeyEnd(((TxnIdInterval)a).end.compareTo((RoutingKey)b)) |
143 |
| - : keyEndWithIntervalEnd(((RoutingKey)a).compareTo(((TxnIdInterval)b).end)); |
144 |
| - } |
| 113 | + @Override public AsymmetricComparator<RoutingKey, TxnIdInterval> startWithStartSeeker() { return (a, b) -> keyStartWithStart(a.compareTo(b.start));} |
| 114 | + @Override public AsymmetricComparator<RoutingKey, TxnIdInterval> startWithEndSeeker() { return (a, b) -> keyStartWithEnd(a.compareTo(b.end)); } |
| 115 | + @Override public AsymmetricComparator<RoutingKey, TxnIdInterval> endWithStartSeeker() { return (a, b) -> keyEndWithStart(a.compareTo(b.start)); } |
145 | 116 | }
|
146 | 117 |
|
147 | 118 | public CommandsForRanges(Map<? extends Timestamp, ? extends Summary> m)
|
@@ -224,7 +195,7 @@ static Object[] toMap(TxnId txnId, RangeRoute route)
|
224 | 195 | case 1: return IntervalBTree.singleton(new TxnIdInterval(route.get(0), txnId));
|
225 | 196 | default:
|
226 | 197 | {
|
227 |
| - try (IntervalBTree.FastInteralTreeBuilder<TxnIdInterval> builder = IntervalBTree.fastBuilder(COMPARATORS.endWithEndComparator())) |
| 198 | + try (IntervalBTree.FastIntervalTreeBuilder<TxnIdInterval> builder = IntervalBTree.fastBuilder(COMPARATORS)) |
228 | 199 | {
|
229 | 200 | for (int i = 0 ; i < size ; ++i)
|
230 | 201 | builder.add(new TxnIdInterval(route.get(i), txnId));
|
|
0 commit comments