/** Remove {@code o} from the set. * @return <tt>true</tt> if {@code o} was removed to the set, <tt>false</tt> * if {@code o} was not in the set. */ public boolean remove( final Object o ) { return _map.remove(o) == V; } /** Current count of elements in the set. Due to concurrent racing updates,
@Override public boolean remove ( Object k ) { return NonBlockingHashMap.this.remove (k) != null; } @Override public Iterator<TypeK> iterator() { return new SnapshotK(); }
public int run_normal(NonBlockingHashMap<String, String> hm) { SimpleRandom R = new SimpleRandom(); int get_ops = 0; int put_ops = 0; int del_ops = 0; while (!_stop) { int x = R.nextInt() & ((1 << 20) - 1); String key = KEYS[R.nextInt() & (KEYS.length - 1)]; if (x < _gr) { get_ops++; String val = hm.get(key); if (val != null && !val.equals(key)) throw new IllegalArgumentException("Mismatched key=" + key + " and val=" + val); } else if (x < _pr) { put_ops++; hm.putIfAbsent(key, key); } else { del_ops++; hm.remove(key); } } // We stopped; report results into shared result structure return get_ops + put_ops + del_ops; }
@Test public void removeResultIsBasedOnEquality() { NonBlockingHashMap<Integer, Integer> map = new NonBlockingHashMap<>(); Integer initialValue = new Integer(10); map.put(1, initialValue); assertTrue(map.remove(1, initialValue)); map.put(1, initialValue); assertTrue(map.remove(1, new Integer(10))); }
void work_helper(NonBlockingHashMap<String, String> nbhm, String thrd, int d) { final int ITERS = 20000; for (int j = 0; j < 10; j++) { //long start = System.nanoTime(); for (int i = d; i < ITERS; i += 2) { assertThat("this key not in there, so putIfAbsent must work", nbhm.putIfAbsent("k" + i, thrd), is((String) null)); } for (int i = d; i < ITERS; i += 2) { assertTrue(nbhm.remove("k" + i, thrd)); } //double delta_nanos = System.nanoTime()-start; //double delta_secs = delta_nanos/1000000000.0; //double ops = ITERS*2; //System.out.println("Thrd"+thrd+" "+(ops/delta_secs)+" ops/sec size="+nbhm.size()); } }
checkSizes(2); assertThat(_nbhm.putIfAbsent("k2", "v2b"), is("v2a")); assertThat(_nbhm.remove("k1"), is("v1a")); assertFalse(_nbhm.containsKey("k1")); checkSizes(1); assertThat(_nbhm.remove("k1"), nullValue()); assertThat(_nbhm.remove("k2"), is("v2a")); checkSizes(0); assertThat(_nbhm.remove("k2"), nullValue()); assertThat(_nbhm.remove("k3"), nullValue()); assertTrue(_nbhm.isEmpty()); assertTrue(_nbhm.containsKey("k0")); checkSizes(1); assertThat(_nbhm.remove("k0"), is("v0")); assertFalse(_nbhm.containsKey("k0")); checkSizes(0); assertEquals(_nbhm.replace("k0", "v0a"), "v0"); assertEquals(_nbhm.get("k0"), "v0a"); assertThat(_nbhm.remove("k0"), is("v0a")); assertFalse(_nbhm.containsKey("k0")); checkSizes(0); assertEquals(_nbhm.replace("k1", "v1a"), "v1"); assertEquals(_nbhm.get("k1"), "v1a"); assertThat(_nbhm.remove("k1"), is("v1a")); assertFalse(_nbhm.containsKey("k1")); checkSizes(0);
/** Remove {@code o} from the set. * @return <tt>true</tt> if {@code o} was removed to the set, <tt>false</tt> * if {@code o} was not in the set. */ public boolean remove( final Object o ) { return _map.remove(o) == V; } /** Current count of elements in the set. Due to concurrent racing updates,
@Override public boolean remove ( Object k ) { return NonBlockingHashMap.this.remove (k) != null; } @Override public Iterator<TypeK> iterator() { return new SnapshotK(); }