// If keys are locked, we can share the same keys.
 public StringDoubleMap copy() {
   StringDoubleMap newMap = new StringDoubleMap();
   newMap.mapType = mapType;
   newMap.locked = locked;
   newMap.num = num;
   newMap.keys = locked ? keys : (String[]) keys.clone(); // Share keys!
   newMap.values = (double[]) values.clone();
   return newMap;
 }
 // Return a map with only keys in the set
 public StringDoubleMap restrict(Set<String> set) {
   StringDoubleMap newMap = new StringDoubleMap();
   newMap.mapType = mapType;
   if (mapType == MapType.SORTED_LIST) {
     newMap.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;
 }