// Path: src/chap6/Environment.java
// public interface Environment {
//     void put(String name, Object value);
//     Object get(String name);
// }
// 
// Path: src/chap11/EnvOptimizer.java
// @Reviser public static interface EnvEx2 extends Environment {
//     Symbols symbols();
//     void put(int nest, int index, Object value);
//     Object get(int nest, int index);
//     void putNew(String name, Object value);
//     Environment where(String name);
// }


import java.util.Arrays;
import chap6.Environment;
import chap11.EnvOptimizer.EnvEx2;
package chap11;

public class ResizableArrayEnv extends ArrayEnv {
    protected Symbols names;
    public ResizableArrayEnv() {
        super(10, null);
        names = new Symbols();
    }
    @Override public Symbols symbols() { return names; }
    @Override public Object get(String name) {
        Integer i = names.find(name);
        if (i == null)
            if (outer == null)
                return null;
            else
                return outer.get(name);
        else
            return values[i];
    }
    @Override public void put(String name, Object value) {
        Environment e = where(name);
        if (e == null)
            e = this;
// Path: src/chap6/Environment.java
// public interface Environment {
//     void put(String name, Object value);
//     Object get(String name);
// }
// 
// Path: src/chap11/EnvOptimizer.java
// @Reviser public static interface EnvEx2 extends Environment {
//     Symbols symbols();
//     void put(int nest, int index, Object value);
//     Object get(int nest, int index);
//     void putNew(String name, Object value);
//     Environment where(String name);
// }


// Path: src/chap11/ResizableArrayEnv.java
import java.util.Arrays;
import chap6.Environment;
import chap11.EnvOptimizer.EnvEx2;

package chap11;

public class ResizableArrayEnv extends ArrayEnv {
    protected Symbols names;
    public ResizableArrayEnv() {
        super(10, null);
        names = new Symbols();
    }
    @Override public Symbols symbols() { return names; }
    @Override public Object get(String name) {
        Integer i = names.find(name);
        if (i == null)
            if (outer == null)
                return null;
            else
                return outer.get(name);
        else
            return values[i];
    }
    @Override public void put(String name, Object value) {
        Environment e = where(name);
        if (e == null)
            e = this;
        ((EnvEx2)e).putNew(name, value);