/** Auto-boxing version of {@link #putIfAbsent}. */ public TypeV putIfAbsent( Long key, TypeV val ) { return putIfAbsent( key.longValue(), val ); } /** Auto-boxing version of {@link #replace}. */
_hash.putIfAbsent(k, key);
public Integer call() throws Exception { _barrier.await(); int count = 0; for (TestKey item : _items) { if (_map.contains(item._id)) { System.err.printf("COLLISION DETECTED: %s exists\n", item.toString()); } final TestKey exists = _map.putIfAbsent(item._id, item); if (exists == null) { count++; } else { System.err.printf("COLLISION DETECTED: %s exists as %s\n", item.toString(), exists.toString()); } } return count; } }
void work_helper(NonBlockingHashMapLong<String> nbhml, int d, int num_thrds) { String thrd = "T" + d; final int ITERS = 20000; for (int j = 0; j < 10; j++) { //long start = System.nanoTime(); for (int i = d; i < ITERS; i += num_thrds) { assertThat("key " + i + " not in there, so putIfAbsent must work", nbhml.putIfAbsent((long) i, thrd), is((String) null)); } for (int i = d; i < ITERS; i += num_thrds) { assertTrue(nbhml.remove((long) 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="+nbhml.size()); } }
assertThat(_nbhml.put(1, "v1"), nullValue()); checkSizes(1); assertThat(_nbhml.putIfAbsent(2, "v2"), nullValue()); checkSizes(2); assertTrue(_nbhml.containsKey(2)); assertThat(_nbhml.put(2, "v2a"), is("v2")); checkSizes(2); assertThat(_nbhml.putIfAbsent(2, "v2b"), is("v2a")); assertThat(_nbhml.remove(1), is("v1a")); assertFalse(_nbhml.containsKey(1));
/** Auto-boxing version of {@link #putIfAbsent}. */ public TypeV putIfAbsent( Long key, TypeV val ) { return putIfAbsent( key.longValue(), val ); } /** Auto-boxing version of {@link #replace}. */