Skip to content

Commit 4aa0a8a

Browse files
committed
Fix test failures
1 parent 4b09c27 commit 4aa0a8a

File tree

5 files changed

+13
-37
lines changed

5 files changed

+13
-37
lines changed

accord-core/src/main/java/accord/topology/Topology.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ Topology forSubset(int[] newSubset)
267267
{
268268
Ranges rangeSubset = ranges.select(newSubset);
269269
SimpleBitSet nodes = new SimpleBitSet(nodeIds.size());
270+
Int2ObjectHashMap<NodeInfo> nodeLookup = new Int2ObjectHashMap<>(nodes.size(), 0.8f);
270271
for (int shardIndex : newSubset)
271272
{
272273
Shard shard = shards[shardIndex];
@@ -288,15 +289,18 @@ Topology forSubset(int[] newSubset)
288289
Topology forSubset(int[] newSubset, Collection<Id> nodes)
289290
{
290291
Ranges rangeSubset = ranges.select(newSubset);
291-
Id[] nodeIds = nodes.toArray(new Id[nodes.size()]);
292-
Arrays.sort(nodeIds);
292+
Id[] nodeIds = new Id[nodes.size()];
293293
Int2ObjectHashMap<NodeInfo> nodeLookup = new Int2ObjectHashMap<>(nodes.size(), 0.8f);
294294
for (Id id : nodes)
295295
{
296296
NodeInfo info = this.nodeLookup.get(id.id).forSubset(newSubset);
297297
if (info.ranges.isEmpty()) continue;
298+
nodeIds[nodeLookup.size()] = id;
298299
nodeLookup.put(id.id, info);
299300
}
301+
if (nodeLookup.size() != nodeIds.length)
302+
nodeIds = Arrays.copyOf(nodeIds, nodeLookup.size());
303+
Arrays.sort(nodeIds);
300304
return new Topology(global(), epoch, shards, ranges, new SortedArrayList<>(nodeIds), nodeLookup, rangeSubset, newSubset);
301305
}
302306

@@ -515,7 +519,7 @@ public boolean contains(Id id)
515519

516520
public List<Shard> shards()
517521
{
518-
return new AbstractList<Shard>()
522+
return new AbstractList<>()
519523
{
520524
@Override
521525
public Shard get(int i)

accord-core/src/main/java/accord/utils/CheckpointIntervalArray.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import net.nicoulaj.compilecommand.annotations.Inline;
2525

2626
import static accord.utils.SortedArrays.Search.CEIL;
27-
import static accord.utils.SortedArrays.Search.FLOOR;
2827

2928
public class CheckpointIntervalArray<Ranges, Range, Key>
3029
{
@@ -128,36 +127,6 @@ else if (c.compare(accessor.end(ranges, start), startKey) <= 0)
128127
return forEach(start, end, floor, startKey, 0, forEachScanOrCheckpoint, forEachRange, p1, p2, p3, p4, minIndex);
129128
}
130129

131-
public <P1, P2, P3, P4> int forEachKey(Key key, IndexedQuadConsumer<P1, P2, P3, P4> forEachScanOrCheckpoint, IndexedRangeQuadConsumer<P1, P2, P3, P4> forEachRange, P1 p1, P2 p2, P3 p3, P4 p4, int minIndex)
132-
{
133-
if (accessor.size(ranges) == 0 || minIndex == accessor.size(ranges))
134-
return minIndex;
135-
136-
var c = accessor.keyComparator();
137-
int end = accessor.binarySearch(ranges, minIndex, accessor.size(ranges), key, (a, b) -> c.compare(a, accessor.start(b)), FLOOR);
138-
if (end < 0) end = -1 - end;
139-
else ++end;
140-
if (end <= minIndex) return minIndex;
141-
142-
int floor = accessor.binarySearch(ranges, minIndex, accessor.size(ranges), key, (a, b) -> c.compare(a, accessor.start(b)), CEIL);
143-
int start = floor;
144-
if (floor < 0)
145-
{
146-
// if there's no precise match on start, step backwards;
147-
// if this range does not overlap us, step forwards again for start
148-
// but retain the floor index for performing scan and checkpoint searches from
149-
// as this contains all ranges that might overlap us (whereas those that end
150-
// after us but before the next range's start would be missed by the next range index)
151-
start = floor = -2 - floor;
152-
if (start < 0)
153-
start = floor = 0;
154-
else if (c.compare(accessor.end(ranges, start), key) <= 0)
155-
++start;
156-
}
157-
158-
return forEach(start, end, floor, key, 0, forEachScanOrCheckpoint, forEachRange, p1, p2, p3, p4, minIndex);
159-
}
160-
161130
@Inline
162131
protected <P1, P2, P3, P4> int forEach(int start, int end, int floor, Key startBound, int cmpStartBoundWithEnd,
163132
IndexedQuadConsumer<P1, P2, P3, P4> forEachScanOrCheckpoint, IndexedRangeQuadConsumer<P1, P2, P3, P4> forEachRange,

accord-core/src/main/java/accord/utils/SearchableRangeList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public SearchableRangeList(Range[] ranges, int[] lowerBounds, int[] headers, int
8686
}
8787

8888
@Inline
89-
public <P1, P2, P3, P4> int forEach(RoutableKey key, IndexedQuadConsumer<P1, P2, P3, P4> forEachScanOrCheckpoint, IndexedRangeQuadConsumer<P1, P2, P3, P4> forEachRange, P1 p1, P2 p2, P3 p3, P4 p4, int minIndex)
89+
public <P1, P2, P3, P4> int forEachKey(RoutableKey key, IndexedQuadConsumer<P1, P2, P3, P4> forEachScanOrCheckpoint, IndexedRangeQuadConsumer<P1, P2, P3, P4> forEachRange, P1 p1, P2 p2, P3 p3, P4 p4, int minIndex)
9090
{
9191
if (ranges.length == 0 || minIndex == ranges.length)
9292
return minIndex;

accord-core/src/test/java/accord/primitives/RangeDepsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public void testRandom()
247247
for (int i = 0 ; i < 1000 ; ++i)
248248
{
249249
long seed = random.nextLong();
250-
// long seed = -5637243003494330136L;
250+
// long seed = 1953755836248097851L;
251251
System.out.println("Seed: " + seed);
252252
random.setSeed(seed);
253253
generate(random, new GenerateRanges(1000, 0.01f, 0.3f, 0.1f, 1f), 100, 1000)

accord-core/src/test/java/accord/utils/ExtendedAssertions.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import accord.topology.Shard;
3131
import accord.topology.Topologies;
3232
import accord.topology.Topology;
33+
import accord.utils.SortedArrays.SortedArrayList;
3334
import org.agrona.collections.LongArrayList;
3435
import org.assertj.core.api.AbstractAssert;
3536
import org.assertj.core.api.Assertions;
@@ -122,9 +123,11 @@ public TopologyAssert isShardsEqualTo(List<Shard> shards)
122123
return myself;
123124
}
124125

125-
public TopologyAssert isHostsEqualTo(List<Node.Id> nodes)
126+
public TopologyAssert isHostsEqualTo(SortedArrayList<Node.Id> nodes)
126127
{
127128
isNotNull();
129+
// Collection<Node.Id> actualNodes = actual.nodes();
130+
// if (!(actualNodes instanceof SortedArrayList)) actualNodes = SortedArrayList.copyUnsorted(nodes, Node.Id[]::new);
128131
objects.assertEqual(info, actual.nodes(), nodes);
129132
return myself;
130133
}

0 commit comments

Comments
 (0)