/*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * 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 com.facebook.rendercore;

import androidx.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;

/**
 * A Cache that can be used to re use LayoutResults or parts of them across layout calculations.
 * It's responsibility of the implementer of the Layout function to put values in the cache for a
 * given node. Values put in the LayoutCache will only be available in the next layout pass.
 */
public class LayoutCache {
  private final Map<Node, Node.LayoutResult> mWriteCache;
  private final Map<Node, Node.LayoutResult> mReadCache;

  LayoutCache() {
    this(new HashMap<Node, Node.LayoutResult>());
  }

  LayoutCache(@Nullable Map<Node, Node.LayoutResult> cacheResult) {
    mWriteCache = new HashMap<>();
    if (cacheResult == null) {
      mReadCache = new HashMap<>();
    } else {
      mReadCache = cacheResult;
    }
  }

  public void put(Node node, Node.LayoutResult layout) {
    mWriteCache.put(node, layout);
  }

  public Node.LayoutResult get(Node node) {
    return mReadCache.get(node);
  }

  Map<Node, Node.LayoutResult> getWriteCache() {
    return mWriteCache;
  }
}

@@ -1077,33 +1077,8 @@
  Map
-%3CNode, Node.LayoutResult%3E
  mWr
@@ -1110,33 +1110,8 @@
  Map
-%3CNode, Node.LayoutResult%3E
  mRe
@@ -1224,33 +1224,8 @@
  Map
-%3CNode, Node.LayoutResult%3E
  cac
@@ -1550,27 +1550,220 @@
 urn 
-mReadCache.get(node
+(Node.LayoutResult) mReadCache.get(node);%0A  %7D%0A%0A  public %3CT%3E void put(long uniqueId, T value) %7B%0A    mWriteCache.put(uniqueId, value);%0A  %7D%0A%0A  public %3CT%3E T get(long uniqueId) %7B%0A    return (T) mReadCache.get(uniqueId
 );%0A 

Allow Nodes to put id scoped values in the LayoutCache