class Concurrent::Collection::AtomicReferenceMapBackend

def attempt_internal_replace(key, expected_old_value, hash, current_table, i, node, node_hash)

def attempt_internal_replace(key, expected_old_value, hash, current_table, i, node, node_hash)
  current_table.try_lock_via_hash(i, node, node_hash) do
    predecessor_node = nil
    old_value        = NULL
    begin
      if node.matches?(key, hash) && NULL != (current_value = node.value)
        if NULL == expected_old_value || expected_old_value == current_value # NULL == expected_old_value means whatever value
          old_value = current_value
          if NULL == (node.value = yield(old_value))
            current_table.delete_node_at(i, node, predecessor_node)
            decrement_size
          end
        end
        break
      end
      predecessor_node = node
    end while node = node.next
    return true, old_value
  end
end