// 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;
 }
 // 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;
 }