private void updateCounts(ExpandingArrayList<Long> counts, long nRods, long nObs) { if ( nRods >= 0 ) { long prev = counts.get((int)nRods) == null ? 0l : counts.get((int)nRods); counts.set((int)nRods, nObs + prev); } }
@Test public void testSetExpandingReset() { logger.warn("Executing testSetExpandingReset"); Assert.assertEquals(0, empty.size()); empty.set(3, 3); empty.set(2, 2); empty.set(1, 1); empty.set(0, 0); Assert.assertEquals(4, empty.size()); for ( int i = 0; i < 4; i++ ) Assert.assertEquals(i, (int)empty.get(i)); }
@Test public void testSettingTenElements() { logger.warn("Executing testSettingTenElements"); for ( int i = 0; i < 10; i++ ) { Assert.assertEquals(i+1, (int)hasTen.set(i, 2*i)); } Assert.assertEquals(10, hasTen.size()); for ( int i = 0; i < 10; i++ ) { Assert.assertEquals(2*i, (int)hasTen.get(i)); } }
/** * Put mapResult into this MapResultsQueue, associated with its jobID * @param mapResult a non-null map result */ public synchronized void put(final MapResult<MapType> mapResult) { if ( mapResult == null ) throw new IllegalArgumentException("mapResult cannot be null"); // make sure that nothing is at the job id for map assert queue.size() < mapResult.getJobID() || queue.get(mapResult.getJobID()) == null; queue.set(mapResult.getJobID(), mapResult); }
@Test public void testSetBadGetPost() { logger.warn("Executing testSetBadGetPost"); empty.set(1, 1); Assert.assertEquals(empty.get(0), null); Assert.assertEquals(1, (int)empty.get(1)); Assert.assertEquals(empty.get(2), null); } }
@Test public void testSet1() { logger.warn("Executing testSet1"); Assert.assertEquals(0, empty.size()); empty.set(0, 1); Assert.assertEquals(1, empty.size()); Assert.assertEquals(1, (int)empty.get(0)); empty.set(1, 2); Assert.assertEquals(2, empty.size()); Assert.assertEquals(2, (int)empty.get(1)); // doesn't expand empty.set(0, 3); Assert.assertEquals(2, empty.size()); Assert.assertEquals(3, (int)empty.get(0)); }
@Test public void testSetExpandingBig() { logger.warn("Executing testSetExpandingBig"); Assert.assertEquals(0, empty.size()); empty.set(1000, 1000); Assert.assertEquals(1001, empty.size()); for ( int i = 0; i < 1000; i++ ) Assert.assertEquals(empty.get(i), null); Assert.assertEquals(1000, (int)empty.get(1000)); }
@Test public void testSetExpanding() { logger.warn("Executing testSetExpanding"); Assert.assertEquals(0, empty.size()); empty.set(3, 1); Assert.assertEquals(4, empty.size()); Assert.assertEquals(empty.get(0), null); Assert.assertEquals(empty.get(1), null); Assert.assertEquals(empty.get(2), null); Assert.assertEquals(1, (int)empty.get(3)); }
/** * Can only be called when nextValueIsAvailable is true * @return * @throws InterruptedException */ // TODO -- does this have to be synchronized? -- I think the answer is no public synchronized MapResult<MapType> take() throws InterruptedException { final MapResult<MapType> result = queue.get(nextJobID()); // make sure the value we've fetched has the right id assert result.getJobID() == nextJobID(); prevJobID = result.getJobID(); queue.set(prevJobID, null); return result; } }
@Override public Pair<ExpandingArrayList<Long>, Long> treeReduce(Pair<ExpandingArrayList<Long>, Long> lhs, Pair<ExpandingArrayList<Long>, Long> rhs) { ExpandingArrayList<Long> nt = new ExpandingArrayList<Long>(); nt.addAll(lhs.first); int index = 0; for (Long l : rhs.first) { if (nt.get(index) == null) nt.add(l); else nt.set(index,nt.get(index) + l); index++; } return new Pair<ExpandingArrayList<Long>, Long>(nt, lhs.second + rhs.second); }