BagT Class |
Namespace: X3Platform.Collections
[Missing <typeparam name="T"/> documentation for "T:X3Platform.Collections.Bag`1"]
The BagT type exposes the following members.
Name | Description | |
---|---|---|
![]() | BagT |
Creates a new Bag.
|
![]() | BagT(IEnumerableT) |
Creates a new Bag. The bag is
initialized with all the items in the given collection.
|
![]() | BagT(IEqualityComparerT) |
Creates a new Bag. The Equals and GetHashCode methods of the passed comparison object
will be used to compare items in this bag for equality.
|
![]() | BagT(IEnumerableT, IEqualityComparerT) |
Creates a new Bag. The Equals and GetHashCode methods of the passed comparison object
will be used to compare items in this bag. The bag is
initialized with all the items in the given collection.
|
Name | Description | |
---|---|---|
![]() | Add |
Adds a new item to the bag. Since bags can contain duplicate items, the item
is added even if the bag already contains an item equal to item. In
this case, the count of items for the representative item is increased by one, but the existing
represetative item is unchanged.
(Overrides CollectionBaseTAdd(T).) |
![]() | AddMany |
Adds all the items in collection to the bag.
|
![]() | AddRepresentative |
Adds a new item to the bag. Since bags can contain duplicate items, the item
is added even if the bag already contains an item equal to item. In
this case (unlike Add), the new item becomes the representative item.
|
![]() | AsReadOnly |
Provides a read-only view of this collection. The returned ICollection<T> provides
a view of the collection that prevents modifications to the collection. Use the method to provide
access to the collection without allowing changes. Since the returned object is just a view,
changes to the collection will be reflected in the view.
(Inherited from CollectionBaseT.) |
![]() | ChangeNumberOfCopies |
Changes the number of copies of an existing item in the bag, or adds the indicated number
of copies of the item to the bag.
|
![]() | Clear |
Removes all items from the bag.
(Overrides CollectionBaseTClear.) |
![]() | Clone |
Makes a shallow clone of this bag; i.e., if items of the
bag are reference types, then they are not cloned. If T is a value type,
then each element is copied as if by simple assignment.
|
![]() | CloneContents |
Makes a deep clone of this bag. A new bag is created with a clone of
each element of this bag, by calling ICloneable.Clone on each element. If T is
a value type, then each element is copied as if by simple assignment.
|
![]() | Contains |
Determines if this bag contains an item equal to item. The bag
is not changed.
(Overrides CollectionBaseTContains(T).) |
![]() | ConvertAllTOutput |
Convert this collection of items by applying a delegate to each item in the collection. The resulting enumeration
contains the result of applying converter to each item in this collection, in
order.
(Inherited from CollectionBaseT.) |
![]() | CopyTo |
Copies all the items in the collection into an array. Implemented by
using the enumerator returned from GetEnumerator to get all the items
and copy them to the provided array.
(Inherited from CollectionBaseT.) |
![]() | CountWhere |
Counts the number of items in the collection that satisfy the condition
defined by predicate.
(Inherited from CollectionBaseT.) |
![]() | Difference |
Computes the difference of this bag with another bag. The difference of these two bags
is all items that appear in this bag, but not in otherBag. If an item appears X times in this bag,
and Y times in the other bag, the difference contains the item X - Y times (zero times if Y >= X). A new bag is
created with the difference of the bags and is returned. This bag and the other bag
are unchanged.
|
![]() | DifferenceWith |
Computes the difference of this bag with another bag. The difference of these two bags
is all items that appear in this bag, but not in otherBag. If an item appears X times in this bag,
and Y times in the other bag, the difference contains the item X - Y times (zero times if Y >= X). This bag receives
the difference of the two bags; the other bag is unchanged.
|
![]() | DistinctItems |
Enumerates all the items in the bag, but enumerates equal items
just once, even if they occur multiple times in the bag.
|
![]() | Equals | (Inherited from Object.) |
![]() | Exists |
Determines if the collection contains any item that satisfies the condition
defined by predicate.
(Inherited from CollectionBaseT.) |
![]() | Finalize | (Inherited from Object.) |
![]() | FindAll |
Enumerates the items in the collection that satisfy the condition defined
by predicate.
(Inherited from CollectionBaseT.) |
![]() | ForEach |
Performs the specified action on each item in this collection.
(Inherited from CollectionBaseT.) |
![]() | GetEnumerator |
Returns an enumerator that enumerates all the items in the bag.
If an item is present multiple times in the bag, the representative item is yielded by the
enumerator multiple times. The order of enumeration is haphazard and may change.
(Overrides CollectionBaseTGetEnumerator.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetRepresentativeItem |
Returns the representative item stored in the bag that is equal to
the provided item. Also returns the number of copies of the item in the bag.
|
![]() | GetType | (Inherited from Object.) |
![]() | Intersection |
Computes the intersection of this bag with another bag. The intersection of two bags
is all items that appear in both of the bags. If an item appears X times in one bag,
and Y times in the other bag, the intersection contains the item Minimum(X,Y) times. A new bag is
created with the intersection of the bags and is returned. This bag and the other bag
are unchanged.
|
![]() | IntersectionWith |
Computes the intersection of this bag with another bag. The intersection of two bags
is all items that appear in both of the bags. If an item appears X times in one bag,
and Y times in the other bag, the sum contains the item Minimum(X,Y) times. This bag receives
the intersection of the two bags, the other bag is unchanged.
|
![]() | IsDisjointFrom |
Determines if this bag is disjoint from another bag. Two bags are disjoint
if no item from one set is equal to any item in the other bag.
|
![]() | IsEqualTo |
Determines if this bag is equal to another bag. This bag is equal to
otherBag if they contain the same number of
of copies of equal elements.
|
![]() | IsProperSubsetOf |
Determines if this bag is a proper subset of another bag. Neither bag is modified.
This bag is a subset of otherBag if every element in this bag
is also in otherBag, at least the same number of
times. Additional, this bag must have strictly fewer items than otherBag.
|
![]() | IsProperSupersetOf |
Determines if this bag is a proper superset of another bag. Neither bag is modified.
This bag is a proper superset of otherBag if every element in
otherBag is also in this bag, at least the same number of
times. Additional, this bag must have strictly more items than otherBag.
|
![]() | IsSubsetOf |
Determines if this bag is a subset of another ba11 items in this bag.
|
![]() | IsSupersetOf |
Determines if this bag is a superset of another bag. Neither bag is modified.
This bag is a superset of otherBag if every element in
otherBag is also in this bag, at least the same number of
times.
|
![]() | MemberwiseClone | (Inherited from Object.) |
![]() | NumberOfCopies |
Returns the number of copies of item in the bag.
|
![]() | Remove |
Searches the bag for one item equal to item, and if found,
removes it from the bag. If not found, the bag is unchanged.
(Overrides CollectionBaseTRemove(T).) |
![]() | RemoveAll |
Removes all the items in the collection that satisfy the condition
defined by predicate.
(Inherited from CollectionBaseT.) |
![]() | RemoveAllCopies |
Searches the bag for all items equal to item, and
removes all of them from the bag. If not found, the bag is unchanged.
|
![]() | RemoveMany |
Removes all the items in collection from the bag. Items that
are not present in the bag are ignored.
|
![]() | Sum |
Computes the sum of this bag with another bag. he sum of two bags
is all items from both of the bags. If an item appears X times in one bag,
and Y times in the other bag, the sum contains the item (X+Y) times. A new bag is
created with the sum of the bags and is returned. This bag and the other bag
are unchanged.
|
![]() | SumWith |
Computes the sum of this bag with another bag. The sum of two bags
is all items from both of the bags. If an item appears X times in one bag,
and Y times in the other bag, the sum contains the item (X+Y) times. This bag receives
the sum of the two bags, the other bag is unchanged.
|
![]() | SymmetricDifference |
Computes the symmetric difference of this bag with another bag. The symmetric difference of two bags
is all items that appear in either of the bags, but not both. If an item appears X times in one bag,
and Y times in the other bag, the symmetric difference contains the item AbsoluteValue(X - Y) times. A new bag is
created with the symmetric difference of the bags and is returned. This bag and the other bag
are unchanged.
|
![]() | SymmetricDifferenceWith |
Computes the symmetric difference of this bag with another bag. The symmetric difference of two bags
is all items that appear in either of the bags, but not both. If an item appears X times in one bag,
and Y times in the other bag, the symmetric difference contains the item AbsoluteValue(X - Y) times. This bag receives
the symmetric difference of the two bags; the other bag is unchanged.
|
![]() | ToArray |
Creates an array of the correct size, and copies all the items in the
collection into the array, by calling CopyTo.
(Inherited from CollectionBaseT.) |
![]() | ToString |
Shows the string representation of the collection. The string representation contains
a list of the items in the collection. Contained collections (except string) are expanded
recursively.
(Inherited from CollectionBaseT.) |
![]() | TrueForAll |
Determines if all of the items in the collection satisfy the condition
defined by predicate.
(Inherited from CollectionBaseT.) |
![]() | Union |
Computes the union of this bag with another bag. The union of two bags
is all items from both of the bags. If an item appears X times in one bag,
and Y times in the other bag, the union contains the item Maximum(X,Y) times. A new bag is
created with the union of the bags and is returned. This bag and the other bag
are unchanged.
|
![]() | UnionWith |
Computes the union of this bag with another bag. The union of two bags
is all items from both of the bags. If an item appears X times in one bag,
and Y times in the other bag, the union contains the item Maximum(X,Y) times. This bag receives
the union of the two bags, the other bag is unchanged.
|
Name | Description | |
---|---|---|
![]() | Comparer |
Returns the IEqualityComparer<T> used to compare items in this bag.
|
![]() | Count |
Returns the number of items in the bag.
(Overrides CollectionBaseTCount.) |
The items are compared in one of two ways. If T implements IComparable<T> then the Equals method of that interface will be used to compare items, otherwise the Equals method from Object will be used. Alternatively, an instance of IComparer<T> can be passed to the constructor to use to compare items.
Bag is implemented as a hash table. Inserting, deleting, and looking up an an element all are done in approximately constant time, regardless of the number of items in the bag.
When multiple equal items are stored in the bag, they are stored as a representative item and a count. If equal items can be distinguished, this may be noticable. For example, if a case-insensitive comparer is used with a Bag<string>, and both "hello", and "HELLO" are added to the bag, then the bag will appear to contain two copies of "hello" (the representative item).
OrderedBagT is similar, but uses comparison instead of hashing, maintain the items in sorted order, and stores distinct copies of items that compare equal.