2 * (C) Copyright 2016 Pantheon Technologies, s.r.o. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.opendaylight.yangtools.triemap;
18 final class LNode<K, V> extends MainNode<K, V> {
19 // Internally-linked single list of of entries
20 private final LNodeEntries<K, V> entries;
21 private final int size;
23 private LNode(final LNodeEntries<K, V> entries, final int size) {
24 this.entries = entries;
28 LNode(final K k1, final V v1, final K k2, final V v2) {
29 this(LNodeEntries.map(k1, v1, k2, v2), 2);
32 LNode<K, V> insertChild(final K key, final V value) {
33 return new LNode<>(entries.insert(key, value), size + 1);
36 MainNode<K, V> removeChild(final LNodeEntry<K, V> entry, final int hc) {
37 // While remove() can return null, that case will never happen here, as we are starting off with two entries
38 // so we cannot observe a null return here.
39 final LNodeEntries<K, V> map = entries.remove(entry);
41 // If the returned LNode would have only one element, we turn it into a TNode, hence above null return from
42 // remove() can never happen.
44 // create it tombed so that it gets compressed on subsequent accesses
45 return new TNode<>(map.getKey(), map.getValue(), hc);
48 return new LNode<>(map, size - 1);
51 MainNode<K, V> replaceChild(final LNodeEntry<K, V> entry, final V value) {
52 return new LNode<>(entries.replace(entry, value), size);
55 LNodeEntry<K, V> get(final Equivalence<? super K> equiv, final K key) {
56 return entries.findEntry(equiv, key);
59 LNodeEntries<K, V> entries() {
69 int size(final ImmutableTrieMap<?, ?> ct) {