Commit Graph
67 Commits
Author SHA1 Message Date
Marek Safar fa19bfd400 [corlib] Tweak Dictionary initial capacity to be more conservative. Fixes #21375 2014-07-21 20:35:14 +02:00
Simon Hartmann 11b5312c83 Bug 17838 - IDictionary item property implemention for ConcurrentDictionary/SortedList_T throws exception on non-existing key
Avoid double lookup for Dictionary IDictionary.get_Item property impl
2014-02-19 16:40:57 +01:00
Marek Safar cfe97bf3a5 Share more common code 2013-02-27 22:58:31 +01:00
Marek Safar b1683b85d3 Remove some unused code 2012-02-24 13:14:08 +00:00
Miguel de Icaza 38edc367c4 Update two days worth of copyrights, many more missing 2011-11-09 10:25:48 -05:00
Sebastien Pouliot aa155736de Workaround AOT limitation for bug #1443. Patch by Rodrigo Kumpera 2011-11-08 07:56:40 -05:00
Marek Safar e1c66efea8 Add 4.5 readonly collection interfaces 2011-09-19 19:34:27 +01:00
Rodrigo Kumpera d72794cced Reorder fields to improve object layout since the runtime can't do it for corlib types. 2011-05-23 01:13:09 -03:00
Robert Jordan c42abafd5b In System.Collections.Generic:
2010-01-24  Robert Jordan  <[email protected]>

	* Dictionary.cs: Fix deserialization compatibility with MS.NET.
	Fixes bug #474009.

In Test/System.Collections.Generic:
2010-01-24  Robert Jordan  <[email protected]>

	* DictionaryTest.cs: Add test case for bug #474009.


svn path=/trunk/mcs/; revision=150089
2010-01-24 01:04:18 +00:00
Miguel de Icaza 820ad1b041 2010-01-20 Miguel de Icaza <[email protected]>
* Dictionary.cs: Always create the keys, fixes compatibility
       between Mono and .NET.  Patch from John Lenz <[email protected]>


svn path=/trunk/mcs/; revision=149947
2010-01-21 00:49:45 +00:00
Marek Safar 511cd3ef88 2009-10-20 Marek Safar <[email protected]>
* List.cs, CollectionDebuggerView.cs, KeyValuePair.cs, Dictionary.cs
	Improve debugging experience.


svn path=/trunk/mcs/; revision=144437
2009-10-20 10:32:19 +00:00
Miguel de Icaza 0204abe803 Drop more obsolete defines
svn path=/trunk/mcs/; revision=144304
2009-10-17 01:35:27 +00:00
Raja R Harinath b668695e59 * Dictionary.cs (Do_ICollectionCopyTo): Revert 2009-10-01 change.
Use BOOTSTRAP_BASIC to hide code from gmcs 2.4.x.

svn path=/trunk/mcs/; revision=143210
2009-10-01 20:20:51 +00:00
Marek Habersack e64813b7f7 2009-10-01 Marek Habersack <[email protected]>
* Dictionary.cs: cast target array to TRet[] instead of object[] -
	may fail, but otherwise it doesn't compile with 2.4 (e.g. when
	bootstrapping trunk)

svn path=/trunk/mcs/; revision=143188
2009-10-01 18:24:46 +00:00
Raja R Harinath 162d3490c5 Dictionary: Ensure that invalid arrays to CopyTo result in ArgumentExceptions.
* System.Collections.Generic/Dictionary.cs (CopyToCheck, Do_CopyTo):
Carve out of ...
(CopyTo): ... this.
(Do_ICollectionCopyTo): Carve out of ICollection.CopyTo.  Convert
type-cast exceptions to ArgumentExceptions.
(KeyCollection.CopyTo): Use them.
(ValueCollection.CopyTo): Use them.
* Test/System.Collections.Generic/DictionaryTest.cs (ICollectionCopyTo):
Test various odd scenarios where .NET CopyTo does _not_ throw an exception.
(ICollectionCopyTo_ex1..4): Ensure that ArgumentExceptions are
thrown in appropriate cases.

svn path=/trunk/mcs/; revision=142427
2009-09-22 17:39:52 +00:00
Raja R Harinath ac80cb8d8e * Dictionary.cs (Enumerator.MoveNext): Avoid an out-of-bounds access.
svn path=/trunk/mcs/; revision=139111
2009-07-30 19:04:14 +00:00
Raja R Harinath a22621964d Fix Dictionary<,>-relevant parts of #491858 and #517415
* System.Collections.Generic/Dictionary.cs (Enumerator.current): New.
(Enumerator.MoveNext): Update it.
(Enumerator.Current): Don't verify any invariants.
* Test/System.Collections.Generic/DictionaryTest.cs (Enumerator_Current):
New test, includes relevant parts of #491858 and #517415.

svn path=/trunk/mcs/; revision=139082
2009-07-30 13:52:39 +00:00
Jb Evain e8d5dfcfd1 optimize a bit the fix to avoid double checking
svn path=/trunk/mcs/; revision=130886
2009-04-02 17:39:17 +00:00
Jb Evain c0deaf8193 2009-04-02 Jb Evain <[email protected]>
* Dictionary.cs (ValueCollection.CopyTo): fix for copying to
	an object array. Based on a patch by Tobias Grimm <[email protected]>.
	Fixes bug #328036.


svn path=/trunk/mcs/; revision=130884
2009-04-02 17:33:12 +00:00
Zoltan Varga f77392683a 2009-02-04 Zoltan Varga <[email protected]>
* Dictionary.cs: Declare the Link struct outside the main class to avoid
	creating a separate inflated instances for each instantiation of Dictionary.

svn path=/trunk/mcs/; revision=125739
2009-02-04 20:24:35 +00:00
Jb Evain 667f5dbe39 2008-11-14 Jb Evain <[email protected]>
* Dictionary.cs (ICollection.CopyTo): fix the different possible
	copying cases depending on the actual type of destination array,
	be it an array of KeyValuePair, DictionaryEntry, or object.
	Fixes #444778.


svn path=/trunk/mcs/; revision=118841
2008-11-14 11:47:11 +00:00
Jb Evain 1330c66bc1 2008-11-14 Jb Evain <[email protected]>
* Dictionary.cs: fix ICollection<KeyValuePair<T>>.Remove and .Contains
	to not only check if the key exists but if the associated value is the
	good one as well. Fixes #444768.


svn path=/trunk/mcs/; revision=118838
2008-11-14 10:36:28 +00:00
Paolo Molaro ddee43464b Add a bit of explanation about the double use of HashCode.
svn path=/trunk/mcs/; revision=114969
2008-10-06 17:06:51 +00:00
Zoltan Varga 9a6df6496c 2008-10-06 Zoltan Varga <[email protected]>
* Dictionary.cs (Clear): Clear the linkSlots array as well, as 
	Enumerator.MoveNext () depends on it. Fixes #432441.

svn path=/trunk/mcs/; revision=114915
2008-10-06 03:35:26 +00:00
Paolo Molaro 2b223a5248 Fri Oct 3 23:08:06 CEST 2008 Paolo Molaro <[email protected]>
* Dictionary.cs: by popular demand, return keys/values in insertion
	order when possible.


svn path=/trunk/mcs/; revision=114791
2008-10-03 21:17:58 +00:00
Jb Evain 399b1652ad 2008-09-29 Jb Evain <[email protected]>
* Dictionary.cs: check for null argument in ContainsKey.
	Patch by Jonathan Anderson  <[email protected]>


svn path=/trunk/mcs/; revision=114371
2008-09-29 07:43:31 +00:00
Jb Evain 271b49aabf 2008-09-24 Jb Evain <[email protected]>
* Dictionary.cs: properly reset all compounds enumerators.
	Fixes #429530.


svn path=/trunk/mcs/; revision=113954
2008-09-24 13:34:05 +00:00
Jb Evain 553bc77516 2008-09-12 Jb Evain <[email protected]>
* Dictionary.cs: (ToTValue) allow null values to be added for non
	value types TValues to the dictionary when using the
	non generic IDictionary. Fixes #425693.


svn path=/trunk/mcs/; revision=112907
2008-09-12 20:58:02 +00:00
Andreas N 0577f9a422 2008-06-16 Andreas Nahr <[email protected]>
* String.cs: Dictionary: Do not change the index data when using the indexer for
	an already existing index. This is somewhat illogical and breakes obscure code situations

svn path=/trunk/mcs/; revision=105870
2008-06-15 23:00:42 +00:00
Juraj Skripsky 226db4e636 2008-04-29 Juraj Skripsky <[email protected]>
* Dictionary.cs (Clear, Remove): Clear empty slots in keySlots 
	and valueSlots. Otherwise the garbage collector cannot reclaim 
	the referenced key/value. Fixes bug #384723.


svn path=/trunk/mcs/; revision=102114
2008-04-29 12:58:17 +00:00
Sebastien Pouliot aa4096bfbf 2007-11-05 Sebastien Pouliot <[email protected]>
* Dictionary.cs: Ensure that the non-generic CopyTo works on Array.
	Fix #322783


svn path=/trunk/mcs/; revision=88940
2007-11-05 23:51:42 +00:00
Miguel de Icaza 2b6fc7d4a2 2007-10-31 Miguel de Icaza <[email protected]>
* Dictionary.cs: Do not increment curTableItem when we return
	false.   Was not necessary, just a defensive move.

svn path=/trunk/mcs/; revision=88535
2007-10-31 04:12:56 +00:00
Miguel de Icaza 2c01aa0209 Patch from Juraj:
2007-10-10  Juraj Skripsky <[email protected]>

	* Dictionary.cs (Enumerator.MoveNext): Handle the case where we
	had already reached the end. Fixes bug #332534.



svn path=/trunk/mcs/; revision=88534
2007-10-31 04:10:33 +00:00
Atsushi Eno 56c9656fd4 another set of cosmetic 2.0 API fixes.
svn path=/trunk/mcs/; revision=83679
2007-08-08 16:25:59 +00:00
Juraj Skripsky 5a11e85018 2007-06-20 Juraj Skripsky <[email protected]>
* Dictionary.cs: Optimize and add implementation notes. Use a "mini-heap"
   to store the linked lists instead of the regular heap. Split arrays of
   structs into separate arrays to make the GC's life simpler (see bug 81879
   for details). Make class serialization compatible with MS.NET.

   * EqualityComparer.cs: Rename IEquatableOfTEqualityComparer<T> to
   GenericEqualityComparer<T> to fix binary serialization compatibility
   with MS.


svn path=/trunk/mcs/; revision=80341
2007-06-20 18:00:23 +00:00
Miguel de Icaza 0d7f04e0e4 2007-03-05 David Mitchell <[email protected]>
* Dictionary.cs: An instance of Dictionary<TKey,TValue> is
	supposed to throw a KeyNotFoundException when 
	the user attempts to retrieve the value associated with a key that
	is not in the dictionary.

	On the other hand, an instance of IDictionary is supposed to
	return null in similar circumstances.


svn path=/trunk/mcs/; revision=73764
2007-03-05 21:56:00 +00:00
Zoltan Varga c9b823c3b0 2006-09-06 Zoltan Varga <[email protected]>
* Dictionary.cs: Speed up get_Item/set_Item/GetPrev () a bit. Increase capacity
	specified by the user so 'capacity' elements can really be added without resizing.

svn path=/trunk/mcs/; revision=65005
2006-09-06 13:13:33 +00:00
Zoltan Varga 1edc58fa28 2006-07-12 Zoltan Varga <[email protected]>
* Dictionary.cs: Swap order of parameters to cmp.Equals () to improve 
	compatibility with MS.NET and strange Equals () implementations.	

svn path=/trunk/mcs/; revision=62496
2006-07-12 13:28:44 +00:00
Paolo Molaro fb809038ba Tue Jan 24 18:22:54 CET 2006 Paolo Molaro <[email protected]>
* Dictionary.cs: avoid long reminder operations.


svn path=/trunk/mcs/; revision=55992
2006-01-24 17:23:23 +00:00
Raja R Harinath ae6559b8ab In System.Collections.Generic:
Speed up remove.  Use 'dict[k]=v' as a self-tuning hint.
	* Dictionary.cs (GetSlot): Move data-structure traversal to ...
	(GetPrev): ... this.  Returns the slot prior to the place we're
	looking for, or null if that place is the head of the chain.
	(Remove): Use it.
	(this.set): Use it.  Implement move-to-front on set.

	* Dictionary.cs (ToTKey, ToTValue): New helpers to convert from
	type 'object'.
	(IDictionary.this, IDictionary.Add): Use them.
	(IDictionary.Contains, IDictionary.Remove): If the types don't
	match, do nothing.

In Test/System.Collections.Generic:
	* DictionaryTest.cs (IDictionary_*): Add a few tests for the
	IDictionary explicit implementation.

svn path=/trunk/mcs/; revision=55946
2006-01-23 15:21:09 +00:00
Raja R Harinath 18b3383ec5 In System.Collections.Generic:
Fix to pass new nunit tests.
	* Dictionary.cs (ShimEnumerator): New class.  Implement the
	requirement that ((IDictionary) foo).GetEnumerator ().Current has
	type DictionaryEntry.
	(IDictionary.GetEnumerator): Use ShimEnumerator.
	(Enumerator.Current): Now has type KeyValuePair<TKey, TValue>.
	(Enumerator.MoveNext): Use VerifyState.
	(Enumerator.VerifyState): Move validation of 'current' field to ...
	(Enumerator.CurrentSlot): ... this.
	(Enumerator.Current, Enumerator.IDictionaryEnumerator.Entry):
	Use CurrentSlot.
	(CopyTo, ICollection.CopyTo): Use subtle reasoning to replace a
	'>=' with a '>'.  Don't throw an ArgumentException when
	index==array.Length && Count==0.
	(KeyCollection.CopyTo, ValueCollection.CopyTo): Likewise, and thus
	obviate the need to check (dictionary.Count == 0).

In Test/System.Collections.Generic:
	* DictionaryTest.cs: Remove NotWorking annotations.
	(Empty_CopyTo, Empty_Values_CopyTo): Fix tests to check that
	CopyTo from an empty dictionary does not throw an exception when
	'index==array.Length'.
	(PlainEnumeratorReturnTest): Check the type of 'Entry' property too.

svn path=/trunk/mcs/; revision=55781
2006-01-19 13:32:39 +00:00
Sebastien Pouliot b4a30d2a42 2005-12-19 Sebastien Pouliot <[email protected]>
* Dictionary.cs: Added [Serializable] attribute to both inner 
	Enumerator struct in Key and Value inner collection classes.
	* EqualityComparer.cs: Added missing IEqualityComparer interface.
	* List.cs: Added [Serializable] attribute to both inner Enumerator
	struct.


svn path=/trunk/mcs/; revision=54619
2005-12-19 19:33:40 +00:00
Sebastien Pouliot bfc39ae131 2005-12-19 Sebastien Pouliot <[email protected]>
* Dictionary.cs: Fixed ICollection.CopyTo to use DictionaryEntry. Fixed
	Key and Value CopyTo not to throw exception if the dictionary is empty
	(fix bug #77019).

svn path=/trunk/mcs/; revision=54616
2005-12-19 17:16:57 +00:00
Miguel de Icaza ef89ac9931 I had these sitting on my tree
svn path=/trunk/mcs/; revision=53852
2005-12-02 22:17:55 +00:00
Miguel de Icaza 77f55162b9 Add new test for bug #76061
Fix bug #76061

Change field style


svn path=/trunk/mcs/; revision=50203
2005-09-18 22:44:30 +00:00
Kamil Skalski a56d49c9a4 Change Key and Value in System.Collections.Generic.KeyValuePair to properties to match .NET 2.0 July CTP. Update its use in Dictionary, since now we cannot write to them.
svn path=/trunk/mcs/; revision=48217
2005-08-10 08:44:08 +00:00
Raja R Harinath cf760a97e8 In System.Collections.Generic:
Introduce some thread-safety by removing the modify-on-read
	move-to-front heuristic.
	* Dictionary.cs (_enumeratorGeneration, _enumerators): Remove.
	(Count): Add internal property set.  Invalidate enumerators when
	Count is changed.  Change all references of _usedSlots to Count.
	(this): Invalidate enumerators when the value of some slot is
	changed, even if the layout of the data-structure isn't modified.
	(DoHash): Remove null-key check.  All codepaths leading to this
	function already have the check.
	(GetSlot): Remove move-to-front heuristic.
	(Remove): Update.

In Test/System.Collections.Generic:
	* DictionaryTest.cs (FailFastTest1, FailFastTest2, FailFastTest3):
	New tests to ensure that enumerators are invalidated on
	modifications to the dictionary.

svn path=/trunk/mcs/; revision=46538
2005-06-27 08:36:29 +00:00
Martin Baulig acba2e467b 2005-06-24 Martin Baulig <[email protected]>
* IDictionary.cs: Use the same type parameter names than on MS.

	* IDictionary.cs, Dictionary.cs: We don't need the `CLSCompliant'
	attribute here.


svn path=/trunk/mcs/; revision=46477
2005-06-24 15:51:23 +00:00
Raja R Harinath 497020b7ff In System.Collections.Generic:
* Dictionary.cs (_generation, _enumeratorGeneration, _enumerators):
	New fields to implement fail-fast semantics.  All code that
	modifies the table increment _generation.
	(GetSlot): Use _hcp to compare keys.  Return the slot containing
	the key, rather than the index.  Avoid move-to-front heuristic
	when there's an enumerator coursing through the table.
	(this, Add, TryGetValue, ContainsKey, Remove): Update to change.
	(Enumerator.Enumerator): Save the generation of the dictionary.
	(Enumerator.Dispose): Inform dictionary that the enumerator is no more.
	(Enumerator.MoveNext, Enumerator.VerifyState): Fail if the
	dictionary has been modified.

In Test/System.Collections.Generic:
	* DictionaryTest.cs (KeyValueEnumeratorTest): Add test for infloop
	if dictionary is read while it's being enumerated.

svn path=/trunk/mcs/; revision=46370
2005-06-22 14:42:13 +00:00
David Waite 7bb5e539d1 2005-06-16 David Waite <[email protected]>
* Dictionary.cs (EnumerationMode): Remove.
    (Enumerator): Remove return type flag - legacy return is expected to
    always return a DictionaryEntry
    (Enumerator): Make constructor internal, it is not public on ms.net 
    beta 2
    (Enumerator.MoveNext): Fix endless loop on enumerator use
    (VerifyState): Added method to check state preconditions and throw
    appropriate exceptions.
    (KeyCollection,ValueCollection): Mark sealed to match ms.net beta 2
    (KeyCollection.Enumerator._hostEnumerator): make exact struct type,
    rather than boxing and using by interface
    (KeyCollection.Enumerator.Dispose): use default to clear Enumerator
    (ValueCollection.Enumerator._hostEnumerator): make exact struct type,
    rather than boxing and using by interface
    (ValueCollection.Enumerator.Dispose): use default to clear Enumerator
    * EqualityComparer.cs (DefaultComparer, IEquatableOfTEqualityComparer):
    Mark as serializable.
    * DictionaryTest.cs (AddTest3): Added test of simple interaction with
    struct dictionary
    (AddDuplicateTest,IndexerGetNullTest,IndexerSetNullTest): Added tests
    for exceptional cases to verify correct exceptions
    (TryGetValueTest): check return value from TryGetValue
    (KeyValueEnumeratorTest): Added test from verification of ms.net beta2
    behavior for non-generic IEnumerator/IDictionaryEnumerator behavior
    against Dictionary<>
    (SerializationTest): Added test to utilize serialization routines.

svn path=/trunk/mcs/; revision=46200
2005-06-19 02:36:21 +00:00