System.Collections.Generic `ISet<T>` and `IDictionary<T>` (Fixes #53)
This PR addresses #53:
- Implements
SCG.ISet<T>onTreeSet<T> - Implements
SCG.IDictionary<K, V>onDictionaryBase<K, V>
I also attempted to implement SCG.ISet<T> on HashSet<T>, but since it seems to be missing a way to get and delete items by index, I am not sure how to proceed. Here is the (non compiling) attempt, in case you want to try to complete it:
Redundant Behavior
Do note that the AddAll, ContainsAll RetainAll, and RemoveAll methods are now redundant with UnionWith, IsSupersetOf, IntersectWith, and ExceptWith, respectively.
Options
- Leave the redundant methods in place
- Break C5 backward compatibility, but follow .NET conventions by removing (or making internal)
AddAll,ContainsAllRetainAll, andRemoveAll - Preserve C5 backward compatibility, and hide
UnionWith,IsSupersetOf,IntersectWith, andExceptWithby using explicit interface declarations
Performance
Most of the ISet<T> methods were reverse engineered from SCG.HashSet<T>, but it may be possible to implement some of the methods at a lower level for better performance - I didn't look into it.
On 31 Dec 2019, at 21.22, Shad Storhaug <[email protected]mailto:[email protected]> wrote:
- Implements SCG.ISet<T> on TreeSet<T>
- Implements SCG.IDictionary<K, V> on DictionaryBase<K, V>
I also attempted to implement SCG.ISet<T> on HashSet<T>, but since it seems to be missing a way to get and delete items by index, I am not sure how to proceed.
You mean, using the indexer set[i] = … where i is an integer?
Having this indexer on ISet<T> is an abominable design mistake in the .Net library, and I think it should throw an exception on HashSet<T> and similar. What does it do on SCG.HashSet<T>?
Peter
Here is the (non compiling) attempt, in case you want to try to complete it:
- 4901d561dda3ee6385aa0f366ff34b51aee09904https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FNightOwl888%2FC5%2Fcommit%2F4901d561dda3ee6385aa0f366ff34b51aee09904&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403253096&sdata=pYEz%2BiBApAMHio%2BF9vlmUKIlqqvdzguPMaeD%2F693B%2FU%3D&reserved=0
Redundant Behavior
Do note that the AddAll, ContainsAll RetainAll, and RemoveAll methods are now redundant with UnionWith, IsSupersetOf, IntersectWith, and ExceptWith, respectively.
Options
- Leave the redundant methods in place
- Break C5 backward compatibility, but follow .NET conventions by removing (or making internal) AddAll, ContainsAll RetainAll, and RemoveAll
- Preserve C5 backward compatibility, and hide UnionWith, IsSupersetOf, IntersectWith, and ExceptWith by using explicit interface declarations
Performance
Most of the ISet<T> methods were reverse engineered from SCG.HashSet<T>, but it may be possible to implement some of the methods at a lower level for better performance - I didn't look into it.
You can view, comment on, or merge this pull request online at:
https://github.com/sestoft/C5/pull/93https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403263093&sdata=Vtj6HLcnNHE6jMbrXFCWcIoaPCaET5Ff8gdQOH52I%2Fs%3D&reserved=0
Commit Summary
- Implemented SCG.IEqualityComparer<T> on C5.Tests.SC class
- Added SCG.ISet<T> to TreeSet<T> (fixes #53)
- Added SCG.IDictionary<K, V> to DictionaryBase<K, V> (#53)
File Changes
- M C5.Tests/SupportClasses.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-0&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403273090&sdata=jxFThw7MmgcnS4qxXQ8eWWqSkWVjbz%2F%2FzpQFdS67y4g%3D&reserved=0 (13)
- A C5.Tests/Templates/Set.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-1&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403273090&sdata=XpKwaRjypDe9E3LwQwvjczHdsJMsM4nwOSJV8Letq2Y%3D&reserved=0 (330)
- M C5.Tests/Trees/Dictionary.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-2&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403283083&sdata=q8H4PJ9mgohWB1HwuXHc7j6AFhpxGtCbZb1%2Bp8LkSE4%3D&reserved=0 (260)
- M C5.Tests/Trees/RedBlackTreeSetTests.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-3&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403283083&sdata=VxOysHtxxt4bvmjKw6k%2Fa6znNhT1n6x2P%2FG1%2BxFtBnw%3D&reserved=0 (14)
- M C5.UserGuideExamples/Graph.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-4&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403293079&sdata=f65q3fWdrqDGWdVdu5NxibjmYj9IhmN8Fb%2BvkGhtXJg%3D&reserved=0 (2)
- M C5.UserGuideExamples/MultiCollection.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-5&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403303073&sdata=ASNrLl%2FesGZQx0dwNUWZfrWeNQ85UyReXOH%2BC%2Bn8tiw%3D&reserved=0 (2)
- M C5/Arrays/ArrayList.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-6&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403303073&sdata=UMC5hjC5aapfucwokgTLdmwg%2F%2BY3o36pY%2BhIrdkAUL4%3D&reserved=0 (6)
- M C5/BaseClasses/ArrayBase.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-7&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403313073&sdata=Ac38EuK0U7dq76N9Y%2B%2FPY2PMPkSzIgPxOBLWhi9ednU%3D&reserved=0 (6)
- M C5/BaseClasses/CollectionBase.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-8&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403313073&sdata=N%2BI9LZ7MVifpO%2BlnaZ6YizCUe4PScOG6WySYtYfbMec%3D&reserved=0 (2)
- M C5/BaseClasses/CollectionValueBase.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-9&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403323063&sdata=jLetVOsmS4YoM7TIaLuwCDZvtFHOepk0bQAjk99pzFY%3D&reserved=0 (43)
- M C5/BaseClasses/DictionaryBase.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-10&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403323063&sdata=ubTsuAyKgcY9OtZtJUWiOnh5sEpa3PNTrIJ0b4Q8h6I%3D&reserved=0 (94)
- M C5/Dictionaries/SortedDictionaryBase.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-11&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403333057&sdata=dMixjcv0Uwh8kRZD3TQwyKGumFWP6Ew5o6wV5bDlGoQ%3D&reserved=0 (8)
- M C5/Enumerators/MappedCollectionValue.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-12&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403343055&sdata=NguEl5GaqT%2F6fmI%2Bc1ZMYlcoLRjR%2FI0u98xABffIZYA%3D&reserved=0 (2)
- M C5/Enumerators/MappedDirectedCollectionValue.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-13&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403343055&sdata=d%2FbKHlfmXOiqsNe22kUx89mjCRgznZHHIGWi%2FVcHcsU%3D&reserved=0 (2)
- M C5/Hashing/HashBag.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-14&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403353047&sdata=VRGt2B2Ueg4DC1yAv5v6XHLTniYVTR%2BpXAZKagH%2FmTk%3D&reserved=0 (8)
- M C5/Hashing/HashSet.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-15&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403363043&sdata=vNhGKa502uxmtQ6LycZuNniW7SU%2B8rqjimcE%2FSpEW4o%3D&reserved=0 (11)
- M C5/Heaps/IntervalHeap.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-16&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403363043&sdata=hr1dt67qOUbBGdezXAXWuyVgynXPb2UFnsFVejHQDPo%3D&reserved=0 (2)
- M C5/Interfaces/ICollectionValue.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-17&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403373039&sdata=uG2PBpVSS3w%2BNpsRkltoPuMo5LNiZLjaHENNohgEE9U%3D&reserved=0 (15)
- M C5/Interfaces/IDictionary.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-18&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403373039&sdata=DcXDFNjWc%2Byv9s9zeTuKr7%2Bz9a3uOds%2FXQRAnQQxFwE%3D&reserved=0 (4)
- M C5/Interfaces/IExtensible.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-19&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403383030&sdata=NbI2bcj%2Bwts14kpZE5JyeWOg0Nj87S5NZrQvtftH8wQ%3D&reserved=0 (4)
- M C5/LinkedLists/HashedLinkedList.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-20&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403383030&sdata=2QaVg76VtHI5iRqm8Q2nuXytLJ%2BeRnKqNUumb8eSRG0%3D&reserved=0 (2)
- M C5/LinkedLists/LinkedList.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-21&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403393031&sdata=UBNmH6TwMpXja2VKPV%2Fjb58Vka2VxQMIsvLc%2B2yFsrw%3D&reserved=0 (2)
- M C5/Trees/TreeBag.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-22&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403403024&sdata=am4ee5sBzNKMg4tQfdfqndJESdIVDwOeKhNDRFsOE%2FM%3D&reserved=0 (4)
- M C5/Trees/TreeSet.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-23&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403403024&sdata=GPvNfg6A0aL8xsadfZ4odDkPElJc6lHHEw9KaGFWy2g%3D&reserved=0 (478)
- M C5/WeakViewList.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-24&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403413020&sdata=pqSPvAKg%2BGp1V5bnJvNItqw9pcLVN6YEbev6Ishogl4%3D&reserved=0 (2)
- M C5/Wrappers/GuardedCollection.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-25&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403413020&sdata=F%2ByKOuezSknWpsK2WSMWJPVzBE4S5y050F6h2Yr0%2BaM%3D&reserved=0 (12)
- M C5/Wrappers/GuardedCollectionValue.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-26&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403423015&sdata=1eQS0Xm5UYPPMAGyGy9o21xNsrbEJKR5Lq1duiZIFX8%3D&reserved=0 (37)
- M C5/Wrappers/GuardedDictionary.cshttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%2Ffiles%23diff-27&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403423015&sdata=5z2hYd1DscXZwPLypcw1aY7M9LldItT5Z1g%2FPpUPL9c%3D&reserved=0 (4)
Patch Links:
- https://github.com/sestoft/C5/pull/93.patchhttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93.patch&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403433011&sdata=q%2Fg6DwBUY6EgXGNX6hq6AR2nYPQMAT4tgsY91pq2GF0%3D&reserved=0
- https://github.com/sestoft/C5/pull/93.diffhttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93.diff&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403443013&sdata=p1YCto300VJtL5bmYcI9DsWnPi%2FwAxsImUQFMJW4CGE%3D&reserved=0
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%3Femail_source%3Dnotifications%26email_token%3DAAFSQECR24RJ3KH2DAOAKW3Q3OSXRA5CNFSM4KBXZWF2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IDQZ6EA&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403443013&sdata=w1NdapeWHBCzcmHxmGdUqtfDVutdjQyaJdWsys9u9FI%3D&reserved=0, or unsubscribehttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAFSQEDQS4RKNDFVEWPADUDQ3OSXRANCNFSM4KBXZWFQ&data=02%7C01%7Csestoft%40itu.dk%7C1949ec5c619544d6d56708d78e2f2188%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637134205403453008&sdata=sRoOrEIQx0b5C9Mmh6VxauRY1ZoR860iDSoTqKBLOqo%3D&reserved=0.
You mean, using the indexer set[i] = … where i is an integer?
Having this indexer on ISet<T> is an abominable design mistake in the .Net library, and I think it should throw an exception on HashSet<T> and similar. What does it do on SCG.HashSet<T>?
No, what I meant was that the SCG.HashSet<T> has an IndexOfInternal(TKey) method and a way to delete an item internally by index. Since TreeSet<T> has an external IndexOf(TKey) and RemoveAt(int) methods, it was easy to translate. However, the C5 HashSet<T> doesn't seem to expose this functionality, so it is not as straightforward to implement ISet<T>.
On 4 Jan 2020, at 16.55, Shad Storhaug <[email protected]mailto:[email protected]> wrote:
You mean, using the indexer set[i] = … where i is an integer?
Having this indexer on ISet is an abominable design mistake in the .Net library, and I think it should throw an exception on HashSet and similar. What does it do on SCG.HashSet?
No, what I meant was that the SCG.HashSet<T> has an IndexOfInternal(TKey) method and a way to delete an item internally by index.
Strange, I don’t see any (documentation of) such a method on either SCG.HashSet<T> or SCG.ISet<T>.
In any case I believe the best way to implement it is by a method that throws a suitable exception, with a message such as “Not implemented”.
Peter
Strange, I don’t see any (documentation of) such a method on either SCG.HashSet<T> or SCG.ISet<T>.
You won't find any documentation, because as I mentioned, the method is intenal:
https://github.com/microsoft/referencesource/blob/master/System.Core/System/Collections/Generic/HashSet.cs#L1423
There is also an internal way to delete a slot by index after determining which indices need removal:
https://github.com/microsoft/referencesource/blob/master/System.Core/System/Collections/Generic/HashSet.cs#L1310
In any case I believe the best way to implement it is by a method that throws a suitable exception, with a message such as “Not implemented”.
Since this is the slow path that happens whenever the equality comparers don't match (which is probably 70-80% of the time), it would mean that all of the set operations would throw an exception 70-80% of the time.
Of course, if there is no way to get the index of an item or delete an item by index, this could be implemented by wrapping each item in a structure with a bit to track the items, but that would be a lot slower than using a BitArray to track the indicies.
I was hoping you had a more clever lower-level way to complete this than what Microsoft did.
But whatever the case, to me it makes more sense to provide the basic tests and a direction to go than to provide a broken implementation or one that is unreasonably slow. Since it is not part of the PR, you can either use your knowledge of the inner workings of C5's HashSet to complete it the right way or completely leave it out.
Sorry, I failed to notice this about the method being internal. This makes more sense.
Peter
On 5 Jan 2020, at 04.59, Shad Storhaug <[email protected]mailto:[email protected]> wrote:
Strange, I don’t see any (documentation of) such a method on either SCG.HashSet or SCG.ISet.
You won't find any documentation, because as I mentioned, the method is intenal:
https://github.com/microsoft/referencesource/blob/master/System.Core/System/Collections/Generic/HashSet.cs#L1423https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmicrosoft%2Freferencesource%2Fblob%2Fmaster%2FSystem.Core%2FSystem%2FCollections%2FGeneric%2FHashSet.cs%23L1423&data=02%7C01%7Csestoft%40itu.dk%7C0fef879490874276411d08d79193aa75%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637137935734167066&sdata=vdPRJLYZmhoiTi4SfoaTvaY9gsZNnnPazVJKli%2BkESk%3D&reserved=0
There is also an internal way to delete a slot by index after determining which indices need removal:
https://github.com/microsoft/referencesource/blob/master/System.Core/System/Collections/Generic/HashSet.cs#L1310https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmicrosoft%2Freferencesource%2Fblob%2Fmaster%2FSystem.Core%2FSystem%2FCollections%2FGeneric%2FHashSet.cs%23L1310&data=02%7C01%7Csestoft%40itu.dk%7C0fef879490874276411d08d79193aa75%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637137935734167066&sdata=FEkgzJKZmn14yRGB3ORKFrc5ddxzTXsWJg75tYFo7Y4%3D&reserved=0
In any case I believe the best way to implement it is by a method that throws a suitable exception, with a message such as “Not implemented”.
Since this is the slow path that happens whenever the equality comparers don't match (which is probably 70-80% of the time), it would mean that all of the set operations would throw an exception 70-80% of the time.
Of course, if there is no way to get the index of an item or delete an item by index, this could be implemented by wrapping each item in a structure with a bit to track the items, but that would be a lot slower than using a BitArray to track the indicies.
I was hoping you had a more clever lower-level way to complete this than what Microsoft did.
But whatever the case, to me it makes more sense to provide the basic tests and a direction to go than to provide a broken implementation or one that is unreasonably slow. Since it is not part of the PR, you can either use your knowledge of the inner workings of C5's HashSet to complete it the right way or completely leave it out.
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsestoft%2FC5%2Fpull%2F93%3Femail_source%3Dnotifications%26email_token%3DAAFSQEF2H23VVVKEXAA44ATQ4FLKBA5CNFSM4KBXZWF2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIDIFJA%23issuecomment-570852004&data=02%7C01%7Csestoft%40itu.dk%7C0fef879490874276411d08d79193aa75%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637137935734172058&sdata=J1mpccU63mYcO2AHMbnkjOR60X%2BP1NEEjUL%2BaIyES%2FY%3D&reserved=0, or unsubscribehttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAFSQEGWBQTAUPW4UQJH7S3Q4FLKBANCNFSM4KBXZWFQ&data=02%7C01%7Csestoft%40itu.dk%7C0fef879490874276411d08d79193aa75%7Cbea229b67a084086b44c71f57f716bdb%7C1%7C0%7C637137935734177049&sdata=fqUhetkY9dk9Ru0JRNeq71WmIwIYG1cKp8AD%2FzxAt8M%3D&reserved=0.
AddAll, ContainsAll, RetainAll, and RemoveAll come from ICollection or IExtensible.
They should maybe be called *Range to match the naming in .NET.
My thinking would be to rename *All to *Range and then go with option 3: hide by using explicit interface declarations. This is in line with how SCG.LinkedList<T> implements SCG.ICollection<T>.
WRT HashSet<T> I think we should provide a crude implementation of ISet<T> to allow it to be used and possibly not the the perf is not optimal for ISet<T> operations.
AddAll, ContainsAll, RetainAll, and RemoveAll come from ICollection or IExtensible. They should maybe be called *Range to match the naming in .NET. My thinking would be to rename *All to *Range and then go with option 3: hide by using explicit interface declarations. This is in line with how SCG.LinkedList<T> implements SCG.ICollection<T>. WRT HashSet<T> I think we should provide a crude implementation of ISet<T> to allow it to be used and possibly not the the perf is not optimal for ISet<T> operations.
Do you mean hide all of the ISet<T> set operations, or just the redundant ones?
It would be useful to provide the rest of the set operations (IsSubsetOf, IsProperSubsetOf, IsProperSupersetOf, and Overlaps) as top-level methods. However, it feels like a crime to provide IsSubsetOf, IsProperSubsetOf, IsProperSupersetOf and name the remaining one ContainsRange instead of IsSupersetOf.
Either way it feels like Overlaps should definitely be on the top level, but IsSubsetOf, IsProperSubsetOf, IsProperSupersetOf and IsSupersetOf should be all public or all hidden.
No I mean hide the IExtensible methods so HashSet and TreeSet looks and behaves like SCG.ISet.
That’s a breaking change but I think it’ll make more sense than hiding the ISet methods.
We just need to ensure the C5 event stuff is implemented also.
@NightOwl888: are you working on the changes mentioned above?
I haven't had a chance to get to it yet, and it might be awhile until I have the time. No objections if you want to jump ahead and do it yourself.