org.armedbear.lisp.CharHashMap Maven / Gradle / Ivy
package org.armedbear.lisp;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class CharHashMap {
final public T[] constants;
final public T NULL;
final static int CACHE_SIZE = 256;
final HashMap backing;
@SuppressWarnings("unchecked")
public CharHashMap(Class componentType, T def) {
NULL = def;
constants = (T[]) Array.newInstance(componentType, CACHE_SIZE);
Arrays.fill(constants, NULL);
backing = new HashMap();
}
@Override
public Object clone() {
CharHashMap n = new CharHashMap(constants.getClass().getComponentType(),NULL);
System.arraycopy(constants,0, n.constants,0,CACHE_SIZE);
n.backing.putAll(backing);
return n;
}
public T get(char key) {
if (key getCharIterator() {
return new Iterator() {
final Iterator carIt = backing.keySet().iterator();
int charNum = -1;
public boolean hasNext() {
if ( charNum