/* * (C) Copyright 2016 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; import java.util.Map.Entry; final class LNode extends MainNode { final ListMap listmap; LNode(final ListMap listmap) { this.listmap = listmap; } LNode(final K k, final V v) { this(ListMap.map(k, v)); } LNode(final K k1, final V v1, final K k2, final V v2) { this(ListMap.map(k1, v1, k2, v2)); } LNode inserted(final K k, final V v) { return new LNode<> (listmap.add (k, v)); } MainNode removed (final K k, final TrieMap ct) { ListMap updmap = listmap.remove(k); if (updmap.size () > 1) { return new LNode<> (updmap); } final Entry kv = updmap.iterator().next(); // create it tombed so that it gets compressed on subsequent accesses return new TNode<>(kv.getKey(), kv.getValue(), ct.computeHash(kv.getKey())); } Option get(final K k) { return listmap.get(k); } @Override int cachedSize(final TrieMap ct) { return listmap.size(); } @Override String string(final int lev) { // (" " * lev) + "LNode(%s)".format(listmap.mkString(", ")) return "LNode"; } }