*/
package org.opendaylight.yangtools.triemap;
+import static org.opendaylight.yangtools.triemap.LookupResult.RESTART;
+import static org.opendaylight.yangtools.triemap.PresencePredicate.ABSENT;
+import static org.opendaylight.yangtools.triemap.PresencePredicate.PRESENT;
+
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
final class INode<K, V> extends BasicNode {
-
- static final Object KEY_PRESENT = new Object ();
- static final Object KEY_ABSENT = new Object ();
-
- /**
- * Virtual result for lookup methods indicating that the lookup needs to be restarted. This is a faster version
- * of throwing a checked exception to control the restart.
- */
- static final Object RESTART = new Object();
-
@SuppressWarnings("rawtypes")
private static final AtomicReferenceFieldUpdater<INode, MainNode> MAINNODE_UPDATER =
AtomicReferenceFieldUpdater.newUpdater(INode.class, MainNode.class, "mainnode");
}
return null;
- } else if (cond == INode.KEY_ABSENT) {
+ } else if (cond == ABSENT) {
if (sn.hc == hc && ct.equal(sn.k, k)) {
return Optional.of(sn.v);
}
}
return null;
- } else if (cond == INode.KEY_PRESENT) {
+ } else if (cond == PRESENT) {
if (sn.hc == hc && ct.equal(sn.k, k)) {
if (GCAS(cn, cn.updatedAt(pos, new SNode<>(k, v, hc), gen), ct)) {
return Optional.of(sn.v);
return Optional.empty();
}
}
- } else if (cond == null || cond == INode.KEY_ABSENT) {
+ } else if (cond == null || cond == ABSENT) {
final CNode<K, V> rn = (cn.gen == gen) ? cn : cn.renewed(gen, ct);
final CNode<K, V> ncnode = rn.insertedAt (pos, flag, new SNode<>(k, v, hc), gen);
if (GCAS(cn, ncnode, ct)) {
}
return null;
- } else if (cond == INode.KEY_PRESENT) {
- return Optional.empty();
} else {
return Optional.empty();
}
return optv;
}
return null;
- } else if (cond == INode.KEY_ABSENT) {
+ } else if (cond == ABSENT) {
final Optional<V> t = ln.get(k);
if (t.isPresent()) {
return t;
return Optional.empty();
}
return null;
- } else if (cond == INode.KEY_PRESENT) {
+ } else if (cond == PRESENT) {
final Optional<V> t = ln.get(k);
if (!t.isPresent()) {
return t;
continue;
}
- // used to be throw RestartException
return RESTART;
} else if (sub instanceof SNode) {
// 2) singleton node
return null;
}
- // used to be throw RestartException
clean(parent, ct, lev - 5);
return RESTART;
}
--- /dev/null
+/*
+ * (C) Copyright 2017 Pantheon Technologies, s.r.o. and others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opendaylight.yangtools.triemap;
+
+/**
+ * Virtual result for lookup methods indicating that the lookup needs to be restarted. This is a faster version
+ * of throwing a checked exception to control restart.
+ *
+ * @author Robert Varga
+ */
+enum LookupResult {
+ RESTART;
+}
--- /dev/null
+/*
+ * (C) Copyright 2017 Pantheon Technologies, s.r.o. and others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opendaylight.yangtools.triemap;
+
+/**
+ * Presence predicate. These are specialized objects passed down from callers to indicate an assertion about
+ * whether a mapping is required.
+ *
+ * @author Robert Varga
+ */
+enum PresencePredicate {
+ ABSENT,
+ PRESENT;
+}
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
+import static org.opendaylight.yangtools.triemap.LookupResult.RESTART;
+import static org.opendaylight.yangtools.triemap.PresencePredicate.ABSENT;
+import static org.opendaylight.yangtools.triemap.PresencePredicate.PRESENT;
import com.google.common.base.Verify;
import com.google.common.collect.Iterators;
do {
// Keep looping as long as RESTART is being indicated
res = RDCSS_READ_ROOT().rec_lookup(k, hc, 0, null, this);
- } while (INode.RESTART.equals(res));
+ } while (res == RESTART);
return (V) res;
}
public V putIfAbsent(final K key, final V value) {
ensureReadWrite();
final K k = checkNotNull(key);
- return insertifhc(k, computeHash(k), checkNotNull(value), INode.KEY_ABSENT).orElse(null);
+ return insertifhc(k, computeHash(k), checkNotNull(value), ABSENT).orElse(null);
}
@Override
public V replace(final K key, final V value) {
ensureReadWrite();
final K k = checkNotNull(key);
- return insertifhc (k, computeHash(k), checkNotNull(value), INode.KEY_PRESENT).orElse(null);
+ return insertifhc (k, computeHash(k), checkNotNull(value), PRESENT).orElse(null);
}
/***