Class DictionaryBase<K, V>
A base class for implementing a dictionary based on a set collection implementation. See the source code for C5.HashDictionary`2 for an example
Inheritance
Implements
Inherited Members
Namespace: Lucene.Net.Support.C5
Assembly: Lucene.Net.dll
Syntax
public abstract class DictionaryBase<K, V> : CollectionValueBase<KeyValuePair<K, V>>, IDictionary<K, V>, ICollectionValue<KeyValuePair<K, V>>, IEnumerable<KeyValuePair<K, V>>, IEnumerable, IShowable, IFormattable
Type Parameters
Name | Description |
---|---|
K | |
V |
Constructors
| Improve this Doc View SourceDictionaryBase(IEqualityComparer<K>, MemoryType)
Declaration
protected DictionaryBase(IEqualityComparer<K> keyequalityComparer, MemoryType memoryType)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEqualityComparer<K> | keyequalityComparer | |
MemoryType | memoryType |
Fields
| Improve this Doc View Sourcepairs
The set collection of entries underlying this dictionary implementation
Declaration
protected ICollection<KeyValuePair<K, V>> pairs
Field Value
Type | Description |
---|---|
ICollection<KeyValuePair<K, V>> |
Properties
| Improve this Doc View SourceActiveEvents
Declaration
public override EventTypeEnum ActiveEvents { get; }
Property Value
Type | Description |
---|---|
EventTypeEnum |
Overrides
ContainsSpeed
Declaration
public virtual Speed ContainsSpeed { get; }
Property Value
Type | Description |
---|---|
Speed |
Count
Declaration
public override int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The number of entries in the dictionary |
Overrides
CountSpeed
Declaration
public override Speed CountSpeed { get; }
Property Value
Type | Description |
---|---|
Speed | The number of entries in the dictionary |
Overrides
EqualityComparer
Declaration
public virtual IEqualityComparer<K> EqualityComparer { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEqualityComparer<K> |
Func
Declaration
public virtual Func<K, V> Func { get; }
Property Value
Type | Description |
---|---|
System.Func<K, V> |
IsEmpty
Declaration
public override bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
System.Boolean | True if this collection is empty. |
Overrides
IsReadOnly
Declaration
public virtual bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean | True if dictionary is read only |
Item[K]
Indexer by key for dictionary.
The get method will throw an exception if no entry is found.
The set method behaves like C5.DictionaryBase`2.UpdateOrAdd(`0,`1).
Declaration
public virtual V this[K key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
K | key |
Property Value
Type | Description |
---|---|
V | The value corresponding to the key |
Exceptions
Type | Condition |
---|---|
NoSuchItemException | On get if no entry is found. |
Keys
Declaration
public virtual ICollectionValue<K> Keys { get; }
Property Value
Type | Description |
---|---|
ICollectionValue<K> | A collection containing all the keys of the dictionary |
ListenableEvents
Declaration
public override EventTypeEnum ListenableEvents { get; }
Property Value
Type | Description |
---|---|
EventTypeEnum |
Overrides
Values
Declaration
public virtual ICollectionValue<V> Values { get; }
Property Value
Type | Description |
---|---|
ICollectionValue<V> | A collection containing all the values of the dictionary |
Methods
| Improve this Doc View SourceAdd(K, V)
Add a new (key, value) pair (a mapping) to the dictionary.
Declaration
public virtual void Add(K key, V value)
Parameters
Type | Name | Description |
---|---|---|
K | key | Key to add |
V | value | Value to add |
Exceptions
Type | Condition |
---|---|
DuplicateNotAllowedException | if there already is an entry with the same key. |
AddAll<L, W>(IEnumerable<KeyValuePair<L, W>>)
Add the entries from a collection of C5.KeyValuePair`2 pairs to this dictionary.
TODO: add restrictions L:K and W:V when the .Net SDK allows it
Declaration
public virtual void AddAll<L, W>(IEnumerable<KeyValuePair<L, W>> entries)
where L : K where W : V
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<KeyValuePair<L, W>> | entries |
Type Parameters
Name | Description |
---|---|
L | |
W |
Exceptions
Type | Condition |
---|---|
DuplicateNotAllowedException | If the input contains duplicate keys or a key already present in this dictionary. |
Check()
Check the integrity of the internal data structures of this dictionary.
Declaration
public virtual bool Check()
Returns
Type | Description |
---|---|
System.Boolean | True if check does not fail. |
Choose()
Choose some entry in this Dictionary.
Declaration
public override KeyValuePair<K, V> Choose()
Returns
Type | Description |
---|---|
KeyValuePair<K, V> |
Overrides
Exceptions
Type | Condition |
---|---|
NoSuchItemException | if collection is empty. |
Clear()
Remove all entries from the dictionary
Declaration
public virtual void Clear()
Contains(K)
Check if there is an entry with a specified key
Declaration
public virtual bool Contains(K key)
Parameters
Type | Name | Description |
---|---|---|
K | key | The key to look for |
Returns
Type | Description |
---|---|
System.Boolean | True if key was found |
ContainsAll<H>(IEnumerable<H>)
Declaration
public virtual bool ContainsAll<H>(IEnumerable<H> keys)
where H : K
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<H> | keys |
Returns
Type | Description |
---|---|
System.Boolean |
Type Parameters
Name | Description |
---|---|
H |
Find(ref K, out V)
Check if there is an entry with a specified key and report the corresponding value if found. This can be seen as a safe form of "val = this[key]".
Declaration
public virtual bool Find(ref K key, out V value)
Parameters
Type | Name | Description |
---|---|---|
K | key | The key to look for |
V | value | On exit, the value of the entry |
Returns
Type | Description |
---|---|
System.Boolean | True if key was found |
FindOrAdd(K, ref V)
Look for a specific key in the dictionary. If found, report the corresponding value, else add an entry with the key and the supplied value.
Declaration
public virtual bool FindOrAdd(K key, ref V value)
Parameters
Type | Name | Description |
---|---|---|
K | key | On entry the key to look for |
V | value | On entry the value to add if the key is not found. On exit the value found if any. |
Returns
Type | Description |
---|---|
System.Boolean | True if key was found |
GetEnumerator()
Create an enumerator for the collection of entries of the dictionary
Declaration
public override IEnumerator<KeyValuePair<K, V>> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<KeyValuePair<K, V>> | The enumerator |
Overrides
Remove(K)
Remove an entry with a given key from the dictionary
Declaration
public virtual bool Remove(K key)
Parameters
Type | Name | Description |
---|---|---|
K | key | The key of the entry to remove |
Returns
Type | Description |
---|---|
System.Boolean | True if an entry was found (and removed) |
Remove(K, out V)
Remove an entry with a given key from the dictionary and report its value.
Declaration
public virtual bool Remove(K key, out V value)
Parameters
Type | Name | Description |
---|---|---|
K | key | The key of the entry to remove |
V | value | On exit, the value of the removed entry |
Returns
Type | Description |
---|---|
System.Boolean | True if an entry was found (and removed) |
Show(StringBuilder, ref Int32, IFormatProvider)
Declaration
public override bool Show(StringBuilder stringbuilder, ref int rest, IFormatProvider formatProvider)
Parameters
Type | Name | Description |
---|---|---|
System.Text.StringBuilder | stringbuilder | |
System.Int32 | rest | |
System.IFormatProvider | formatProvider |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
Update(K, V)
Look for a specific key in the dictionary and if found replace the value with a new one. This can be seen as a non-adding version of "this[key] = val".
Declaration
public virtual bool Update(K key, V value)
Parameters
Type | Name | Description |
---|---|---|
K | key | The key to look for |
V | value | The new value |
Returns
Type | Description |
---|---|
System.Boolean | True if key was found |
Update(K, V, out V)
Declaration
public virtual bool Update(K key, V value, out V oldvalue)
Parameters
Type | Name | Description |
---|---|---|
K | key | |
V | value | |
V | oldvalue |
Returns
Type | Description |
---|---|
System.Boolean |
UpdateOrAdd(K, V)
Update value in dictionary corresponding to key if found, else add new entry. More general than "this[key] = val;" by reporting if key was found.
Declaration
public virtual bool UpdateOrAdd(K key, V value)
Parameters
Type | Name | Description |
---|---|---|
K | key | The key to look for |
V | value | The value to add or replace with. |
Returns
Type | Description |
---|---|
System.Boolean | True if entry was updated. |
UpdateOrAdd(K, V, out V)
Update value in dictionary corresponding to key if found, else add new entry. More general than "this[key] = val;" by reporting if key was found and the old value if any.
Declaration
public virtual bool UpdateOrAdd(K key, V value, out V oldvalue)
Parameters
Type | Name | Description |
---|---|---|
K | key | |
V | value | |
V | oldvalue |
Returns
Type | Description |
---|---|
System.Boolean |
Events
| Improve this Doc View SourceCollectionChanged
The change event. Will be raised for every change operation on the collection.
Declaration
public override event CollectionChangedHandler<KeyValuePair<K, V>> CollectionChanged
Event Type
Type | Description |
---|---|
CollectionChangedHandler<KeyValuePair<K, V>> |
Overrides
CollectionCleared
The change event. Will be raised for every change operation on the collection.
Declaration
public override event CollectionClearedHandler<KeyValuePair<K, V>> CollectionCleared
Event Type
Type | Description |
---|---|
CollectionClearedHandler<KeyValuePair<K, V>> |
Overrides
ItemsAdded
The item added event. Will be raised for every individual addition to the collection.
Declaration
public override event ItemsAddedHandler<KeyValuePair<K, V>> ItemsAdded
Event Type
Type | Description |
---|---|
ItemsAddedHandler<KeyValuePair<K, V>> |
Overrides
ItemsRemoved
The item added event. Will be raised for every individual removal from the collection.
Declaration
public override event ItemsRemovedHandler<KeyValuePair<K, V>> ItemsRemoved
Event Type
Type | Description |
---|---|
ItemsRemovedHandler<KeyValuePair<K, V>> |