// Construct a map from a list of key, value, key value arguments.
 public static <T> TDoubleMap newMap(Object... args) {
   if (args.length % 2 != 0) throw Exceptions.bad;
   TDoubleMap map = new TDoubleMap();
   for (int i = 0; i < args.length; i += 2) {
     T key = (T) args[i];
     Object value = args[i + 1];
     if (value instanceof Integer) value = (double) ((Integer) value);
     map.put((T) args[i], (Double) value);
   }
   return map;
 }
 // Return a map with only keys in the set
 public TDoubleMap<T> restrict(Set<T> set) {
   TDoubleMap<T> newMap = new TDoubleMap<T>(keyFunc);
   newMap.mapType = mapType;
   if (mapType == MapType.SORTED_LIST) {
     allocate(getCapacity(num, false));
     for (int i = 0; i < keys.length; i++) {
       if (set.contains(keys[i])) {
         newMap.keys[newMap.num] = keys[i];
         newMap.values[newMap.num] = values[i];
         newMap.num++;
       }
     }
   } else if (mapType == MapType.HASH_TABLE) {
     for (int i = 0; i < keys.length; i++)
       if (keys[i] != null && set.contains(keys[i])) newMap.put(keys[i], values[i]);
   }
   newMap.locked = locked;
   return newMap;
 }
 // If keys are locked, we can share the same keys.
 public TDoubleMap<T> copy() {
   TDoubleMap<T> newMap = new TDoubleMap<T>(keyFunc);
   newMap.mapType = mapType;
   newMap.locked = locked;
   newMap.num = num;
   newMap.keys = locked ? keys : (T[]) keys.clone(); // Share keys! CHECKED
   newMap.values = values.clone();
   return newMap;
 }
 public TDoubleMap toTDoubleMap() {
   TDoubleMap map = new TDoubleMap();
   for (int i = 0; i < keys.length; i++) if (keys[i] != null) map.put(keys[i], values[i]);
   return map;
 }