public static IMutableSeq <T> Of <T>(IEnumerable <T> values) { IMutableSeq <T> mseq; if (values is IImmutableSeq <T> ) { var seq = (values as IImmutableSeq <T>); mseq = seq.IsEmpty ? Empty <T>() : Of <T>(seq); } else if (values is IMutableSeq <T> ) { var seq = (IMutableSeq <T>)values; mseq = seq.IsEmpty ? Empty <T>() : Of <T>(seq); } else if (values is ICollection <T> ) { var collection = (ICollection <T>)values; mseq = collection.Count == 0 ? Empty <T>() : OfLength <T>(collection.Count).SetAll(values); } else { var array = values.ToArray(); mseq = array.Length == 0 ? Empty <T>() : new ArrayMutableSeq <T>(Array.Of(ObjectStore.Of(array))); } return(mseq); }
private static char[] Distinct(char[] chars) { System.Array.Sort(chars); var j = 0; for (var i = 1; i < chars.Length; ++i) { if (chars[j] != chars[i]) { chars[++j] = chars[i]; } } var size = Math.Min(chars.Length, j + 1); var array = new char[size]; System.Array.Copy(chars, 0, array, 0, size); return(array); }
public static IMutableSeq <T> Of <T>(params T[] values) { return(values.Length == 0 ? Empty <T>() : new ArrayMutableSeq <T>(Array.Of(ObjectStore.Of((T[])values.Clone())))); }
public static IMutableSeq <T> OfLength <T>(int length) { return(length == 0 ? Empty <T>() : new ArrayMutableSeq <T>(Array.Of(ObjectStore.OfLength <T>(length)))); }
public CharSeq(char[] characters) : base(Distinct((char[])characters.Clone())) { }
protected CharSeqBase(SerializationInfo info, StreamingContext context) : base(Array.OfLength <char>(0)) { Values = (char[])info.GetValue("_array", typeof(char[])); base.Values = Array.Of(CharStore.Of(Values)).Seal(); }
protected CharSeqBase(char[] characters) : base(Array.Of(CharStore.Of(characters)).Seal()) { Values = characters; }