internal Set(IEnumerable <T> items) { set = SetItem <T> .Empty; // TODO: Perf foreach (var item in items) { set = SetModule.Add(set, item, Comparer <T> .Default); } }
public IEnumerable <A> FindRange(A keyFrom, A keyTo) { if (isnull(keyFrom)) { throw new ArgumentNullException(nameof(keyFrom)); } if (isnull(keyTo)) { throw new ArgumentNullException(nameof(keyTo)); } return(default(OrdA).Compare(keyFrom, keyTo) > 0 ? SetModule.FindRange <OrdA, A>(set, keyTo, keyFrom) : SetModule.FindRange <OrdA, A>(set, keyFrom, keyTo)); }
/// <summary> /// Ctor that takes an initial (distinct) set of items /// </summary> /// <param name="items"></param> internal SetInternal(IEnumerable <A> items, bool tryAdd) { set = SetItem <A> .Empty; if (tryAdd) { foreach (var item in items) { set = SetModule.TryAdd <OrdA, A>(set, item); } } else { foreach (var item in items) { set = SetModule.Add <OrdA, A>(set, item); } } }
/// <summary> /// Ctor that takes an initial (distinct) set of items /// </summary> /// <param name="items"></param> internal Set(IEnumerable <T> items, bool checkUniqueness = false) { set = SetItem <T> .Empty; if (checkUniqueness) { foreach (var item in items) { set = SetModule.TryAdd(set, item, Comparer <T> .Default); } } else { foreach (var item in items) { set = SetModule.Add(set, item, Comparer <T> .Default); } } }
public Option <A> FindOrSuccessor(A key) => SetModule.TryFindOrSuccessor <OrdA, A>(set, key);
public Option <A> Find(A value) => SetModule.TryFind <OrdA, A>(set, value);
public SetInternal <OrdA, A> AddOrUpdate(A value) => new SetInternal <OrdA, A>(SetModule.AddOrUpdate <OrdA, A>(set, value));
public bool Exists(Func <A, bool> pred) => SetModule.Exists(set, pred);
public SetInternal <OrdB, B> Map <OrdB, B>(Func <A, B> f) where OrdB : struct, Ord <B> => new SetInternal <OrdB, B>(SetModule.Map(set, f));
public bool Contains(T value) => SetModule.Contains(set, value, Comparer <T> .Default);
public Set <T> Filter(Func <T, bool> pred) => new Set <T>(SetModule.Filter(set, pred));
public S Fold <S>(S state, Func <S, T, S> folder) => SetModule.Fold(set, state, folder);
public Set <T> Remove(T value) => new Set <T>(SetModule.Remove(set, value, Comparer <T> .Default));
public SetInternal <OrdA, A> Remove(A value) => new SetInternal <OrdA, A>(SetModule.Remove <OrdA, A>(set, value));
public Set <T> Add(T value) => new Set <T>(SetModule.Add(set, value, Comparer <T> .Default));
public S FoldBack <S>(S state, Func <S, A, S> folder) => SetModule.FoldBack(set, state, folder);
public Option <T> Find(T value) => SetModule.Find(set, value, Comparer <T> .Default);
public SetInternal <OrdA, A> Map(Func <A, A> f) => new SetInternal <OrdA, A>(SetModule.Map(set, f));
public SetInternal <OrdA, A> Add(A value) => new SetInternal <OrdA, A>(SetModule.Add <OrdA, A>(set, value));
public bool Contains(A value) => SetModule.Contains <OrdA, A>(set, value);
public SetInternal <OrdA, A> Filter(Func <A, bool> pred) => new SetInternal <OrdA, A>(SetModule.Filter(set, pred));