Java Code Examples for java.util.concurrent.atomic.AtomicInteger#getAndAccumulate()

The following examples show how to use java.util.concurrent.atomic.AtomicInteger#getAndAccumulate() . These examples are extracted from open source projects. 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 Project: aparapi   File: Kernel.java    License: Apache License 2.0 4 votes vote down vote up
@OpenCLMapping(atomic32 = true, mapTo = "atomic_min")
protected final int atomicMin(AtomicInteger p, int val) {
 return p.getAndAccumulate(val, minOperator);
}
 
Example 2
Source Project: aparapi   File: Kernel.java    License: Apache License 2.0 4 votes vote down vote up
@OpenCLMapping(atomic32 = true, mapTo = "atomic_max")
protected final int atomicMax(AtomicInteger p, int val) {
 return p.getAndAccumulate(val, maxOperator);
}
 
Example 3
Source Project: aparapi   File: Kernel.java    License: Apache License 2.0 4 votes vote down vote up
@OpenCLMapping(atomic32 = true, mapTo = "atomic_and")
protected final int atomicAnd(AtomicInteger p, int val) {
 return p.getAndAccumulate(val, andOperator);
}
 
Example 4
Source Project: aparapi   File: Kernel.java    License: Apache License 2.0 4 votes vote down vote up
@OpenCLMapping(atomic32 = true, mapTo = "atomic_or")
protected final int atomicOr(AtomicInteger p, int val) {
 return p.getAndAccumulate(val, orOperator);
}
 
Example 5
Source Project: aparapi   File: Kernel.java    License: Apache License 2.0 4 votes vote down vote up
@OpenCLMapping(atomic32 = true, mapTo = "atomic_xor")
protected final int atomicXor(AtomicInteger p, int val) {
 return p.getAndAccumulate(val, xorOperator);
}
 
Example 6
Source Project: algorithms   File: BinaryGapTest.java    License: MIT License 4 votes vote down vote up
@Test
public void collections() {
    Map<String, Integer> map1 = new HashMap<>();
    map1.values();
    map1.keySet();
    map1.isEmpty();
    map1.clear();
    map1.merge("t", 5, (v1, v2) -> v1 +v2);
    System.out.println(map1.get("t"));
    map1.merge("t", 4, (v1, v2) -> v1 +v2);
    System.out.println(map1.get("t"));
    System.out.println(map1.computeIfAbsent("r", k -> 1));
    System.out.println(map1.get("r"));
    map1.put("", 1);
    System.out.println(map1.computeIfPresent("", (k, v) -> v + 1));
    System.out.println(map1.get(""));
    System.out.println(map1.getOrDefault("", 5));
    map1.merge("", 5, (i, j) -> i + j);
    map1.merge("a", 5, (i, j) -> i + j);
    Set<Map.Entry<String, Integer>> entrySet = map1.entrySet();
    System.out.println(map1.compute("", (k,i) -> i + 1));
    System.out.println(map1.get(""));
    System.out.println(map1.get("a"));
    map1.putIfAbsent("d", 8);
    System.out.println(map1.replace("d", 9));
    System.out.println(map1.get("d"));
    map1.containsKey("d");
    map1.containsValue(8);
    map1.remove("d");

    NavigableMap<Integer, Integer> map2 = new TreeMap<>(Comparator.naturalOrder());
    map2.ceilingEntry(1);
    map2.ceilingKey(1);
    map2.floorEntry(1);
    map2.floorKey(1);
    map2.descendingKeySet();
    map2.descendingMap();
    map2.higherEntry(1);
    map2.higherKey(1);
    map2.lowerEntry(1);
    map2.lowerKey(1);
    map2.navigableKeySet();
    map2.firstEntry();
    map2.lastEntry();
    map2.pollFirstEntry();
    map2.pollLastEntry();

    Set<Integer> set = new HashSet<>();
    set.containsAll(new ArrayList<>());
    set.contains(1);
    set.add(1);
    set.size();
    set.clear();
    set.isEmpty();
    set.iterator();
    set.remove(1);
    NavigableSet<Integer> set1 = new TreeSet<>(Comparator.naturalOrder());
    set1.ceiling(1);
    set1.floor(1);
    set1.higher(1);
    set1.lower(1);
    set1.pollFirst();
    set1.pollLast();

    PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(Comparator.reverseOrder());
    priorityQueue.add(4);
    priorityQueue.add(2);
    priorityQueue.offer(3);

    int a = priorityQueue.peek();
    int b = priorityQueue.poll();
    priorityQueue.remove(1);

    CopyOnWriteArrayList<Integer> copyList = new CopyOnWriteArrayList<>();
    copyList.addIfAbsent(1);
    AtomicInteger atomicInteger = new AtomicInteger(0);
    int index = atomicInteger.getAndAccumulate(1, (i, j) -> (i+j) % 20);
    copyList.set(index, 2);
    copyList.iterator();
}