Commit Graph
98 Commits
Author SHA1 Message Date
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
Jb Evain da07f762ad 2007-08-20 Jb Evain <[email protected]>
* List.cs (AddCollection): return early if the collection
	to be added is empty.

svn path=/trunk/mcs/; revision=84420
2007-08-20 01:57:32 +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
Marek Safar f2347a2a65 2007-06-23 Marek Safar <[email protected]>
* List.cs: Make CheckMatch static.


svn path=/trunk/mcs/; revision=80604
2007-06-23 21:37:08 +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
Jonathan Chambers 1888bc79f1 2006-04-16 Jonathan Chambers <[email protected]>
* List.cs: Clear entry in RemoveAt after removing item. 
	Fixes bug #81387.

svn path=/trunk/mcs/; revision=75788
2007-04-16 20:54:22 +00:00
Alan McGovern af4b028e30 Optimised a lot of the List methods to increase performance.
svn path=/trunk/mcs/; revision=75021
2007-03-27 14:42:51 +00:00
Juraj Skripsky ea28770cf8 2007-03-21 Juraj Skripsky <[email protected]>
* List.cs (FindAllStackBits): Small optimization to the new code.
	Built resulting List<T> directly as an array, wrap it in a List<T>
	afterwards. Stop the filling of the result array as soon as all
	matching items have been processed.

svn path=/trunk/mcs/; revision=74715
2007-03-21 09:22:24 +00:00
Miguel de Icaza 926556e10b 2007-03-20 Juan Cristóbal Olivares <[email protected]>
* List.cs (FindAll): Optimize FindAll using a bitmask to
        * determine
        the number of positive matches, this increases the performance
in
        all cases below 10,000,000 elements extensively:

        100 elements:
        old method:             00:00:00.0126610 (26x)
        stackalloc bit method:  00:00:00.0004750 (1x)
        array bit method:       00:00:00.0010700 (2x)
        heap bit method:        00:00:00.0038830 (8x)

        1,000 elements:
        old method:             00:00:00.0139250 (24x)
        stackalloc bit method:  00:00:00.0005670 (1x)
        array bit method:       00:00:00.0010890 (2x)
        heap bit method:        00:00:00.0034920 (6x)

        10,000 elements:
        old method:             00:00:00.0136110 (12x)
        stackalloc bit method:  00:00:00.0011240 (1x)
        array bit method:       00:00:00.0016450 (1.4x)
        heap bit method:        00:00:00.0043110 (3x)

        50,000 elements:
        old method:             00:00:00.0175970 (3x)
        stackalloc bit method:  00:00:00.0085630 (1.5x)
        array bit method:       00:00:00.0055010 (1x)
        heap bit method:        00:00:00.0099590 (1.8x)

        100,000 elements:
        old method:             00:00:00.0210330 (2x)
        array bit method:       00:00:00.0100430 (1x)
        heap bit method:        00:00:00.0154150 (1.5x)

        1,000,000 elements:
        old method:             00:00:00.1243730 (1.2x)
        array bit method:       00:00:00.0973110 (1x)
        heap bit method:        00:00:00.1285650 (1.3x)

        10,000,000 elements:
        old method:             00:00:00.9252570 (1x)
        array bit method:       00:00:00.9632300 ( 1.05x)
        heap bit method:        00:00:01.1098490 (1.20x)



svn path=/trunk/mcs/; revision=74694
2007-03-20 15:39:19 +00:00
Miguel de Icaza 929fcbd4fa 2007-03-08 David Mitchell <[email protected]>
* List.cs: Fix the case where List.set_Item(int index) throws
	inappropriate exception when index is equal to List.Count

	List.IndexOf(object item) and IList.Contains(object item) throw
	exceptions when given invalid types.

	IList.Add(object item) throws InvalidCastException when item is
	not of the correct type.

svn path=/trunk/mcs/; revision=73976
2007-03-09 00:38:11 +00:00
Gert Driesen dfdbcf7fdd * Comparer.cs: Renamed IComparableOfTComparer<T> to GenericComparer<T>
to fix binary serialization compatibility with MS.
* ComparerTest.cs: Added test for bug #80929. Added tests to verify
binary serialization compatibility.
* IListTest.cs: Fixed header.
* corlib_test.dll.sources: Added ComparerTest.cs.

svn path=/trunk/mcs/; revision=73964
2007-03-08 20:22:06 +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
Miguel de Icaza 9ea62353d8 2007-03-05 David Mitchell <[email protected]>
* List.cs: Fix InsertRange bug (80930).


svn path=/trunk/mcs/; revision=73762
2007-03-05 21:34:23 +00:00
Gert Driesen a22cecf689 * List.cs: Fixed binary serialization compatibility with MS.NET.
Increment version whenever _items is modified; this fixes version
checks in Enumerator.
* ListTest.cs: Added tests for binary serialization, and Enumerator
version checks.

svn path=/trunk/mcs/; revision=66698
2006-10-15 14:17:58 +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
Kazuki Oikawa 5886b4f644 2006-05-17 Kazuki Oikawa <[email protected]>
* Array.cs : added internal sort method used
	  in System.Collections.Generics.List<T>.Sort(Comparison<T>).
	* List.cs : implemented Sort(Comparison <T>).

svn path=/trunk/mcs/; revision=60742
2006-05-16 16:34:16 +00:00
Atsushi Eno 089398a170 2006-05-08 Atsushi Enomoto <[email protected]>
* ArrayTest.cs : use proper comparer in IndexOf() and LastIndexOf().
	  Patch by Kazuki Oikawa. Fixed bug #77277.

	* List.cs : use proper comparer in Contains(), IndexOf() and
	  LastIndexOf(). Patch by Kazuki Oikawa. Fixed bug #77277.

	* ArrayTest.cs : test for bug #77277 by Kazuki Oikawa.

	* ListTest.cs : test for bug #77277 by Kazuki Oikawa.


svn path=/trunk/mcs/; revision=60396
2006-05-08 07:34:06 +00:00
Ankit Jain bff6e6ed35 In class/corlib/System.Collections.Generic:
* List.cs (CheckIndex): Check for -ve indices and allow index == size.
	(Insert): Use CheckIndex.

In class/corlib/Test/System.Collections.Generic:

	* ListTest.cs: Add some tests for InsertRange.


svn path=/trunk/mcs/; revision=58069
2006-03-16 17:04:44 +00:00
Zoltan Varga e30cb1f437 2006-03-12 Zoltan Varga <[email protected]>
* List.cs: Applied patch from <[email protected]>. Fixes #77504.

svn path=/trunk/mcs/; revision=57874
2006-03-12 18:00:09 +00:00
Martin Baulig 1eac6ee65d 2006-02-10 Martin Baulig <[email protected]>
* Comparer.cs
	(IComparableOfTComparer): `T' must implement `IComparable<T>' and
	not `IComparable'.


svn path=/trunk/mcs/; revision=56747
2006-02-10 09:17:47 +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 95fc536564 2005-12-20 Sebastien Pouliot <[email protected]>
* List.cs: Applied Atsushi's patch for Sort (bug 76361) now that the
	generic versions of Array.Sort are implemented.


svn path=/trunk/mcs/; revision=54654
2005-12-20 13:58:22 +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
Sebastien Pouliot ba7856141c 2005-12-19 Sebastien Pouliot <[email protected]>
* List.cs: Fix exception reporting to match MS behaviour (2.0 final).


svn path=/trunk/mcs/; revision=54606
2005-12-19 15:56:10 +00:00
Zoltan Varga 94574334a9 2005-11-19 Zoltan Varga <[email protected]>
* KeyNotFoundException.cs: Add default message.

svn path=/trunk/mcs/; revision=53277
2005-11-19 18:42:06 +00:00
Miguel de Icaza 5370ce3394 2005-09-29 Miguel de Icaza <[email protected]>
* Add ComVisible(true) to all the classes that needed it.

	* Removed documentation from DictionaryBase.cs and moved it to
	Monodoc. 

	* ArrayList.cs: Fixed signature for constructor, parameter names
	are normative.

	* CollectionBase.cs: Add a couple of missing methods. 



svn path=/trunk/mcs/; revision=51018
2005-09-30 02:15:04 +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
Kamil Skalski 15b7b57545 Mark BindGenericParameters as deprecated (update from Beta2 API). Use MakeGenericType as default implementation with updated signature. Fix API usage here and there.
svn path=/trunk/mcs/; revision=47147
2005-07-09 21:45:28 +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
Martin Baulig 470d35c95e 2005-06-23 Martin Baulig <[email protected]>
* *.cs: Removed the `[ComVisible(false)]' attributes everywhere.


svn path=/trunk/mcs/; revision=46437
2005-06-23 16:53:59 +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 b2e0ae57fb 2005-06-20 David waite <[email protected]>
* List.cs : substantial changes and optimizations
    (AddCollection, AddEnumerable): new internal specializations of AddRange
    (AsReadOnly): returns specific IList<T> to match ms.net 2.0b2 api.
    (Clear): reset size to zero on clear
    (ConvertAll): catch null converter, use Add to prevent OutOfBounds
    exception
    (FindAll, FindIndex, FindLast, FindLastIndex, RemoveAll, TrueForAll): 
    check for null match
    (FindLastIndex): correct index parameters based on ms.net 2005b2 behavior
    (ForEach): catch null action
    (CheckIndex): new internal function similar to CheckRange for functions
    which only provide a starting index
    (InsertCollection, InsertEnumerable): new internal specializations of
    InsertRange
    (ReadOnlyList): removed, ReadOnlyCollection in 
    System.Collections.ObjectModel is used instead now 
    * ListTest.cs: Substantial new tests

svn path=/trunk/mcs/; revision=46283
2005-06-21 07:17:50 +00:00
Raja R Harinath 3d24544600 Fix changelog entry. Use tab, not 4 spaces to indent.
Remove entry on Enumerator.MoveNext: no such change was checked in.
Update entry for Enumerator.Dispose to reflect actual change checked in.

svn path=/trunk/mcs/; revision=46203
2005-06-19 04:44:55 +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
Raja R Harinath 3bb11dfff8 In System.Collections.Generic:
* Dictionary.cs (GetKeys, GetValues): Remove.
	(SetThreshold): New function to calculate the resize threshold.
	(CopyTo): Don't use foreach syntax.
	(ContainsValue): Likewise.  Use default equality comparer of the
	value type.
	(GetObjectData): Use CopyTo to copy into temporary array.  Don't
	save redundant _usedSlots and _threshold.
	(OnDeserialization): Rewrite.
	(ICollection<>.CopyTo): Forward to CopyTo.
	(Enumerator._nextIndex): Rename to from _index.
	(Enumerator._next, Enumerator.FixNext): Remove.
	(Enumerator.Current): Rewrite to avoid need for _next.
	(Enumerator.IEnumerator.Reset): Update.
	(KeyCollection): Is also IEnumerable<TKey> and IEnumerable.
	Update methods to conform to standard.
	(KeyCollection.GetEnumerator): Restore.  Return the correct type.
	(KeyCollection.Enumerator): Rename from KeyEnumerator.  Simple
	wrapper that forwards to Dictionary<,>.Enumerator.
	(ValueCollection): Likewise.

In Test/System.Collections.Generic:
	* DictionaryTest.cs (SliceCollectionsEnumeratorTest): New test
	based on #75053.

svn path=/trunk/mcs/; revision=46087
2005-06-16 12:45:33 +00:00
Martin Baulig 00d6ed169c Applied a patch from David Waite <[email protected]> containing some collection updates.
svn path=/trunk/mcs/; revision=46043
2005-06-15 14:10:38 +00:00
Ben Maurer 05aecab26c 2005-06-12 Ben Maurer <[email protected]>
* Comparer.cs, EqualityComparer.cs: Important performance hack:
	make sure that we don't box stuff and do reflection on every
	comparison. We use reflection at cctor time rather than on every
	request.


svn path=/trunk/mcs/; revision=45833
2005-06-12 19:42:28 +00:00
Raja R Harinath 340e3fc12f Simplify Enumerator.MoveNext to make it "obviously correct", rather
than require subtle reasoning about the state of various variables.
* Dictionary.cs (Enumerator._isValid): Remove.  Replace all uses
with "_current == null".
(Enumerator._validNodeVisited): Remove.
(Enumerator._next): New.  Holds the the next position.
(Enumerator.FixNest): New helper function that ensures that _next
has the right value.
(Enumerator.MoveNext): Simplify.  Now, copies _next to _current
and advances _next if possible.

svn path=/trunk/mcs/; revision=45703
2005-06-09 14:34:47 +00:00
Martin Baulig 21fd97ac36 2005-06-08 Martin Baulig <[email protected]>
* Dictionary.cs (Dictionary.KeyEnumerator): Removed the public
	GetEnumerator() function since it's returning the wrong type.
	(Dictionary.ValueEnumerator): Likewise.  Fix #75073.


svn path=/trunk/mcs/; revision=45669
2005-06-08 19:57:29 +00:00
Ankit Jain 6453f46132 2005-06-08 Ankit Jain <[email protected]>
* Dictionary.cs (Dictionary<TKey, TValue>.MoveNext): Allow traversal of chain in last slot
	of the table. Fixes #75168.


svn path=/trunk/mcs/; revision=45603
2005-06-07 22:28:31 +00:00
Ben Maurer 56611048b3 2005-06-04 Ben Maurer <[email protected]>
* *.cs: 2.0 api fixups


svn path=/trunk/mcs/; revision=45412
2005-06-04 19:01:32 +00:00
Miguel de Icaza fcca32c6f5 2005-05-26 Miguel de Icaza <[email protected]>
* Dictionary.cs: Remove the `Hash' name from the Dictionary
	internal classes, make them public.

2005-05-26  Miguel de Icaza  <[email protected]>

	* File.cs (ReadAllBytes): add.



svn path=/trunk/mcs/; revision=45058
2005-05-26 15:52:42 +00:00
Zoltan Varga 6157df587e 2005-05-26 Zoltan Varga <[email protected]>
* Dictionary.cs: Fix a warning.

	* IDictionary.cs: Add missing TryGetValue method.

svn path=/trunk/mcs/; revision=45045
2005-05-26 13:36:03 +00:00