Class HashBag<T>

A bag collection based on a hash table of (item,count) pairs.

Implements

IEnumerable<T>, System.Collections.IEnumerable, System.IFormattable, System.ICloneable, System.Collections.Generic.ICollection<T>, ICollection<T>, ICollectionValue<T>, IExtensible<T>, IShowable

Bases

object, EnumerableBase<T>, CollectionValueBase<T>, CollectionBase<T>

Field overview

isReadOnlyBase, Inherited from CollectionBase<T> ,
itemequalityComparer, Inherited from CollectionBase<T> ,
size, Inherited from CollectionBase<T> ,
stamp, Inherited from CollectionBase<T>

Event overview

CollectionChanged, Inherited from CollectionValueBase<T> ,
CollectionCleared, Inherited from CollectionValueBase<T> ,
ItemInserted, Inherited from CollectionValueBase<T> ,
ItemRemovedAt, Inherited from CollectionValueBase<T> ,
ItemsAdded, Inherited from CollectionValueBase<T> ,
ItemsRemoved, Inherited from CollectionValueBase<T>

Property overview

ActiveEvents, Inherited from CollectionValueBase<T> ,
AllowsDuplicates ,
ContainsSpeed ,
Count, Inherited from CollectionBase<T> ,
CountSpeed, Inherited from CollectionBase<T> ,
DuplicatesByCounting ,
EqualityComparer, Inherited from CollectionBase<T> ,
IsEmpty, Inherited from CollectionBase<T> ,
IsReadOnly, Inherited from CollectionBase<T> ,
ListenableEvents

Constructor overview

HashBag<T>() ,
HashBag<T>(System.Collections.Generic.IEqualityComparer<T> itemequalityComparer) ,
HashBag<T>(int capacity, System.Collections.Generic.IEqualityComparer<T> itemequalityComparer) ,
HashBag<T>(int capacity, double fill, System.Collections.Generic.IEqualityComparer<T> itemequalityComparer)

Method overview

Add(T item) ,
AddAll<U>(IEnumerable<U> items) ,
All(Fun<T,bool> predicate), Inherited from CollectionValueBase<T> ,
Apply(Act<T> action), Inherited from CollectionValueBase<T> ,
Check() ,
checkRange(int start, int count), Inherited from CollectionBase<T> ,
Choose() ,
Clear() ,
Clone() ,
Contains(T item) ,
ContainsAll<U>(IEnumerable<U> items) ,
ContainsCount(T item) ,
CopyTo(T[] array, int index) ,
Equals(object obj), Inherited from object ,
Exists(Fun<T,bool> predicate), Inherited from CollectionValueBase<T> ,
Filter(Fun<T,bool> predicate), Inherited from CollectionValueBase<T> ,
Finalize(), Inherited from object ,
Find(ref T item) ,
Find(Fun<T,bool> predicate, out T item), Inherited from CollectionValueBase<T> ,
FindOrAdd(ref T item) ,
GetEnumerator() ,
GetHashCode(), Inherited from object ,
GetType(), Inherited from object ,
GetUnsequencedHashCode(), Inherited from CollectionBase<T> ,
ItemMultiplicities() ,
MemberwiseClone(), Inherited from object ,
modifycheck(int thestamp), Inherited from CollectionBase<T> ,
raiseCollectionChanged(), Inherited from CollectionValueBase<T> ,
raiseCollectionCleared(bool full, int count), Inherited from CollectionValueBase<T> ,
raiseCollectionCleared(bool full, int count, System.Nullable<int> offset), Inherited from CollectionValueBase<T> ,
raiseForAdd(T item), Inherited from CollectionValueBase<T> ,
raiseForInsert(int i, T item), Inherited from CollectionValueBase<T> ,
raiseForRemove(T item), Inherited from CollectionValueBase<T> ,
raiseForRemove(T item, int count), Inherited from CollectionValueBase<T> ,
raiseForRemoveAll(ICollectionValue<T> wasRemoved), Inherited from CollectionValueBase<T> ,
raiseForRemoveAt(int index, T item), Inherited from CollectionValueBase<T> ,
raiseForSetThis(int index, T value, T item), Inherited from CollectionValueBase<T> ,
raiseForUpdate(T newitem, T olditem), Inherited from CollectionValueBase<T> ,
raiseForUpdate(T newitem, T olditem, int count), Inherited from CollectionValueBase<T> ,
raiseItemInserted(T item, int index), Inherited from CollectionValueBase<T> ,
raiseItemRemovedAt(T item, int index), Inherited from CollectionValueBase<T> ,
raiseItemsAdded(T item, int count), Inherited from CollectionValueBase<T> ,
raiseItemsRemoved(T item, int count), Inherited from CollectionValueBase<T> ,
Remove(T item) ,
Remove(T item, out T removeditem) ,
RemoveAll<U>(IEnumerable<U> items) ,
RemoveAllCopies(T item) ,
RetainAll<U>(IEnumerable<U> items) ,
Show(System.Text.StringBuilder stringbuilder, ref int rest, System.IFormatProvider formatProvider), Inherited from CollectionValueBase<T> ,
ToArray() ,
ToString(string format, System.IFormatProvider formatProvider), Inherited from CollectionValueBase<T> ,
ToString(), Inherited from CollectionValueBase<T> ,
UniqueItems() ,
UnsequencedEquals(ICollection<T> otherCollection), Inherited from CollectionBase<T> ,
Update(T item) ,
Update(T item, out T olditem) ,
updatecheck(), Inherited from CollectionBase<T> ,
UpdateOrAdd(T item) ,
UpdateOrAdd(T item, out T olditem)

Property details

bool AllowsDuplicatesAccess: Read-Only

Value:Always true

Report if this is a set collection.
Speed ContainsSpeedAccess: Read-Only

Value:Always returns Speed.Constant

The complexity of the Contains operation
bool DuplicatesByCountingAccess: Read-Only

Value:True if only one representative of a group of equal items is kept in the collection together with the total count.

By convention this is true for any collection with set semantics.
EventTypeEnum ListenableEventsAccess: Read-Only

Value:

Constructor details

HashBag<T>() Create a hash bag with the deafult item equalityComparer.
HashBag<T>(System.Collections.Generic.IEqualityComparer<T> itemequalityComparer) Create a hash bag with an external item equalityComparer.
Parameters:
itemequalityComparer:The external item equalityComparer.
HashBag<T>(int capacity, System.Collections.Generic.IEqualityComparer<T> itemequalityComparer) Create a hash bag with external item equalityComparer, prescribed initial table size and default fill threshold (66%)
Parameters:
capacity:Initial table size (rounded to power of 2, at least 16)
itemequalityComparer:The external item equalityComparer
HashBag<T>(int capacity, double fill, System.Collections.Generic.IEqualityComparer<T> itemequalityComparer) Create a hash bag with external item equalityComparer, prescribed initial table size and fill threshold.
Parameters:
capacity:Initial table size (rounded to power of 2, at least 16)
fill:Fill threshold (valid range 10% to 90%)
itemequalityComparer:The external item equalityComparer

Method details

bool Add(T item) Add an item to this bag.
Returns:Always true
Parameters:
item:The item to add.
void AddAll<U>(IEnumerable<U> items) Add the elements from another collection with a more specialized item type to this collection.
Type parameters:
UThe type of items to add
Constraints:
U : T
Parameters:
items:The items to add
bool Check() Test internal structure of data (invariants)
Returns:True if pass
T Choose() Choose some item of this collection.
Throws
NoSuchItemExceptionif collection is empty.
Returns:
void Clear() Remove all items from the bag, resetting internal table to initial size.
object Clone() Make a shallow copy of this HashBag.
Returns:
bool Contains(T item) Check if an item is in the bag
Returns:True if bag contains item
Parameters:
item:The item to look for
bool ContainsAll<U>(IEnumerable<U> items) Check if all items in a supplied collection is in this bag (counting multiplicities).
Type parameters:
U
Constraints:
U : T
Returns:True if all items are found.
Parameters:
items:The items to look for.
int ContainsCount(T item) Count the number of times an item is in this set.
Returns:The count
Parameters:
item:The item to look for.
void CopyTo(T[] array, int index) Copy the items of this bag to part of an array. /ThrowsSystem.ArgumentOutOfRangeException if i is negative. /ThrowsSystem.ArgumentException if the array does not have room for the items.
Parameters:
array:The array to copy to
index:The starting index.
bool Find(ref T item) Check if an item (collection equal to a given one) is in the bag and if so report the actual item object found.
Returns:True if bag contains item
Parameters:
item:On entry, the item to look for. On exit the item found, if any
bool FindOrAdd(ref T item) Check if an item (collection equal to a given one) is in the bag. If found, report the actual item object in the bag, else add the supplied one.
Returns:True if item was found
Parameters:
item:On entry, the item to look for or add. On exit the actual object found, if any.
System.Collections.Generic.IEnumerator<T> GetEnumerator() Create an enumerator for this bag.
Returns:The enumerator
ICollectionValue<KeyValuePair<T,int>> ItemMultiplicities()
Returns:
bool Remove(T item) Remove one copy af an item from the bag
Returns:True if item was (found and) removed
Parameters:
item:The item to remove
bool Remove(T item, out T removeditem) Remove one copy of an item from the bag, reporting the actual matching item object.
Returns:True if item was found.
Parameters:
item:The value to remove.
removeditem:The removed value.
void RemoveAll<U>(IEnumerable<U> items) Remove all items in a supplied collection from this bag, counting multiplicities.
Type parameters:
U
Constraints:
U : T
Parameters:
items:The items to remove.
void RemoveAllCopies(T item) Remove all copies of item from this set.
Parameters:
item:The item to remove
void RetainAll<U>(IEnumerable<U> items) Remove all items *not* in a supplied collection from this bag, counting multiplicities.
Type parameters:
U
Constraints:
U : T
Parameters:
items:The items to retain
T[] ToArray() Create an array containing all items in this bag (in enumeration order).
Returns:The array
ICollectionValue<T> UniqueItems()
Returns:
bool Update(T item) Check if an item (collection equal to a given one) is in the bag and if so replace the item object in the bag with the supplied one.
Returns:True if item was found (and updated)
Parameters:
item:The item object to update with
bool Update(T item, out T olditem)
Returns:
Parameters:
item:
olditem:
bool UpdateOrAdd(T item) Check if an item (collection equal to a supplied one) is in the bag and if so replace the item object in the set with the supplied one; else add the supplied one.
Returns:True if item was updated
Parameters:
item:The item to look for and update or add
bool UpdateOrAdd(T item, out T olditem)
Returns:
Parameters:
item:
olditem: