/// <summary>
/// Create a <see cref="PersistentArrayMap">PersistentArrayMap</see> (if small enough, else create a <see cref="PersistentHashMap">PersistentHashMap</see>.
/// </summary>
/// <param name="other">The BCL map to initialize from</param>
/// <returns>A new persistent map.</returns>
public static IPersistentMap create(IDictionary other)
{
// Java version has this. Seems wasteful.
//IPersistentMap ret = EMPTY;
//foreach (DictionaryEntry e in other)
//{
// ret = ret.assoc(e.Key, e.Value);
//}
//return ret;
if (other.Count > HASHTABLE_THRESHOLD / 2)
{
return(PersistentHashMap.create(other));
}
object[] array = new object[other.Count * 2];
int i = 0;
foreach (DictionaryEntry e in other)
{
array[2 * i] = e.Key;
array[2 * i + 1] = e.Value;
i++;
}
return(new PersistentArrayMap(array));
}