Java Code Examples for java.util.concurrent.atomic.AtomicIntegerArray#get()
The following examples show how to use
java.util.concurrent.atomic.AtomicIntegerArray#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemoryChunkJUnitTestBase.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
static private ArrayList<Bucket> computeHistogram(AtomicIntegerArray originalValues, final int granualarity) { int[] values = new int[originalValues.length()]; for (int i=0; i < values.length; i++) { values[i] = originalValues.get(i); } Arrays.sort(values); ArrayList<Bucket> result = new ArrayList<Bucket>(); Bucket curBucket = new Bucket(values[0]); result.add(curBucket); for (int i=1; i < values.length; i++) { int curVal = values[i]; if (!curBucket.addValue(curVal, granualarity)) { curBucket = new Bucket(curVal); result.add(curBucket); } } return result; }
Example 2
Source File: MemoryChunkJUnitTestBase.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
static private ArrayList<Bucket> computeHistogram(AtomicIntegerArray originalValues, final int granualarity) { int[] values = new int[originalValues.length()]; for (int i=0; i < values.length; i++) { values[i] = originalValues.get(i); } Arrays.sort(values); ArrayList<Bucket> result = new ArrayList<Bucket>(); Bucket curBucket = new Bucket(values[0]); result.add(curBucket); for (int i=1; i < values.length; i++) { int curVal = values[i]; if (!curBucket.addValue(curVal, granualarity)) { curBucket = new Bucket(curVal); result.add(curBucket); } } return result; }
Example 3
Source File: ChoiceOfTwoLoadBalancerTest.java From ocelli with Apache License 2.0 | 6 votes |
@Test public void testMany() { BehaviorSubject<List<Integer>> source = BehaviorSubject.create(); LoadBalancer<Integer> lb = LoadBalancer.fromSnapshotSource(source).build(ChoiceOfTwoLoadBalancer.create(COMPARATOR)); source.onNext(Lists.newArrayList(0,1,2,3,4,5,6,7,8,9)); AtomicIntegerArray counts = new AtomicIntegerArray(10); for (int i = 0; i < 100000; i++) { counts.incrementAndGet(lb.next()); } Double[] pct = new Double[counts.length()]; for (int i = 0; i < counts.length(); i++) { pct[i] = counts.get(i)/100000.0; } for (int i = 1; i < counts.length(); i++) { Assert.assertTrue(counts.get(i) > counts.get(i-1)); } }
Example 4
Source File: ComposableFutures.java From ob1k with Apache License 2.0 | 5 votes |
private static <T, R> ComposableFuture<Void> jump(final List<T> elements, final AtomicIntegerArray nodesState, final R[] results, final AtomicInteger pendingNodeLowerBound, final FutureSuccessHandler<T, R> producer) { int node = pendingNodeLowerBound.get(); // Find the top leftmost pending element for (; node <= elements.size() && nodesState.get(node - 1) == 1; node++) ; // We may set pendingNodeLowerBound to a lower value than its latest value, // but it won't break the invariant that for all x < pendingNodeLowerBound.get(), nodesState.get(x - 1) == 1 pendingNodeLowerBound.set(node + 1); return processTree(elements, node, nodesState, results, pendingNodeLowerBound, producer, true); }
Example 5
Source File: HeapChunkSpace.java From greycat with Apache License 2.0 | 4 votes |
private void capacity_extends() { int new_maxEntries = this._maxEntries * 2; this._graph.log().warn("extends cache capacity from " + this._maxEntries + " to " + new_maxEntries); int new_hashEntries = new_maxEntries * HASH_LOAD_FACTOR; Stack new_lru = new HeapFixedStack(new_maxEntries, true); Stack new_dirties = new HeapFixedStack(new_maxEntries, false); AtomicIntegerArray new_hashNext = new AtomicIntegerArray(new_maxEntries); AtomicIntegerArray new_hash = new AtomicIntegerArray(new_hashEntries); for (int i = 0; i < new_maxEntries; i++) { new_hashNext.set(i, -1); } for (int i = 0; i < new_hashEntries; i++) { new_hash.set(i, -1); } AtomicReferenceArray<Chunk> new_chunkValues = new AtomicReferenceArray<Chunk>(new_maxEntries); AtomicLongArray new_chunkWorlds = new AtomicLongArray(new_maxEntries); AtomicLongArray new_chunkTimes = new AtomicLongArray(new_maxEntries); AtomicLongArray new_chunkIds = new AtomicLongArray(new_maxEntries); HeapAtomicByteArray new_chunkTypes = new HeapAtomicByteArray(new_maxEntries); AtomicLongArray new_chunkMarks = new AtomicLongArray(new_maxEntries); for (int i = 0; i < new_maxEntries; i++) { new_chunkMarks.set(i, 0); } byte type; long world; long time; long id; Chunk chunk; long marks; int index; int offset = (int) _dirtiesStack.dequeueTail(); while (offset != -1) { new_dirties.enqueue(offset); offset = (int) _dirtiesStack.dequeueTail(); } for (int i = 0; i < _maxEntries; i++) { new_lru.dequeue(i); type = _chunkTypes.get(i); world = _chunkWorlds.get(i); time = _chunkTimes.get(i); id = _chunkIds.get(i); chunk = _chunkValues.get(i); marks = _chunkMarks.get(i); new_chunkTypes.set(i, type); new_chunkWorlds.set(i, world); new_chunkTimes.set(i, time); new_chunkIds.set(i, id); new_chunkValues.set(i, chunk); new_chunkMarks.set(i, marks); if (_deep_priority) { index = (int) HashHelper.tripleHash(type, world, time, id, new_hashEntries); } else { index = (int) HashHelper.simpleTripleHash(type, world, time, id, new_hashEntries); } int previous_hash = new_hash.get(index); new_hash.set(index, i); new_hashNext.set(i, previous_hash); if (marks == 0) { new_lru.enqueue(i); } if (_dirtiesStack.dequeue(i)) { new_dirties.enqueue(i); } } this._maxEntries = new_maxEntries; this._hashEntries = new_hashEntries; this._lru = new_lru; this._dirtiesStack = new_dirties; this._hashNext = new_hashNext; this._hash = new_hash; this._chunkValues = new_chunkValues; this._chunkWorlds = new_chunkWorlds; this._chunkTimes = new_chunkTimes; this._chunkIds = new_chunkIds; this._chunkTypes = new_chunkTypes; this._chunkMarks = new_chunkMarks; }
Example 6
Source File: DiffEqualityTypeMapper.java From hollow with Apache License 2.0 | 4 votes |
protected int[] hashToOrdinals() { PopulatedOrdinalListener listener = toState.getListener(PopulatedOrdinalListener.class); final BitSet toPopulatedOrdinals = listener.getPopulatedOrdinals(); final int ordinalSpaceLength = toPopulatedOrdinals.length(); int hashedOrdinalsLength = 1 << (32 - Integer.numberOfLeadingZeros((toPopulatedOrdinals.cardinality() * 2) - 1)); final AtomicIntegerArray hashedToOrdinals = new AtomicIntegerArray(hashedOrdinalsLength); for(int i=0;i<hashedOrdinalsLength;i++) hashedToOrdinals.set(i, -1); SimultaneousExecutor executor = new SimultaneousExecutor(1.5d, getClass(), "hash-to-ordinals"); final int numThreads = executor.getCorePoolSize(); for(int i=0;i<numThreads;i++) { final int threadNumber = i; executor.execute(() -> { for(int t=threadNumber;t<ordinalSpaceLength;t+=numThreads) { if(toPopulatedOrdinals.get(t)) { int hashCode = toRecordHashCode(t); if(hashCode != -1) { int bucket = hashCode & (hashedToOrdinals.length() - 1); while(!hashedToOrdinals.compareAndSet(bucket, -1, t)) { bucket = (bucket + 1) & (hashedToOrdinals.length() - 1); } } } } }); } try { executor.awaitSuccessfulCompletion(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } int arr[] = new int[hashedToOrdinals.length()]; for(int i=0;i<arr.length;i++) { arr[i] = hashedToOrdinals.get(i); } return arr; }