Runtime: IReadOnlySet ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  HashSet, SortedSet์ด ๊ตฌํ˜„ํ•˜๋„๋ก ํ•˜์‹ญ์‹œ์˜ค.

์— ๋งŒ๋“  2015๋…„ 06์›” 09์ผ  ยท  104์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: dotnet/runtime

์›๋ž˜์˜

IReadOnlyList ์ด ์ถ”๊ฐ€๋œ ์ดํ›„ ์„ธํŠธ์™€ ๋ชฉ๋ก ๊ฐ„์˜ ํŒจ๋ฆฌํ‹ฐ๊ฐ€ ๊ฐ์†Œํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๊ฒƒ์„ ๋‹ค์‹œ ํ™•๋ฆฝํ•˜๋Š” ๊ฒƒ์ด ์ข‹์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๊ทธ๊ฒƒ์„ ์‚ฌ์šฉํ•˜๋ฉด "์—ฌ๊ธฐ์—๋Š” ํ•ญ๋ชฉ์ด ๊ณ ์œ ํ•œ ์ฝ๊ธฐ ์ „์šฉ ์ปฌ๋ ‰์…˜์ด ์žˆ์Šต๋‹ˆ๋‹ค"๋ผ๊ณ  ๋งํ•˜๋Š” ๊ตฌํ˜„์— ๊ตฌ์• ๋ฐ›์ง€ ์•Š๋Š” ๋ฐฉ๋ฒ•์ด ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋ถ„๋ช…ํžˆ ๋งŽ์€ ์‚ฌ๋žŒ๋“ค์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

SQL ์„œ๋ฒ„: https://msdn.microsoft.com/en-us/library/gg503096.aspx
๋กœ์Šฌ๋ฆฐ: https://github.com/dotnet/roslyn/blob/master/src/Compilers/Core/Portable/InternalUtilities/IReadOnlySet.cs
๋Œ“๊ธ€์˜ ์ผ๋ถ€ ๋‚จ์ž: http://blogs.msdn.com/b/bclteam/archive/2013/03/06/update-to-immutable-collections.aspx

์ฝ๊ธฐ ์ „์šฉ ์ง‘ํ•ฉ ์ž‘์—…์— ์‚ฌ์ „์˜ ํ‚ค ์ปฌ๋ ‰์…˜์„ ์‚ฌ์šฉํ•˜๋ ค๋Š” ์‹ค์ œ ๋ฌธ์ œ์— ๋Œ€ํ•ด ์ž‘์—…ํ•  ๋•Œ ์ด ํ† ๋ก ์„ ์ฐพ์•˜์Šต๋‹ˆ๋‹ค. ์ด ๊ฒฝ์šฐ๋ฅผ ์ง€์›ํ•˜๊ธฐ ์œ„ํ•ด ์ œ๊ฐ€ ์ œ์•ˆํ•˜๋Š” API๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

ํŽธ์ง‘ํ•˜๋‹ค

์ด๋ก ์  ํ•ด์„

์ œ์•ˆ๋œ API

 namespace System.Collections.Generic {
+    public interface IReadOnlySet<out T> : IReadOnlyCollection<T>, IEnumerable, IEnumerable<T> {
+        bool Contains(T value);
+        bool IsProperSubsetOf(IEnumerable<T> other);
+        bool IsProperSupersetOf(IEnumerable<T> other);
+        bool IsSubsetOf(IEnumerable<T> other);
+        bool IsSupersetOf(IEnumerable<T> other);
+        bool Overlaps(IEnumerable<T> other);
+        bool SetEquals(IEnumerable<T> other);
+    }
-    public class HashSet<T> : ICollection<T>, IDeserializationCallback, IEnumerable, IEnumerable<T>, IReadOnlyCollection<T>, ISerializable, ISet<T> {
+    public class HashSet<T> : ICollection<T>, IDeserializationCallback, IEnumerable, IEnumerable<T>, IReadOnlyCollection<T>, ISerializable, ISet<T>, IReadOnlySet<T> {
     }
-    public class SortedSet<T> : ICollection, ICollection<T>, IDeserializationCallback, IEnumerable, IEnumerable<T>, IReadOnlyCollection<T>, ISerializable, ISet<T> {
+    public class SortedSet<T> : ICollection, ICollection<T>, IDeserializationCallback, IEnumerable, IEnumerable<T>, IReadOnlyCollection<T>, ISerializable, ISet<T>, IReadOnlySet<T> {
     }
+    public class ReadOnlySet<T> : ICollection<T>, IEnumerable, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlySet<T>, ISet<T> {
+        public int Count { get; }
+        public ReadOnlySet(ISet<T> set);
+        public bool Contains(T value);
+        public bool IsProperSubsetOf(IEnumerable<T> other);
+        public bool IsProperSupersetOf(IEnumerable<T> other);
+        public bool IsSubsetOf(IEnumerable<T> other);
+        public bool IsSupersetOf(IEnumerable<T> other);
+        public bool Overlaps(IEnumerable<T> other);
+        public bool SetEquals(IEnumerable<T> other);
+    }
     public class Dictionary<TKey, TValue> {
-        public sealed class KeyCollection : ICollection, ICollection<TKey>, IEnumerable, IEnumerable<TKey>, IReadOnlyCollection<TKey> {
+        public sealed class KeyCollection : ICollection, ICollection<TKey>, IEnumerable, IEnumerable<TKey>, IReadOnlyCollection<TKey>, IReadOnlySet<TKey> {
+            public bool IsProperSubsetOf(IEnumerable<TKey> other);
+            public bool IsProperSupersetOf(IEnumerable<TKey> other);
+            public bool IsSubsetOf(IEnumerable<TKey> other);
+            public bool IsSupersetOf(IEnumerable<TKey> other);
+            public bool Overlaps(IEnumerable<TKey> other);
+            public bool SetEquals(IEnumerable<TKey> other);
         }
     }
 }

์—ด๋ฆฐ ์งˆ๋ฌธ

  • ์ผ๋ฐ˜์ ์œผ๋กœ ์ธ์Šคํ„ด์Šคํ™”๋˜๋Š” ์ œ๋„ค๋ฆญ ์œ ํ˜•์˜ ์ฝ”๋“œ ํฌ๊ธฐ ๋น„์šฉ์„ ๊ฐ์•ˆํ•  ๋•Œ ์ด๋Ÿฌํ•œ ๋ฉ”์„œ๋“œ๋ฅผ Dictionary<TKey, TValue>.KeyCollection ํ—ˆ์šฉ๋ฉ๋‹ˆ๊นŒ? ์—ฌ๊ธฐ๋ฅผ ์ฐธ์กฐ
  • IReadOnlySet<T> ๋Š” SortedDictionary ๋˜๋Š” ImmutableDictionary ์™€ ๊ฐ™์€ ๋‹ค๋ฅธ Dictionary KeyCollection ์—์„œ ๊ตฌํ˜„๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๊นŒ?

์—…๋ฐ์ดํŠธ

  • ์ œ๊ฑฐ TryGetValue ๊ทธ๋ ‡์ง€์—์„œ์˜๋กœ ISet<T> ๊ฐ€๋Šฅ์„ฑ์ด ๊ทธ ์–ด๋Š ๋ฆฌ๋ฒ ์ด์Šค ๋ฐฉ์ง€ ํ•  ์ˆ˜์™€ ๊ฐ™์€ ISet<T> ๊ตฌํ˜„ํ•˜๊ธฐ IReadOnlySet<T> .
  • ReadOnlyCollection<T> ์™€ ์œ ์‚ฌํ•œ ReadOnlySet<T> ํด๋ž˜์Šค๋ฅผ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.
api-approved area-System.Collections up-for-grabs

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

์ œ์•ˆ๋œ API ๋””์ž์ธ:

public interface IReadOnlySet<T> : IReadOnlyCollection<T> {    
    bool Contains(T item);
    bool IsSubsetOf(IEnumerable<T> other);
    bool IsSupersetOf(IEnumerable<T> other);
    bool IsProperSupersetOf(IEnumerable<T> other);
    bool IsProperSubsetOf(IEnumerable<T> other);
    bool Overlaps(IEnumerable<T> other);
    bool SetEquals(IEnumerable<T> other);
}

์ด๊ฒƒ์€ ISet<> API๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•ฉ๋‹ˆ๋‹ค(๋ณ€์ด ๋ฐฉ๋ฒ•์€ ์ œ์™ธ).

Comparer ๊ฐ€ ์ด๊ฒƒ์— ๋งž์ง€ ์•Š๋Š” ๊ฒƒ์€ ์œ ๊ฐ์ด์ง€๋งŒ ISet<> ๋‚˜ IReadOnlyDictionary<> ๋น„๊ต์ž๋ฅผ ๋…ธ์ถœํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ์ง€๊ธˆ ์ˆ˜์ •ํ•˜๊ธฐ์—๋Š” ๋„ˆ๋ฌด ๋Šฆ์—ˆ์Šต๋‹ˆ๋‹ค.

๋ชจ๋“  104 ๋Œ“๊ธ€

๋ถˆ๋ณ€ํ•˜๊ฒŒ ๋งŒ๋“œ๋Š” ์–ธ์–ด ๊ตฌ์„ฑ์ด ์žˆ๋‹ค๋ฉด ์ข‹์ง€ ์•Š์„๊นŒ์š”? ๊ทธ๋ ‡๋‹ค๋ฉด ์šฐ๋ฆฌ๋Š” ์ด๋Ÿฌํ•œ ๋งˆ๋ฒ•์˜ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ฐ€์งˆ ํ•„์š”๊ฐ€ ์—†์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

@whoisj ์–ด๋–ค ์–ธ์–ด์ธ๊ฐ€์š”? CLR์—๋Š” ์ˆ˜์‹ญ ๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

์ž ์žฌ์ ์ธ ์–ธ์–ด ๊ธฐ๋Šฅ์ด๋ผ๊ณ  ํ•ด๋„ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ํ‘œํ˜„์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ฒฝ์šฐ ๋งˆ์ปค ์ธํ„ฐํŽ˜์ด์Šค(๋˜๋Š” ํ–‰๋™ ์ธํ„ฐํŽ˜์ด์Šค)๊ฐ€ ๊ฐ€์žฅ ์ข‹์Šต๋‹ˆ๋‹ค. ์ƒˆ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ํ•ญ๋ชฉ์„ ํ†ตํ•ด ์ปฌ๋ ‰์…˜ ์œ ํ˜•์˜ ๋ถˆ๋ณ€์„ฑ์„ ์ „๋‹ฌํ•˜๋ ค๋Š” ์‹œ๋„๋Š” CLR์ด ์ž„์˜์˜ ํด๋ž˜์Šค๊ฐ€ ๋‚ด๋ถ€์ ์œผ๋กœ ์ž‘๋™ํ•˜๋Š” ๋ฐฉ์‹์— ๋Œ€ํ•œ ๊ฐ€์ •์„ ํ•ด์„œ๋Š” ์•ˆ ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์ ์ ˆํ•˜์ง€ ์•Š์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋ฐฐ์—ด).

@whoisj ๋‚˜๋Š” ์ด๊ฒƒ์ด ์ ์–ด๋„ ๋ฏธ๋ž˜์˜ C# ๋ฒ„์ „ ์ค‘ ํ•˜๋‚˜์— ๋Œ€ํ•ด ๊ณ ๋ ค

๋˜ํ•œ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๋Š” ์ปฌ๋ ‰์…˜์„ ์ด๋ฏธ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

https://msdn.microsoft.com/en-us/library/system.collections.immutable(v=vs.111).aspx

์™„์ „ํžˆ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๋Š” ์ปฌ๋ ‰์…˜์„ ์–ป์œผ๋ ค๋ฉด immutable T ๋ฅผ ์ •์˜ํ•œ ๋‹ค์Œ ์ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Immutable...<T> ์ปฌ๋ ‰์…˜์„ ์„ ์–ธํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

@HaloFour ์šฐ๋ฆฌ๋Š” ์ „์— ์ด ๊ธธ์„ ๊ฐ€๋ณธ ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค : this )".

@dsaf ์ ˆ๋Œ€์ ์œผ๋กœ! ๋˜ ๋‹ค๋ฅธ ๋ฌธ์ œ์—์„œ ๋‚˜๋Š” ์“ฐ๊ธฐ ๊ฐ€๋Šฅํ•œ ์š”์†Œ์˜ ์ฝ๊ธฐ ์ „์šฉ ์ปฌ๋ ‰์…˜์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์ฝ๊ธฐ ์ „์šฉ์— ๋Œ€ํ•œ ์“ฐ๊ธฐ ๊ฐ€๋Šฅํ•œ ๋ฐ˜ํ•ญ์–ด๋ฅผ ์ œ์•ˆํ–ˆ์Šต๋‹ˆ๋‹ค. readonly Bag<writable Element> ๋ผ์ธ์„ ๋”ฐ๋ผ ๋ญ”๊ฐ€.

& ๋กœ ํ‘œ์‹œ๋œ ์ฐธ์กฐ๋Š” ์ปดํŒŒ์ผ๋Ÿฌ์—์„œ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๋Š” ๊ฒƒ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋„๋ก ์ œ์•ˆํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‚˜๋Š” ์—ฌ์ „ํžˆ ์ปดํŒŒ์ผ ์‹œ๊ฐ„ ํ™•์ธ์ด ํ•„์š”ํ•˜๊ณ  ๋Ÿฐํƒ€์ž„ ๋ณด์žฅ์ด ์•„๋‹Œ ๋…ผ๋ฆฌ์˜ ์ปดํŒŒ์ผ ์‹œ๊ฐ„ ํ™•์ธ์„ ์ถ”๊ตฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— CLR ์ž์ฒด์—์„œ ๋ฐ˜๋“œ์‹œ ์‹œํ–‰ํ•ด์•ผ ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ๊ฐœ๋ฐœ์ž๊ฐ€ ๋ณ€๊ฒฝ ๋ถˆ๊ฐ€๋Šฅํ•˜๊ธฐ๋ฅผ ์›ํ•˜๋Š” ๋ชจ๋“  ์ฐธ์กฐ๋ฅผ ๋‹ค๋ฃจ์ง€๋งŒ ํ˜ธ์ถœ ๊ธฐ์ค€์ž…๋‹ˆ๋‹ค.

@whoisj ์•„๋งˆ๋„, ๊ทธ๋Ÿฌ๋‚˜ ๊ทธ๊ฒƒ์€ ๊ฝค ์ ‘์„ ์ ์ด๋ฉฐ dsaf๊ฐ€ ์˜ค๋Š˜ ์˜คํ›„์— ๋ถ„๊ธฐ/PRํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์—์„œ ์„ธ ๊ฐœ์˜ ๋‹ค๋ฅธ ํŒ€์— ๊ฑธ์ณ ๋…ธ๋ ฅ์„ ํฌํ•จํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์ด ์š”์ฒญ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

๋˜ํ•œ ์ด๊ฒƒ์„ ์ปดํŒŒ์ผ๋Ÿฌ ๋ฌธ์ œ๋กœ ์ทจ๊ธ‰ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์‹œ์ ์—์„œ ๊ด€๋ จ ์ปดํŒŒ์ผ๋Ÿฌ(JIT ์ปดํŒŒ์ผ๋Ÿฌ ์ด์ƒ)๋Š” ์—†์œผ๋ฉฐ ๊ฒ€์ฆ์ž๋งŒ์ด "๋ถ€์ ์ ˆํ•œ" ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ถˆ๋ณ€์„ฑ์˜ ๊ธฐ์กด ๋Ÿฐํƒ€์ž„ ๋ฉ”์ปค๋‹ˆ์ฆ˜์ธ initonly ํ•„๋“œ๋„ ๊ฒ€์ฆ์„ ๊ฑด๋„ˆ๋›ฐ๋ฉด(๋˜๋Š” ๋ฆฌํ”Œ๋ ‰์…˜์„ ํ†ตํ•ด) ์‰ฝ๊ฒŒ ๋ฌด๋ ฅํ™”๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

C# ์–ธ์–ด์™€ ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ "์ˆœ์ˆ˜ํ•œ" ๋ฉ”์„œ๋“œ๋ฅผ ๋” ์ž˜ ์ง€์›ํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉด ์ข‹์„ ๊ฒƒ์ด๋ผ๋Š” ๋ฐ ๋™์˜ํ•ฉ๋‹ˆ๋‹ค. PureAttribute ์†์„ฑ

@HaloFour ๋ฐ•๋žŒํšŒ.

"์ˆœ์ˆ˜" ๋˜๋Š” "const" ์ฐธ์กฐ๋ฅผ ์ง€์›ํ•˜๋Š” ์ผ๋ฐ˜์ ์ธ ๋ฐฉ๋ฒ•์ด ์—†๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๋ฉด ์ œ์•ˆ๋œ ๊ฒƒ์ด ๊ฐ€์žฅ ์ข‹์€ ๋Œ€์•ˆ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

์ง€๊ธˆ ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋‚ด Commons ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ(Commons.Collections https://github.com/yanggujun/commonsfornet/tree/master/src/Commons.Collections/Set )์— ์ฝ๊ธฐ ์ „์šฉ ์„ธํŠธ ์ง€์›์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ด€๋ฆฌ์ž๋Š” ์ด๊ฒƒ์ด ๊ด‘๊ณ ๋ผ๊ณ  ์ƒ๊ฐ๋˜๋ฉด ์ด ๊ฒŒ์‹œ๋ฌผ์„ ์‚ญ์ œํ•˜์‹ญ์‹œ์˜ค... ์ œ ์ œ์•ˆ์€ ์˜คํ”ˆ ์†Œ์Šค ๊ตฌํ˜„์„ ๋‘˜๋Ÿฌ๋ณด๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

@yanggujun ์ข‹์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ฒ˜๋Ÿผ ๋ณด์ด์ง€๋งŒ ์ถ”๊ฐ€ ์ข…์†์„ฑ์„ ํ”ผํ•˜๊ธฐ ์œ„ํ•ด ์ง์ ‘ ๋กค๋งํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๋‚ด ์ œ์•ˆ์€ ์ผ๋ถ€ ์˜คํ”ˆ ์†Œ์Šค ๊ตฌํ˜„์„ ๋‘˜๋Ÿฌ๋ณด๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์ด๊ฒƒ์€ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์ด๋ฉฐ IReadOnlySet๊ณผ ๊ฐ™์€ ๊ธฐ๋ณธ ์ธํ„ฐํŽ˜์ด์Šค๋Š” ์‹ค์ œ๋กœ .NET Framework ์ž์ฒด์˜ ์ผ๋ถ€์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.

"api ๊ฒ€ํ†  ์ค€๋น„"๊ฐ€ ๋˜๋ ค๋ฉด ์ŠคํŽ™๋ ›์ด ํ•„์š”ํ•ฉ๋‹ˆ๊นŒ?

๊ทธ๋ฆฌ๊ณ  "ReadOnly"์™€ ๋‹ค๋ฅธ ์ด๋ฆ„์„ ์ง€์ •ํ•˜๋Š” ๊ฒƒ์„ ๊ณ ๋ คํ•˜์‹ญ์‹œ์˜ค(ํฅ๋ฏธ๋กœ์šด ๊ฒŒ์‹œ๋ฌผ ์ฐธ์กฐ: http://stackoverflow.com/questions/15262981/why-does-listt-implement-ireadonlylistt-in-net-4- 5)
"๊ฐ€๋…์„ฑ"์ด ๊ดœ์ฐฎ์•„ ๋ณด์ž…๋‹ˆ๋‹ค.

@GiottoVerducci ์•„๋‹ˆ์š”. ๋ถˆ์™„์ „ํ•˜๋”๋ผ๋„ ์ผ๊ด€๋œ ๋ช…๋ช… ํŒจํ„ด์„ ์œ ์ง€ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๊ธฐ์กด ์ธํ„ฐํŽ˜์ด์Šค์˜ ์ด๋ฆ„์„ ๋ณ€๊ฒฝํ•˜๊ธฐ ์œ„ํ•ด ๋ณ„๋„์˜ ๋ฌธ์ œ๋ฅผ ์ œ๊ธฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ œ์•ˆ๋œ API ๋””์ž์ธ:

public interface IReadOnlySet<T> : IReadOnlyCollection<T> {    
    bool Contains(T item);
    bool IsSubsetOf(IEnumerable<T> other);
    bool IsSupersetOf(IEnumerable<T> other);
    bool IsProperSupersetOf(IEnumerable<T> other);
    bool IsProperSubsetOf(IEnumerable<T> other);
    bool Overlaps(IEnumerable<T> other);
    bool SetEquals(IEnumerable<T> other);
}

์ด๊ฒƒ์€ ISet<> API๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•ฉ๋‹ˆ๋‹ค(๋ณ€์ด ๋ฐฉ๋ฒ•์€ ์ œ์™ธ).

Comparer ๊ฐ€ ์ด๊ฒƒ์— ๋งž์ง€ ์•Š๋Š” ๊ฒƒ์€ ์œ ๊ฐ์ด์ง€๋งŒ ISet<> ๋‚˜ IReadOnlyDictionary<> ๋น„๊ต์ž๋ฅผ ๋…ธ์ถœํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ์ง€๊ธˆ ์ˆ˜์ •ํ•˜๊ธฐ์—๋Š” ๋„ˆ๋ฌด ๋Šฆ์—ˆ์Šต๋‹ˆ๋‹ค.

    bool Contains(T item);

ICollection<T> ์— Contains(T item) ์žˆ์œผ๋ฏ€๋กœ IReadOnlyCollection<T> ์— ์žˆ์–ด์•ผ ํ•˜์ง€ ์•Š์Šต๋‹ˆ๊นŒ?

๋ถˆ๋ณ€ ์ปฌ๋ ‰์…˜ ํŒจํ‚ค์ง€ ๋Š” ์•„์ง ๋ฒ ํƒ€ ๋ฒ„์ „์ธ ๋™์•ˆ nuget์—์„œ ๋‚˜์—ด๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.
์ด๊ฒƒ์€ ๊ฝค ์ผ๋ฐ˜์ ์ธ ์‚ฌ์šฉ ์‚ฌ๋ก€์ด๋ฉฐ ํ‘œ์ค€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ์ฒ˜๋ฆฌ๋˜์–ด์•ผ ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

ํƒœ๊ทธ์—์„œ ์•Œ ์ˆ˜ ์žˆ๋“ฏ์ด ์—ฌ๊ธฐ์— API์— ๋Œ€ํ•ด ๋” ๋งŽ์€ ์ž‘์—…์ด ์žˆ์Šต๋‹ˆ๊นŒ? ๋„์›€์ด ๋˜๊ณ  ๋ˆ„๊ตฐ๊ฐ€๊ฐ€ ํ•„์š”ํ•œ ๊ฒƒ์„ ์ง€์ ํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉด ์ด์— ๋Œ€ํ•ด ์‹œ๊ฐ„์„ ํ• ์• ํ•˜๊ฒŒ ๋˜์–ด ๊ธฐ์ฉ๋‹ˆ๋‹ค.

@ashmind๊ฐ€ ์ œ์•ˆํ•œ API๋Š”

ISet<T> ๋ฅผ IReadOnlySet<T> ๋กœ ํ™•์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ? IList<T> / IReadOnlyList<T> ๋ฐœ์ƒํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๊นŒ?

๊ทธ๋ ‡์ง€ ์•Š๋‹ค๋ฉด, ๊ทธ๋•Œ ์ถ”๊ฐ€ ๊ณ ๋ คํ•ด์•ผ ํ•  ๋‹ค๋ฅธ ๋ณ€ํ™”๋ฅผ ๊ฐ€์ • IReadOnlySet<T> ๋ชจ๋“  ์ธํ„ฐํŽ˜์ด์Šค ๋ชฉ๋ก์— ISet<T> ์„ ํฌํ•จํ•˜์—ฌ corefx์—์„œ ๊ตฌํ˜„ HashSet<T> , SortedSet<T> ๊ณผ System.Collections.Immutable ๋ถˆ๋ณ€ ๋Œ€์‘.

@GiottoVerducci ์— ๋™์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. IReadOnlySet<T> ์™€ ๊ฐ™์€ ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜๋ฉด ๊ณ„์•ฝ ๊ธฐ๋Šฅ์ด ์„ ์–ธ๋˜์ง€ ์•Š๊ณ  ๊ณ„์•ฝ ์ œํ•œ์ด ์„ ์–ธ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ ์ด๋Ÿฌํ•œ ์ œํ•œ๊ณผ ๋ชจ์ˆœ๋˜๋Š” ๋‹ค๋ฅธ ๊ณ„์•ฝ๊ณผ ๊ฒฐํ•ฉ๋œ ๋™์ผํ•œ ๊ณ„์•ฝ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ํ˜ผ๋ž€์Šค๋Ÿฝ์Šต๋‹ˆ๋‹ค. ๊ณ„์•ฝ ์ด๋ฆ„์€ โ€‹โ€‹๊ตฌํ˜„์ž๊ฐ€ ์ง€์›ํ•˜๋Š” ๊ฒƒ๊ณผ ๊ด€๋ จ๋œ ๊ธ์ •์ ์ธ ์ฃผ์žฅ์„ ์„ค๋ช…ํ•ด์•ผ ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. IReadableSet<T> ์™€ ๊ฐ™์€ ์ด๋ฆ„์€ ๋‹น์—ฐํžˆ ์ข‹์ง€ ์•Š์ง€๋งŒ ์ ์–ด๋„ ๊ตฌํ˜„์ž๊ฐ€ ํ•˜๋Š” ์ผ์„ ๋” ์ž˜ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

@HaloFour ์›์น™์ ์œผ๋กœ ๋™์˜ํ•˜์ง€๋งŒ IReadOnlyList<T> ์™€ ๊ฐ™์€ ์ƒํ™ฉ์ž…๋‹ˆ๋‹ค. ์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•˜๋Š” ๊ฒƒ์ด IMHO์˜ ์ •๋ฐ€๋„ ์ฆ๊ฐ€๋ณด๋‹ค ์šฐ์„ ํ•ฉ๋‹ˆ๋‹ค.

@drewnoakes

์ดํ•ดํ•˜๊ณ  ์ผ๊ด€์„ฑ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. ๋‚˜๋Š” ๊ทธ๊ฒƒ์ด ISet<T> ๊ฐ€ IReadOnlySet<T> ํ™•์žฅํ•ด์„œ๋Š” ์•ˆ๋˜๋Š” ์ด์œ ์— ๋Œ€ํ•ด์„œ๋„ ๋Œ€๋‹ตํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•˜๋Š” ๊ฒƒ์ด IMHO์˜ ์ •๋ฐ€๋„ ์ฆ๊ฐ€๋ณด๋‹ค ์šฐ์„ ํ•ฉ๋‹ˆ๋‹ค.

๋‚˜๋Š” ๊ทธ๊ฒƒ์ด ISet<T> ๊ฐ€ IReadOnlySet<T> ํ™•์žฅํ•ด์„œ๋Š” ์•ˆ๋˜๋Š” ์ด์œ ์— ๋Œ€ํ•ด์„œ๋„ ๋Œ€๋‹ตํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

๋‚˜๋Š” ๋‹น์‹ ์ด ์š”์ ์„ ๋†“์น˜๊ณ  ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์ด ISet<T> ์™ธ์—๋„ IList<T> , ICollection<T> , IDictionary<TKey, TValue> ๋„ ์ฝ๊ธฐ ์ „์šฉ ๋ณด๊ธฐ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๋„๋ก ์ˆ˜์ •๋˜์–ด์•ผ ํ•˜๋Š” ์ด์œ ์ž…๋‹ˆ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ๋ชจ๋“  ์‚ฌ๋žŒ์ด BCL์˜ ์ง๊ด€์ ์ด์ง€ ์•Š์€ ๋””์ž์ธ์„ ํ•ด๊ฒฐํ•  ๋•Œ ๊ณ„์†ํ•ด์„œ ํ•ฉ๋‹ˆ๋‹ค .

@binki

๋‚˜๋Š” ๋™์˜ํ•˜์ง€ ์•Š๋Š”๋‹ค. ๋‚ด๊ฐ€ ๊ทธ๊ฒƒ์— ๋Œ€ํ•ด ์ข‹์•„ํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์€ read-_only_ ๋™์ž‘์„ ๊ทœ์ •ํ•˜๋Š” ๊ณ„์•ฝ์ด read-_write_ ๋™์ž‘์„ ๊ทœ์ •ํ•˜๋Š” ๊ณ„์•ฝ์— ์˜ํ•ด ํ™•์žฅ๋˜๋Š” ๊ฒƒ์„ ๊ทœ์ •ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋„ค์ด๋ฐ์ด ํ‹€๋ฆฌ๊ณ  ๊ตฌ์„ฑ์ด ํ‹€๋ฆฌ๋„ค์š”. ํ•˜์ง€๋งŒ ์—ฌ๊ธฐ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‚˜๋Š” ๋‘˜ ๋‹ค ๋ณ€๊ฒฝํ•˜๊ธฐ ์œ„ํ•ด ํˆฌํ‘œํ•˜๊ณ  ์‹ถ์ง€๋งŒ ๊ทธ๊ฒƒ์ด ํ…Œ์ด๋ธ”์— ์žˆ๋Š”์ง€ ์˜์‹ฌ๋ฉ๋‹ˆ๋‹ค.

@HaloFour

์–ด๋–ค ๊ฒƒ์— ๋Œ€ํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์–ป์„ ๋•Œ, ๊ทธ๊ฒƒ์€ ๋ฌด์–ธ๊ฐ€์— ๋Œ€ํ•œ _view_์ž…๋‹ˆ๋‹ค. ๋ณด๊ธฐ ์ž์ฒด๋Š” _is_ ์ฝ๊ธฐ ์ „์šฉ์ž…๋‹ˆ๋‹ค. ์œ ํ˜• ์•ˆ์ „ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ์—…์บ์ŠคํŒ…์„ ์ง„ํ–‰ํ•˜์ง€ ์•Š๋Š”๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๋ฉด ์ฝ๊ธฐ ์ „์šฉ์ธ ๊ฒƒ์„ ์ˆ˜์‹ ํ•˜๋ฉด ๋ชจ๋“  ์˜๋„์™€ ๋ชฉ์ ์— ๋Œ€ํ•ด ์ฝ๊ธฐ ์ „์šฉ์ž…๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐ๊ฐ€ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๋ณด์žฅ์€ ์—†์Šต๋‹ˆ๋‹ค. ํŒŒ์ผ์„ ์ฝ๊ธฐ ์ „์šฉ์œผ๋กœ ์—ฌ๋Š” ๊ฒƒ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ฝ๊ธฐ ์ „์šฉ์œผ๋กœ ์—ด๋ฆฐ ํŒŒ์ผ์€ ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค์— ์˜ํ•ด ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜๋Š” ๊ด€๋ฆฌ์ž๊ฐ€ ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ์ฝ๊ธฐ-์“ฐ๊ธฐ ๋ณด๊ธฐ๋ฅผ ๊ฐ–๊ณ  ์‚ฌ์šฉ์ž ์•„๋ž˜์—์„œ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋Š” ์›น ์‚ฌ์ดํŠธ์˜ ํŽ˜์ด์ง€์— ๋Œ€ํ•œ ์ฝ๊ธฐ ์ „์šฉ ์•ก์„ธ์Šค์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์—ฌ๊ธฐ์—์„œ ์ฝ๊ธฐ ์ „์šฉ์ด ์ž˜๋ชป๋œ ์šฉ์–ด๋กœ ๊ฐ„์ฃผ๋˜๋Š” ์ด์œ ๋ฅผ ์ž˜ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ฝ๊ธฐ ์ „์šฉ์€ ๋ถˆ๋ณ€์„ ์˜๋ฏธํ•˜์ง€ _์•Š์Šต๋‹ˆ๋‹ค_. ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์ „์ฒด nuget ํŒจํ‚ค์ง€/๋‹ค๋ฅธ API(์ถ”๊ฐ€/์ œ๊ฑฐ๊ฐ€ ์ƒˆ ๊ฐœ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ํ˜„์žฌ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ ˆ๋Œ€ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์Œ์„ ๋ณด์žฅํ•˜๋ฏ€๋กœ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†์Œ)๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

๋น„์Šทํ•œ ์ƒ๊ฐ์„ ํ•˜๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. .NET์˜ "์ฝ๊ธฐ ์ „์šฉ"์€ ํ•„๋“œ์— ๋Œ€ํ•ด์„œ๋„ ๋งค์šฐ ์•ฝํ•œ ๋ณด์žฅ์ž…๋‹ˆ๋‹ค. do-over๋ฅผ ๊ฐ์•ˆํ•  ๋•Œ ์ด ๋ชจ๋“  ๊ฒƒ์ด ๋” ํ•ฉ๋ฆฌ์ ์ผ ๊ฒƒ์ด๋ผ๊ณ  ํ™•์‹ ํ•ฉ๋‹ˆ๋‹ค. ์ง€๊ธˆ์€ ์‹ค์šฉ์ ์ผ ๊ฐ€์น˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ์ผ๋ฐ˜์ ์œผ๋กœ ๋ฉ”์„œ๋“œ๊ฐ€ IReadOnlySomething<T> ๋ฅผ ์ˆ˜๋ฝํ•˜๋ฉด ์ผ๋ฐ˜์ ์œผ๋กœ ์ˆ˜์ •ํ•˜์ง€ ์•Š์„ ๊ฒƒ์ด๋ผ๊ณ  ๊ฐ€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ˆ˜์‹  ๋ฉ”์„œ๋“œ๊ฐ€ ์ฐธ์กฐ๋ฅผ ์—…์บ์ŠคํŠธํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๋ณด์žฅ์ด ์—†์œผ๋ฉฐ ์ธํ„ฐํŽ˜์ด์Šค์˜ ๊ตฌํ˜„์ด ์•ก์„ธ์Šค๋  ๋•Œ ๋‚ด๋ถ€์ ์œผ๋กœ ์ž์ฒด ์ˆ˜์ •๋˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๋ณด์žฅ๋„ ์—†์Šต๋‹ˆ๋‹ค.

C++์—์„œ const_cast ๋Š” const ์˜ ๋ณด์žฅ๋„ ์•ฝํ™”์‹œํ‚ต๋‹ˆ๋‹ค. ์ด๋Š” ์ˆ˜์น˜์Šค๋Ÿฌ์šด ์ผ์ด์ง€๋งŒ(์š”์ฆ˜์€ mutable ์ˆ˜์ •์ž๊ฐ€ ์žˆ์Œ) ์‹ค์ œ๋กœ๋Š” ์–ผ๋งˆ๋‚˜ ์œ ์šฉํ•œ์ง€ const ๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค. ๋‹น์‹ ์€ ๋‹น์‹ ์ด ๋ฌด์—‡์„ ๋‹ค๋ฃจ๊ณ  ์žˆ๋Š”์ง€ ์•Œ์•„์•ผํ•ฉ๋‹ˆ๋‹ค.

@binki ๋Š” ์ž˜ ๊ตฌ๋ณ„๋ฉ๋‹ˆ๋‹ค. ์ด๋ฆ„์—์„œ _Immutable_์€ ๊ด€๋ จ๋œ ๋ชจ๋“  ์‚ฌ๋žŒ์—๊ฒŒ ์‹œ๊ฐ„์ด ์ง€๋‚จ์— ๋”ฐ๋ผ ์•ˆ์ •์„ฑ์„ ๋ณด์žฅํ•œ๋‹ค๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค.

IList<T> ๊ฐ€ IReadOnlyList<T> ํ™•์žฅํ•˜์ง€ ์•Š๋Š” ์ด์œ ์— ๋Œ€ํ•œ ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ์ถœ์ฒ˜๊ฐ€ ์žˆ๋Š” ์‚ฌ๋žŒ์ด ์žˆ์Šต๋‹ˆ๊นŒ?

@binki

์ธํ„ฐํŽ˜์ด์Šค๋Š” ๋ณด๊ธฐ๊ฐ€ ์•„๋‹ˆ๋ผ ๊ณ„์•ฝ์ž…๋‹ˆ๋‹ค. ๊ทธ ๊ณ„์•ฝ์€ ๊ตฌํ˜„์ž์˜ ๋Šฅ๋ ฅ์„ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. ๊ตฌํ˜„์ž๊ฐ€ ์‹ค์ œ๋กœ ์ด๋Ÿฌํ•œ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜์ง€ ์•Š์œผ๋ฉด ๊ณ„์•ฝ ์œ„๋ฐ˜์œผ๋กœ ๊ฐ„์ฃผํ•ฉ๋‹ˆ๋‹ค. ํ•ด๋‹น List<T> ํด๋ž˜์Šค๋Š” "is-a" IReadOnlyList<T> ๋ผ๊ณ  ์ฃผ์žฅํ•˜์ง€๋งŒ ๊ทธ๋ ‡์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ทธ ๋Šฅ๋ ฅ์ด ๋ถ€์กฑํ•ฉ๋‹ˆ๋‹ค.

์ด ์ฃผ์ œ์— ๋Œ€ํ•ด ์—ฌ๋Ÿฌ ํ•™ํŒŒ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‚˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์†์ด ์œ ํ˜• ๊ฐ„์˜ "is-s-in" ๊ด€๊ณ„๋ฅผ ๋” ์—„๊ฒฉํ•˜๊ฒŒ ๋”ฐ๋ฅด๋Š” ํ•™๊ต์— ๋ถ„๋ช…ํžˆ ์†ํ•ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋‚˜๋Š” ํ™•์‹คํžˆ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌ์„ฑ์— ๋Œ€ํ•œ ๋ณด๋‹ค ์„ธ๋ถ„ํ™”๋œ ์ ‘๊ทผ ๋ฐฉ์‹์„ ์ง€์›ํ•˜๊ณ  List<T> ๋ฐ ๊ทธ ์นœ์ฒ™์ด 3-4๊ฐœ์˜ ์ถ”๊ฐ€ ์ธํ„ฐํŽ˜์ด์Šค(์ฝ๊ธฐ, ์“ฐ๊ธฐ, ์ถ”๊ฐ€ ๋“ฑ)๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์ด ๋„์›€์ด ๋  ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ํ™•์‹คํžˆ ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ์ธํ„ฐํŽ˜์ด์Šค ์ด๋ฆ„์€ ์œ ํ˜•์ด _ํ•  ์ˆ˜ ์—†๋Š”_ ์ผ์ด ์•„๋‹ˆ๋ผ _ํ•  ์ˆ˜ ์žˆ๋Š”_ ํ•˜๋Š” ์ผ์„ ์„ค๋ช…ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ถ€์ •์ ์ธ ๋Šฅ๋ ฅ ์ฃผ์žฅ์€ ๊ณ„์•ฝ์— ๋ณ„๋กœ ์˜๋ฏธ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.

@drewnoakes

์ง€๊ธˆ์€ ์‹ค์šฉ์ ์ผ ๊ฐ€์น˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‚˜๋Š” ๋™์˜ํ•œ๋‹ค. ์šฐ๋ฆฌ๋Š” ์šฐ๋ฆฌ๊ฐ€ ์žˆ๋Š” ๊ณณ์— ์žˆ์Šต๋‹ˆ๋‹ค. IList<T> ๊ฐ€ IReadOnlyList<T> ๋ฅผ ํ™•์žฅํ•˜๋„๋ก ๋ณ€๊ฒฝ๋˜๋ฉด ISet<T> ๊ฐ€ IReadOnlySet<T> ๋“ฑ์„ ํ™•์žฅํ•˜๋„๋ก ๋ณ€๊ฒฝ๋˜๋Š” ๊ฒƒ์ด ํ•ฉ๋ฆฌ์ ์ž…๋‹ˆ๋‹ค.

IReadableX<T> , IWritableX<T> ๋“ฑ์˜ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ IReadOnlyX<T> ์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๊ธฐ์—๋Š” ๋„ˆ๋ฌด ์ค‘๋ณต๋ฉ๋‹ˆ๊นŒ?

IList<T> ๊ฐ€ IReadOnlyList<T> ํ™•์žฅํ•˜์ง€ ์•Š๋Š” ์ด์œ ์— ๋Œ€ํ•ด ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ์ถœ์ฒ˜๊ฐ€ ์žˆ๋Š” ์‚ฌ๋žŒ์ด ์žˆ์Šต๋‹ˆ๊นŒ?

๋ถ„๋ช…ํžˆ ์ด์ „ .net ํ”„๋ ˆ์ž„์›Œํฌ์— ๋Œ€ํ•ด ์ปดํŒŒ์ผ๋œ ์–ด์…ˆ๋ธ”๋ฆฌ๋ฅผ ๋กœ๋“œํ•  ๋•Œ ABI๋ฅผ ๊นจ๋Š” ๋ณ€๊ฒฝ์ด ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•  ๋•Œ ๋Œ€๋ถ€๋ถ„์˜ ์ปดํŒŒ์ผ๋Ÿฌ๋Š” ์†Œ์Šค ์ฝ”๋“œ๊ฐ€ ์•”์‹œ์  ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌํ˜„์— ์˜์กดํ•  ๋•Œ ์ž๋™์œผ๋กœ ๋ช…์‹œ์  ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌํ˜„์„ ์ƒ์„ฑํ•˜๊ธฐ ๋•Œ๋ฌธ์— IList<T> ๊ฐ€ ์—†๋Š” BCL์— ๋Œ€ํ•ด IList<T> ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ํด๋ž˜์Šค๋ฅผ ์ปดํŒŒ์ผํ•˜๋ฉด IReadOnlyList<T> ๊ตฌํ˜„ํ•˜๋ฉด ์ปดํŒŒ์ผ๋Ÿฌ๋Š” ๋ช…์‹œ์ ์ธ IReadOnlyList<T> ๊ตฌํ˜„์„ ์ž๋™์œผ๋กœ ์ƒ์„ฑํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋‚ด๊ฐ€ ์ด ๊ธ€์„ ์ฝ๊ณ  ์žˆ๋‹ค๋ฉด: http://stackoverflow.com/a/35940240/429091

@HaloFour List<> ์™€ HashSet<> ๊ฐ€ ICollection<> ์™€ IReadOnlyCollection<> ๋•Œ๋ฌธ์— ์šฐ๋ฆฌ๋Š” ์ด๋ฏธ IReadOnly ๊ฐ€ ์ ‘๊ทผ์ด ์•„๋‹Œ ์ ‘๊ทผ์„ ๊ฐ€๋ฆฌํ‚ค๋Š” ๊ฒฝ๋กœ๋ฅผ ๋ฐ›์•„๋“ค์˜€์Šต๋‹ˆ๋‹ค. ๋Šฅ๋ ฅ. ์ด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ IAnything IReadOnlyAnything ํ™•์žฅํ•˜๋Š” ๊ฒƒ์ด ์™„๋ฒฝํ•ฉ๋‹ˆ๋‹ค. IReadable ๊ฐ€ IReadOnly ๋ณด๋‹ค ๋‚ซ๋‹ค๋Š” ๋ฐ ๋™์˜ํ•˜์ง€๋งŒ ์ด ์‹œ์ ์—์„œ ๋ชจ๋‘๊ฐ€ IReadOnly ๋ฅผ IReadable _mean_ ์ดํ•ดํ•˜๊ณ  ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ์‹ค, ๋‚˜๋Š” ์‚ฌ๋ฌผ์— ๋Œ€ํ•ด ๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹์œผ๋กœ ์ƒ๊ฐํ•˜๋Š” ๊ฒƒ์ด ๋‚ด ์ƒ๊ฐ์— ๊ทธ ์–ด๋–ค ๊ฒƒ๋ณด๋‹ค ์ธ์ง€ ๋ถ€ํ•˜๊ฐ€ โ€‹โ€‹๋” ํฌ๊ธฐ ๋•Œ๋ฌธ์— ์˜๋„์ ์œผ๋กœ ๋‚ด ์ž์‹ ์˜ ์ฝ”๋“œ๋ฒ ์ด์Šค์—์„œ ์˜์†ํ™”ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

์šฐ๋ฆฌ๋Š” ๊ทธ ์ด๋ฆ„์— ์–ฝ๋งค์—ฌ ์žˆ์ง€๋งŒ ๊ทธ ์ด๋ฉด์˜ ๊ฐœ๋…์€ ์šฐ๋ฆฌ๊ฐ€ ๊ตฌ์ฒด ํด๋ž˜์Šค์—์„œ ํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์•ž์œผ๋กœ ๋ชจ๋“  ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ IReadOnly ๋ฅผ ํ™•์žฅํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€๋Šฅํ•˜๊ธฐ๋ฅผ ์ง„์ •์œผ๋กœ ๋ฐ”๋ž„ ๋งŒํผ ์ถฉ๋ถ„ํžˆ ๊ฐ•๋ ฅํ•ฉ๋‹ˆ๋‹ค.

@ashmind ์–ด๋–ค ๋ฐฉ๋ฒ•๋„ ๋น„๊ต์ž๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ์™„๋ฒฝํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ์„ธํŠธ์™€ ์‚ฌ์ „์—์„œ ๋น„๊ต์ž๋Š” ์ „์ฒด ๊ฐ์ฒด์˜ ๊ตฌ์กฐ๋ฅผ ๊ฒฐ์ •ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์‰ฝ๊ฒŒ ๊ต์ฒดํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด ์•„๋‹™๋‹ˆ๋‹ค. ๋˜ํ•œ CaseInsensitiveStringCollection ๋˜๋Š” ํŠน์ • ๋น„๊ต๋ฅผ ์•”์‹œํ•˜๋Š” ์ปฌ๋ ‰์…˜์— ๋น„๊ต์ž๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๊ฒƒ์€ ์ด์น˜์— ๋งž์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

(์ด๋ฏธ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ํ™•์žฅ ๋ฉ”์„œ๋“œ ๋ณด๋‹ค Contains(T, IEqualityComparer<T>) ๋” ํšจ์œจ์ ์œผ๋กœ ๊ตฌํ˜„ํ•˜๋Š” ์ด์ƒํ•œ ์ปฌ๋ ‰์…˜์˜ ๊ฒฝ์šฐ ์•„๋งˆ๋„ ์ผํšŒ์„ฑ ํด๋ž˜์Šค ๋ฉ”์„œ๋“œ์ผ ๊ฒƒ์ž…๋‹ˆ๋‹ค. Contains(T, IEqualityComparer<T>) ๊ฐ€ ์ผ๋ฐ˜์ ์ด๋ผ๊ณ  ์ƒ์ƒํ•˜๊ธฐ ์–ด๋ ต์Šต๋‹ˆ๋‹ค. ์ „๋ฌธํ™”๋œ ์ธํ„ฐํŽ˜์ด์Šค๋กœ ๋๋‚˜๊ธฐ์— ์ถฉ๋ถ„ํ•˜์ง€๋งŒ ๊ทธ๋Ÿฐ ์ผ์ด ์ผ์–ด๋‚˜์ง€ ์•Š๋„๋ก ๋ง‰์„ ๋ฐฉ๋ฒ•์€ ์—†์Šต๋‹ˆ๋‹ค.)

@jnm2

์–ด๋–ค ๋ฐฉ๋ฒ•๋„ ๋น„๊ต์ž๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ์™„๋ฒฝํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

๋ช…ํ™•ํžˆํ•˜๊ธฐ ์œ„ํ•ด ๋น„๊ต์ž๋ฅผ ๋…ธ์ถœ์‹œํ‚ค๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๋…ธ์ถœํ•ด์•ผํ•œ๋‹ค๊ณ  ๋งํ•˜๊ณ  ์‹ถ์—ˆ์Šต๋‹ˆ๋‹ค. ๋ชจ๋“  Set ๋˜๋Š” Dictionary์—๋Š” ๋™์ผํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์žˆ์–ด์•ผ ํ•˜๋ฏ€๋กœ ์ธํ„ฐํŽ˜์ด์Šค์— ๋…ธ์ถœ๋˜์—ˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ง€๊ธˆ์€ ์‚ฌ์šฉ ์‚ฌ๋ก€๊ฐ€ ๊ธฐ์–ต๋‚˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์™ธ๋ถ€์—์„œ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ๊ณผ ๋™์ผํ•œ ๋น„๊ต์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ง‘ํ•ฉ์„ ๋งŒ๋“œ๋Š” ๊ฒƒ๊ณผ ๊ฐ™์€ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์ด ํ† ๋ก ์—์„œ ํฅ๋ฏธ๋กœ์šด ์ ๋“ค์ด ๋งŽ์ด ๋‚˜์˜ค์ง€๋งŒ, ์ด ์Šค๋ ˆ๋“œ๋ฅผ ์‹œ์ž‘ํ•œ ๊ฐ„๋‹จํ•˜๊ณ  ๋ถ„๋ช…ํ•œ ์ œ์•ˆ๊ณผ๋Š” ๊ฑฐ๋ฆฌ๊ฐ€ ๋จผ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ด ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋˜์—ˆ์œผ๋ฉด ํ•˜๋Š” ๋ฐ”๋žŒ์— ์‹ค๋ง์Šค๋Ÿฝ์Šต๋‹ˆ๋‹ค.

OP๊ฐ€ ๋งํ–ˆ๋“ฏ์ด IReadOnlySet ์—†์ด IReadOnlyList๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ์„ ๋•Œ ์ปฌ๋ ‰์…˜ ์œ ํ˜• ๊ฐ„์˜ ํŒจ๋ฆฌํ‹ฐ๋ฅผ ์œ ์ง€ํ•˜์ง€ ๋ชปํ•œ ๊ฒƒ์€ ๋ถˆํ–‰ํ•œ ์ผ์ด๋ฉฐ ๋งŽ์€ ์‚ฌ๋žŒ๋“ค์ด ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์œผ๋กœ ์ž์ฒด ๋ฒ„์ „์˜ IReadOnlySet ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค(์ €์˜ ํŒ€๋„ ๋น„์Šทํ•œ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค). ์ด๋Ÿฌํ•œ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• ์ธํ„ฐํŽ˜์ด์Šค๋Š” corefx ํด๋ž˜์Šค์—์„œ ๊ตฌํ˜„ํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์— ์ด์ƒ์ ์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์ด ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ ์ด๊ฒƒ์„ ์ œ๊ณตํ•˜๋Š” ์ฃผ์š” ์ด์œ ์ž…๋‹ˆ๋‹ค. HashSet์ด ์žˆ๋Š” ๊ฒฝ์šฐ ์ด๋ฏธ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฐœ์ฒด๋ฅผ ๋ณต์‚ฌํ•˜๊ฑฐ๋‚˜ ๋ž˜ํ•‘ํ•˜์ง€ ์•Š๊ณ  IReadOnlySet์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค. ์„ฑ๋Šฅ์„ ์œ„ํ•ด์„œ๋Š” ์ ์–ด๋„ ์ด๊ฒƒ์ด ์ข…์ข… ๋ฐ”๋žŒ์งํ•ฉ๋‹ˆ๋‹ค.

์ธํ„ฐํŽ˜์ด์Šค์˜ ์ด๋ฆ„์€ ๋ถ„๋ช…ํžˆ IReadOnlySet์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ผ๊ด€์„ฑ์€ IReadOnlyXXX ์ด๋ฆ„์— ๋Œ€ํ•œ ๋ชจ๋“  ๋ฌธ์ œ๋ฅผ ๋Šฅ๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ๋ฐฐ๋Š” ํ•ญํ•ดํ–ˆ์Šต๋‹ˆ๋‹ค.

๊ธฐ์กด ์ธํ„ฐํŽ˜์ด์Šค(IReadOnlyCollection)๋Š” ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. .NET์— ๋Œ€ํ•œ ์ด์ „ ๋ฒ„์ „๊ณผ์˜ ํ˜ธํ™˜์„ฑ ์š”๊ตฌ ์‚ฌํ•ญ์€ ๊ทธ๋Ÿฌํ•œ ๋ณ€๊ฒฝ์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋น„๊ต์ž๊ฐ€ ๊ธฐ์กด IReadOnlyXXX ์ธํ„ฐํŽ˜์ด์Šค์— ๋…ธ์ถœ๋˜์ง€ ์•Š์€ ๊ฒƒ์€ ๋ถˆํ–‰ํ•œ ์ผ์ด์ง€๋งŒ(์ด ๊ฒฝ์šฐ์—๋„ ๋งˆ์ฐฌ๊ฐ€์ง€์ž„) ๋ฐฐ๊ฐ€ ๋‹ค์‹œ ํ•ญํ•ดํ–ˆ์Šต๋‹ˆ๋‹ค.

์‹ค์šฉ์ ์ธ ๊ด€์ ์—์„œ ๋‚จ์•„ ์žˆ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ด๋Š” ์œ ์ผํ•œ ์งˆ๋ฌธ์€ ์ธํ„ฐํŽ˜์ด์Šค์— ๋Œ€ํ•œ ์ด ๋‘ ๊ฐ€์ง€ ์ž ์žฌ์  ์ •์˜ ์‚ฌ์ด์ž…๋‹ˆ๋‹ค.

@ashmind๊ฐ€ ์ด์ „์— ์ œ์•ˆํ•œ ๋‚ด์šฉ:

public interface IReadOnlySet<T> : IReadOnlyCollection<T> {    
    bool Contains(T item);
    bool IsSubsetOf(IEnumerable<T> other);
    bool IsSupersetOf(IEnumerable<T> other);
    bool IsProperSupersetOf(IEnumerable<T> other);
    bool IsProperSubsetOf(IEnumerable<T> other);
    bool Overlaps(IEnumerable<T> other);
    bool SetEquals(IEnumerable<T> other);
}

์ตœ์†Œํ•œ์˜ ์ œ์•ˆ:

public interface IReadOnlySet<T> : IReadOnlyCollection<T> {    
    bool Contains(T item);
}

๊ฐœ์ธ์ ์œผ๋กœ ๋‚˜๋Š” ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์ด ํŒŒ์ƒ๋  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด ์ตœ์†Œํ•œ์˜ ์ œ์•ˆ์„ ์„ ํ˜ธํ•ฉ๋‹ˆ๋‹ค. ์ด์ƒ์ ์œผ๋กœ๋Š” IReadOnlySet ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด ํ™•์žฅ ๋ฉ”์„œ๋“œ๋กœ ์ด๋Ÿฌํ•œ ํ‘œ์ค€ ๊ตฌํ˜„์ด ์žˆ์œผ๋ฏ€๋กœ IReadOnlySet ๊ตฌํ˜„์ž๊ฐ€ ์ด๋ฅผ ์ œ๊ณตํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ๋‚˜๋Š” ๋˜ํ•œ ์ด ์ตœ์†Œํ•œ์˜ ์ œ์•ˆ์ด ๋‹ค๋ฅธ ์ตœ์†Œํ•œ์˜ IReadOnlyXXX ์ธํ„ฐํŽ˜์ด์Šค์™€ ๋” ์ผ์น˜ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

@aaron-meyers ๋‚ด๊ฐ€ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” ์œ ์ผํ•œ ๊ฑฑ์ •์€ IsSubsetOf ์™€ ์นœ๊ตฌ๊ฐ€ Contains ์—์„œ _ํšจ์œจ์ ์ธ_ ๋ฐฉ์‹์œผ๋กœ ํŒŒ์ƒ๋  ์ˆ˜ ์—†๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ํ•ด์‹œ ํ…Œ์ด๋ธ”์ด ๋‘ ๊ฐœ์ธ ๊ฒฝ์šฐ Contains ์— ์˜์กดํ•˜๋ฉด ๊ตฌํ˜„์—์„œ ํ•ด์‹œ ์ผ์น˜๊ฐ€ ์•„๋‹Œ ์ค‘์ฒฉ ๋ฃจํ”„๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์•„๋งˆ๋„ ์ƒˆ๋กœ์šด ์ธํ„ฐํŽ˜์ด์Šค์ธ IComparableSet<T> ์—๋Š” ์ง‘ํ•ฉ ์ž‘์—…์ด ํฌํ•จ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ช‡ ๊ฐ€์ง€ ์ง‘ํ•ฉ ์ž‘์—…์— ๋Œ€ํ•ด IEnumerable<T> ๋Œ€ํ•œ ํ™•์žฅ ๋ฉ”์„œ๋“œ๊ฐ€ ์ด๋ฏธ ์žˆ์Šต๋‹ˆ๋‹ค.

@jnm2 HashSet์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์ด๋Ÿฌํ•œ ๋ฉ”์„œ๋“œ ์˜ IReadOnlySet ์€

์ˆ˜์ •๋œ ์ œ์•ˆ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

public interface IReadOnlySet<T> : IReadOnlyCollection<T> {    
    IEqualityComparer<T> Comparer { get; }
    bool Contains(T item);
}

๋˜๋Š” Comparer๊ฐ€ ๋ณ„๋„์˜ ์ธํ„ฐํŽ˜์ด์Šค์— ์žˆ์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ ์„ค์ • ์ž‘์—…์˜ ํ™•์žฅ ๋ฉ”์„œ๋“œ ๊ตฌํ˜„์€ ๋‘ ๊ฐœ์ฒด๊ฐ€ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๊ณ  ๋™์ผํ•œ ๋น„๊ต์ž๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ ํšจ์œจ์ ์ธ ๊ฒฝ๋กœ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. IReadOnlyDictionary์— ๋Œ€ํ•ด ๋™์ผํ•œ ์ ‘๊ทผ ๋ฐฉ์‹์„ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค(์‚ฌ์‹ค, ์•„๋งˆ๋„ ๋™์ผํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•จ). ISetComparable๊ณผ ๊ฐ™์€ ๊ฒƒ. ๋˜๋Š” @drewnoakes ์—์„œ ๊ทธ๋ฆผ์„ ๊ทธ๋Ÿฌ๋‚˜ ์ง‘ํ•ฉ ์—ฐ์‚ฐ์ž๋ฅผ ์ •์˜ํ•˜๋Š” ๋Œ€์‹  ๋น„๊ต์ž๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

public interface IComparableSet<T> : IReadOnlySet<T> {    
    IEqualityComparer<T> Comparer { get; }
}

์ด ๊ฒฝ์šฐ IReadOnlySet์€ ๋‹ค์Œ์„ ์ •์˜ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋Œ์•„๊ฐ‘๋‹ˆ๋‹ค.

public interface IReadOnlySet<T> : IReadOnlyCollection<T> {    
    bool Contains(T item);
}

public interface IReadOnlySet<T> : IReadOnlyCollection<T> {    
    bool Contains(T item);
}
public interface IReadOnlySetEx<T> : IReadOnlySet<T> {    
    bool IsSubsetOf(IEnumerable<T> other);
    bool IsSupersetOf(IEnumerable<T> other);
    bool IsProperSupersetOf(IEnumerable<T> other);
    bool IsProperSubsetOf(IEnumerable<T> other);
    bool Overlaps(IEnumerable<T> other);
    bool SetEquals(IEnumerable<T> other);
    IEqualityComparer<T> Comparer { get; }
}
public class HashSet<T>: IReadOnlySetEx<T>, ISet<T>
{
   // Improved implementation here.
}

public static class CollectionExtensiosn
{
    public static IEqualityComparer<T> GetComparer<T>(this IReadOnlySet<T> @set)
    {
           var setEx = <strong i="5">@set</strong> as IReadOnlySetEx<T>;
           if (setEx == null)
           {
                throw new ArgumentException("set should implement IReadOnlySetEx<T> for this method.")
           }
           return setEx.Comparer;
    }

    public static bool IsSubsetOf<T>(this IReadOnlySet<T> <strong i="6">@set</strong>, IEnumerable<T> other)
    {
         var setEx = <strong i="7">@set</strong> as IReadOnlySetEx<T>;
         if (setEx != null)
         {
              return setEx.IsSubsetOf(other);
         }
         // Non optimal implementation here.
    }

    // The same approach for dictionary.
    public static IEqualityComparer<T> GetKeyComparer<T>(this IReadOnlyDictionary<T> dictionary)
    {
           var dictionaryEx = set as IReadOnlyDictionaryEx<T>;
           if (dictionaryEx == null)
           {
                throw new ArgumentException("dictionary should implement IReadDictionaryEx<T> for this method.")
           }
           return dictionaryEx.KeyComparer;
    }

}

์šฐ๋ฆฌ๋Š” ์ด ์ ‘๊ทผ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์‚ฌ์šฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

IReadOnlySet<string> mySet = new HashSet<string>();
bool test = mySet.IsSubsetOf(new []{"some", "strings", "set"}); // Extension method
var = mySet.GetComparer(); // Extension method

๋งŽ์€ ์š”๊ตฌ ์‚ฌํ•ญ์ด ์ถฉ์กฑ๋จ, IReadOnlySet๋ฏธ๋‹ˆ๋ฉ€ํ•˜๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ GetComparer๋Š” ์ด์ œ ์†์„ฑ์ด ์•„๋‹ˆ๋ผ ๋ฉ”์„œ๋“œ์ž…๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ข‹์€ ๊ฑฐ๋ž˜์ž…๋‹ˆ๋‹ค.

    /// <summary>
    /// Readable set abstracton. Allows fast contains method, also shows that collection items are unique by some criteria.
    /// </summary>
    /// <remarks>
    /// Proposal for this abstraction is discussed here https://github.com/dotnet/corefx/issues/1973.
    /// </remarks>
    /// <typeparam name="T">The type of elements in the set.</typeparam>
    public interface IReadOnlySet<out T> : IReadOnlyCollection<T>
    {
        /// <summary>
        /// Determines whether a <see cref="T:System.Collections.Generic.HashSet`1"/> object contains the specified
        /// element.
        /// </summary>
        /// <typeparam name="TItem">The type of the provided item. This trick allows to save contravariance and save from boxing.</typeparam>
        /// <returns>
        /// true if the <see cref="T:System.Collections.Generic.HashSet`1"/> object contains the specified element;
        /// otherwise, false.
        /// </returns>
        /// <param name="item">The element to locate in the <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param>
        bool Contains<TItem>(TItem item);
    }

namespace System.Collections.Generic
{
    /// <summary>
    /// Provides the base interface for the abstraction of sets. <br/>
    /// This is full-featured readonly interface but without contravariance. See contravariant version
    /// <see cref="IReadOnlySet{T}"/>.
    /// </summary>
    /// <typeparam name="T">The type of elements in the set.</typeparam>
    public interface IReadableSet<T> : IReadOnlySet<T>
    {
        /// <summary>
        /// Gets the <see cref="Generic.IEqualityComparer{T}"/> object that is used to determine equality for the values
        /// in the set.
        /// </summary>
        /// <returns>
        /// The <see cref="Generic.IEqualityComparer{T}"/> object that is used to determine equality for the values in the
        /// set.
        /// </returns>
        IEqualityComparer<T> Comparer { get; }

        /// <summary>
        /// Determines whether a <see cref="T:System.Collections.Generic.HashSet`1"/> object contains the specified
        /// element.
        /// </summary>
        /// <returns>
        /// true if the <see cref="T:System.Collections.Generic.HashSet`1"/> object contains the specified element;
        /// otherwise, false.
        /// </returns>
        /// <param name="item">The element to locate in the <see cref="T:System.Collections.Generic.HashSet`1"/> object.</param>
        bool Contains(T item);

        /// <summary>
        /// Determines whether the current set is a proper (strict) subset of a specified collection.
        /// </summary>
        /// <returns><see langword="true"/> if the current set is a proper subset of <paramref name="other"/>; otherwise, false.</returns>
        /// <param name="other">The collection to compare to the current set.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="other"/> is null.
        /// </exception>
        bool IsProperSubsetOf(IEnumerable<T> other);

        /// <summary>Determines whether the current set is a proper (strict) superset of a specified collection.</summary>
        /// <returns>true if the current set is a proper superset of <paramref name="other"/>; otherwise, false.</returns>
        /// <param name="other">The collection to compare to the current set. </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="other"/> is null.
        /// </exception>
        bool IsProperSupersetOf(IEnumerable<T> other);

        /// <summary>Determines whether a set is a subset of a specified collection.</summary>
        /// <returns>true if the current set is a subset of <paramref name="other"/>; otherwise, false.</returns>
        /// <param name="other">The collection to compare to the current set.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="other"/> is null.
        /// </exception>
        bool IsSubsetOf(IEnumerable<T> other);

        /// <summary>Determines whether the current set is a superset of a specified collection.</summary>
        /// <returns>true if the current set is a superset of <paramref name="other"/>; otherwise, false.</returns>
        /// <param name="other">The collection to compare to the current set.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="other"/> is null.
        /// </exception>
        bool IsSupersetOf(IEnumerable<T> other);

        /// <summary>Determines whether the current set overlaps with the specified collection.</summary>
        /// <returns>true if the current set and <paramref name="other"/> share at least one common element; otherwise, false.</returns>
        /// <param name="other">The collection to compare to the current set.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="other"/> is null.
        /// </exception>
        bool Overlaps(IEnumerable<T> other);

        /// <summary>Determines whether the current set and the specified collection contain the same elements.</summary>
        /// <returns>true if the current set is equal to <paramref name="other"/>; otherwise, false.</returns>
        /// <param name="other">The collection to compare to the current set.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="other"/> is null.
        /// </exception>
        bool SetEquals(IEnumerable<T> other);
    }
}

nuget(https://www.nuget.org/packages/ClrCoder.Collections.ReadOnlySet)์— ๋Œ€ํ•œ ์ฃผ์ž… ๋„์šฐ๋ฏธ์™€ ํ•จ๊ป˜ ์ด ๊ณ„์•ฝ์„ ๊ฒŒ์‹œํ–ˆ์Šต๋‹ˆ๋‹ค.
์ž์œ ๋กญ๊ฒŒ ์‚ฌ์šฉํ•˜๊ณ  ์—ฌ๊ธฐ์—์„œ ๋ฌธ์ œ๋ฅผ ์ œ์ถœํ•˜์‹ญ์‹œ์˜ค: https://github.com/dmitriyse/ClrCoder/issues
๊ทธ๊ฒƒ์ด ์กฐ๊ธˆ ๋Œ€์ค‘ํ™”๋œ๋‹ค๋ฉด(์•„๋งˆ๋„ ๋ช‡ ์ฐจ๋ก€์˜ ๊ฐœ์„  ํ›„์—) CoreFX ํŒ€์— ์ด ๊ฐœ์„  ์‚ฌํ•ญ์„ ์ œ์•ˆํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

@terrajobst ๊ธฐ์กด ํด๋ž˜์Šค๊ฐ€ ์ƒˆ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐ ์ ํ•ฉํ•ฉ๋‹ˆ๊นŒ?

@safern List<T> ์— IReadOnly ์ถ”๊ฐ€๋˜๋Š” ์„ ๋ก€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ ‡๋‹ค๋ฉด ๋‹ค์Œ .NET Framework ๋ฆด๋ฆฌ์Šค์— ์ถ”๊ฐ€ํ•  ๊ณ„ํš์ž…๋‹ˆ๊นŒ?

์ด ์ž‘ํ’ˆ์€ ์–ธ์ œ ์ƒ๋ฅ™ํ•˜๋‚˜์š”? ํƒ€์ž„๋ผ์ธ์ด ์žˆ๋‚˜์š”?

https://www.nuget.org/packages/System.Collections.Immutable/
๋ถˆ๋ณ€ ์ปฌ๋ ‰์…˜์˜ ์ „์ฒด ์„ธํŠธ)

์ข‹์•„์š”. ์ด๊ฒƒ์€ ๋„ˆ๋ฌด ์˜ค๋žซ๋™์•ˆ ์—ฌ๊ธฐ์— ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. ๋‚˜๋Š” ๊ทธ๊ฒƒ์ด ๋งค์šฐ ํ•„์š”ํ•˜๋ฉฐ ์ด์— ๋Œ€ํ•œ ์ ‘๊ทผ ๋ฐฉ๋ฒ•์„ ์ œ์•ˆํ•˜๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค.

์ด ๋ชจ๋“  ๊ฒƒ์„ ๋…ธ์ถœํ•˜๋Š” ๋Œ€์‹ :

IEqualityComparer<T> Comparer { get; }
bool IsProperSubsetOf(IEnumerable<T> other);
bool IsProperSupersetOf(IEnumerable<T> other);
bool IsSubsetOf(IEnumerable<T> other);
bool IsSupersetOf(IEnumerable<T> other);
bool Overlaps(IEnumerable<T> other);
bool SetEquals(IEnumerable<T> other);

๊ณ ๊ฐ์ด ์ด๋Ÿฌํ•œ ๊ตฌ์„ฑ์›์„ ๊ตฌํ˜„ํ•˜๋„๋ก ํ•˜๋ ค๋ฉด ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ฒƒ์„ ์ถ”๊ฐ€ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

public interface IReadOnlySet<out T> : IReadOnlyCollection<T>
{
    bool Contains<T>(T item);
}

๊ทธ๋ฆฌ๊ณ  ๋” ์ด์ƒ ์•„๋ฌด๊ฒƒ๋„. ์ด๋Ÿฌํ•œ ํ•„์š”๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ๋” ๋งŽ์€ API๊ฐ€ ํ–ฅํ›„์— ํ•ญ์ƒ ์ถ”๊ฐ€๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ œ๊ฑฐํ•  ์ˆ˜ ์—†์œผ๋ฏ€๋กœ ์ด ์ œ์•ˆ.

๊ทธ๋Ÿฐ ๋‹ค์Œ ์ด ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ISet<T> ํ™•์žฅ๋œ ์ธํ„ฐํŽ˜์ด์Šค ๋ชฉ๋ก์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

๋ฌธ์„œ์—์„œ

ISet<T> : ์ด ์ธํ„ฐํŽ˜์ด์Šค๋Š” ๊ณ ์œ ํ•œ ์š”์†Œ์™€ ํŠน์ • ์ž‘์—…์ด ์žˆ๋Š” ์ปฌ๋ ‰์…˜์ธ ์ง‘ํ•ฉ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ๋ฉ”์„œ๋“œ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ํ•ด์‹œ์…‹๋ฐ SortedSet์ปฌ๋ ‰์…˜์€ ์ด ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.

์ฝ”๋“œ์—์„œ

ISet<T> ์ธํ„ฐํŽ˜์ด์Šค์—๋Š” ์ด๋ฏธ ICollection<T> ๋ฅผ ํ†ตํ•ด ์ •์˜๋œ bool Contains<T>(T item); ๋ฉ”์„œ๋“œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. int Count { get; } ๋ฅผ ํ†ตํ•ด ICollection<T> ์žˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ ‡๊ฒŒ ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค :

public interface ISet<T> : ICollection<T>, IEnumerable<T>, IEnumerable, IReadOnlySet<T>

์‚ฌ์†Œํ•œ ๋ณ€๊ฒฝ, ๋…ผ์˜ํ•  ์‚ฌํ•ญ์ด ๊ฑฐ์˜ ์—†๊ณ  ํฐ ์ด์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•˜๋„๋ก ํ•ฉ์‹œ๋‹ค. ๊ทธ๋Ÿฌํ•œ ํ’€ ์š”์ฒญ์ด ์ˆ˜๋ฝ๋˜๊ณ  ๋ณ‘ํ•ฉ๋˜๋Š”์ง€ ์•Œ๋ ค์ฃผ์„ธ์š”. ๊ทธ๋Ÿฌ๋ฉด ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

@karelz @terrajobst @safern @ianhays

์ฝ๊ธฐ ์ „์šฉ ์ง‘ํ•ฉ ์ž‘์—…์— ์‚ฌ์ „์˜ ํ‚ค ์ปฌ๋ ‰์…˜์„ ์‚ฌ์šฉํ•˜๋ ค๋Š” ์‹ค์ œ ๋ฌธ์ œ์— ๋Œ€ํ•ด ์ž‘์—…ํ•  ๋•Œ ์ด ํ† ๋ก ์„ ์ฐพ์•˜์Šต๋‹ˆ๋‹ค. ์ด ๊ฒฝ์šฐ๋ฅผ ์ง€์›ํ•˜๊ธฐ ์œ„ํ•ด ์ œ๊ฐ€ ์ œ์•ˆํ•˜๋Š” API๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋ก ์  ํ•ด์„

์ œ์•ˆ๋œ API

 namespace System.Collections.Generic {
+    public interface IReadOnlySet<out T> : IReadOnlyCollection<T>, IEnumerable, IEnumerable<T> {
+        bool Contains(T value);
+        bool IsProperSubsetOf(IEnumerable<T> other);
+        bool IsProperSupersetOf(IEnumerable<T> other);
+        bool IsSubsetOf(IEnumerable<T> other);
+        bool IsSupersetOf(IEnumerable<T> other);
+        bool Overlaps(IEnumerable<T> other);
+        bool SetEquals(IEnumerable<T> other);
+    }
-    public class HashSet<T> : ICollection<T>, IDeserializationCallback, IEnumerable, IEnumerable<T>, IReadOnlyCollection<T>, ISerializable, ISet<T> {
+    public class HashSet<T> : ICollection<T>, IDeserializationCallback, IEnumerable, IEnumerable<T>, IReadOnlyCollection<T>, ISerializable, ISet<T>, IReadOnlySet<T> {
     }
-    public class SortedSet<T> : ICollection, ICollection<T>, IDeserializationCallback, IEnumerable, IEnumerable<T>, IReadOnlyCollection<T>, ISerializable, ISet<T> {
+    public class SortedSet<T> : ICollection, ICollection<T>, IDeserializationCallback, IEnumerable, IEnumerable<T>, IReadOnlyCollection<T>, ISerializable, ISet<T>, IReadOnlySet<T> {
     }
+    public class ReadOnlySet<T> : ICollection<T>, IEnumerable, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlySet<T>, ISet<T> {
+        public int Count { get; }
+        public ReadOnlySet(ISet<T> set);
+        public bool Contains(T value);
+        public bool IsProperSubsetOf(IEnumerable<T> other);
+        public bool IsProperSupersetOf(IEnumerable<T> other);
+        public bool IsSubsetOf(IEnumerable<T> other);
+        public bool IsSupersetOf(IEnumerable<T> other);
+        public bool Overlaps(IEnumerable<T> other);
+        public bool SetEquals(IEnumerable<T> other);
+    }
     public class Dictionary<TKey, TValue> {
-        public sealed class KeyCollection : ICollection, ICollection<TKey>, IEnumerable, IEnumerable<TKey>, IReadOnlyCollection<TKey> {
+        public sealed class KeyCollection : ICollection, ICollection<TKey>, IEnumerable, IEnumerable<TKey>, IReadOnlyCollection<TKey>, IReadOnlySet<TKey> {
+            public bool IsProperSubsetOf(IEnumerable<TKey> other);
+            public bool IsProperSupersetOf(IEnumerable<TKey> other);
+            public bool IsSubsetOf(IEnumerable<TKey> other);
+            public bool IsSupersetOf(IEnumerable<TKey> other);
+            public bool Overlaps(IEnumerable<TKey> other);
+            public bool SetEquals(IEnumerable<TKey> other);
         }
     }
 }

์—ด๋ฆฐ ์งˆ๋ฌธ

  • ์ผ๋ฐ˜์ ์œผ๋กœ ์ธ์Šคํ„ด์Šคํ™”๋˜๋Š” ์ œ๋„ค๋ฆญ ์œ ํ˜•์— ๋Œ€ํ•œ ์ฝ”๋“œ ํฌ๊ธฐ ๋น„์šฉ์„ ๊ฐ์•ˆํ•  ๋•Œ ์ด๋Ÿฌํ•œ ๋ฉ”์„œ๋“œ๋ฅผ Dictionary<TKey, TValue>.KeyCollection ํ—ˆ์šฉ๋ฉ๋‹ˆ๊นŒ? ์—ฌ๊ธฐ๋ฅผ ์ฐธ์กฐ
  • ํ•ด์•ผ IReadOnlySet<T> ๋‹ค๋ฅธ ๊ตฌํ˜„ ๋  Dictionary KeyCollection ๋“ฑ์˜ SortedDictionary ๋˜๋Š” ImmutableDictionary ?

์—…๋ฐ์ดํŠธ

  • ์ œ๊ฑฐ TryGetValue ๊ทธ๋ ‡์ง€์—์„œ์˜๋กœ ISet<T> ๊ฐ€๋Šฅ์„ฑ์ด ๊ทธ ์–ด๋Š ๋ฆฌ๋ฒ ์ด์Šค ๋ฐฉ์ง€ ํ•  ์ˆ˜์™€ ๊ฐ™์€ ISet<T> ๊ตฌํ˜„ํ•˜๊ธฐ IReadOnlySet<T> .
  • ์ถ”๊ฐ€ ReadOnlySet<T> ์œ ์‚ฌํ•˜๋‹ค ํด๋ž˜์Šค ReadOnlyCollection<T> .

@TylerBrinkley ์Šค๋ ˆ๋“œ์— API ์ œ์•ˆ์„ ์ถ”๊ฐ€ํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๊ทผ๊ฑฐ์™€ ์‚ฌ์šฉ ์‚ฌ๋ก€๋ฅผ ์ถ”๊ฐ€ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ? ๊ฒ€ํ† ํ•  ์ค€๋น„๊ฐ€ ๋œ ๊ฒƒ์œผ๋กœ ํ‘œ์‹œํ•˜๊ณ  API ์ „๋ฌธ๊ฐ€๊ฐ€ ๊ฒฐ์ •ํ•˜๋„๋ก ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?

@TylerBrinkley ๋Š” ์ƒํ˜ธ ์ž‘์šฉ. ํ˜„์žฌ CoreFX์˜ ์‚ฌ์ „ ์„ธํŠธ์—์„œ ๋ˆ„๋ฝ๋˜์—ˆ์ง€๋งŒ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.

@dmitriyse getter๋Š” IEqualityComparer<T> ์†์„ฑ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ? ๊ทธ๊ฒƒ์œผ๋กœ ๋ฌด์—‡์„ ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?

์‚ฌ์ „ ๋ฐ ์ง‘ํ•ฉ์€ ์˜ฌ๋ฐ”๋ฅธ ์ปฌ๋ ‰์…˜ ๋ณต์ œ๋ฅผ ํ—ˆ์šฉํ•˜๊ธฐ ์œ„ํ•ด EqualityComparers๋ฅผ ๋ณด๊ณ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
๋ถˆํ–‰ํžˆ๋„ ์ด ๋ฌธ์ œ๊ฐ€ ๋…ผ์˜๋œ ๊ณณ์„ ์žŠ์–ด๋ฒ„๋ ธ์Šต๋‹ˆ๋‹ค.

ํด๋กœ๋‹์„ ํ•˜๋ฉด ์ฝ˜ํฌ๋ฆฌํŠธ ํƒ€์ž…์œผ๋กœ ์ž‘์—…ํ•˜์ง€ ์•Š์„๊นŒ์š”? ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ IEqualityComparer<T> ๋ฅผ ์ง€์›ํ•ด์•ผ ํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

์˜ˆ๋ฅผ ๋“ค์–ด ๋ฌธ์ž์—ด๊ณผ ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š๋Š” ํ‰๋“ฑ ๋น„๊ต์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ค์ •ํ•œ ๊ฒฝ์šฐ ์˜ฌ๋ฐ”๋ฅธ EqualityComparer๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š๊ณ  ์ƒˆ HashSet์„ ๋งŒ๋“ค ๋•Œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ์ง€์ •๋œ ์ง‘ํ•ฉ์—์„œ ์–ด๋–ค EqualityComparer๊ฐ€ ์‚ฌ์šฉ๋˜์—ˆ๋Š”์ง€ ์•Œ ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹จ์ˆœํ•œ ๋ณต์ œ๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. ํ›จ์”ฌ ๋” ์ผ๋ฐ˜์ ์ธ ์‹œ๋‚˜๋ฆฌ์˜ค๋Š” ๋‘ ์„ธํŠธ๋ฅผ ๋น„๊ตํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. Contains๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ตœ์ ์˜ ๋น„๊ต๋ฅผ ๊ตฌํ˜„ํ•˜๋ ค๋ฉด ๋‘˜ ๋‹ค ๋™์ผํ•œ ๋น„๊ต์ž๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด ์Šค๋ ˆ๋“œ์— ์˜ˆ๊ฐ€ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

์ฆ‰, IReadOnlySet์„ ์•„์˜ˆ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ๋ณด๋‹ค Contains ๋ฉ”์„œ๋“œ๋งŒ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. Set ๋น„๊ต๋ฅผ ์ผ๋ฐ˜์ ์œผ๋กœ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์œผ๋ฉด ์ข‹๊ฒ ์ง€๋งŒ Set์— ๋Œ€ํ•œ ์ฝ๊ธฐ ์ „์šฉ ์ฐธ์กฐ๊ฐ€ ํ•„์š”ํ•œ ๋งŒํผ ์ผ๋ฐ˜์ ์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

iOS์šฉ Outlook ๋‹ค์šด๋กœ๋“œ https://aka.ms/o0ukef


๋ณด๋‚ธ ์‚ฌ๋žŒ: Tyler Brinkley [email protected]
๋ณด๋‚ธ ๋‚ ์งœ: 2018๋…„ 5์›” 10์ผ ๋ชฉ์š”์ผ ์˜ค์ „ 6:21:52
๋ฐ›๋Š” ์‚ฌ๋žŒ: dotnet/corefx
์ฐธ์กฐ: ์•„๋ก  ๋งˆ์ด์–ด์Šค; ์–ธ๊ธ‰ํ•˜๋‹ค
์ œ๋ชฉ: Re: [dotnet/corefx] IReadOnlySet ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  HashSet, SortedSet์ด ๊ตฌํ˜„ํ•˜๋„๋ก ํ•˜์‹ญ์‹œ์˜ค(#1973).

ํด๋กœ๋‹์„ ํ•˜๋ฉด ์ฝ˜ํฌ๋ฆฌํŠธ ํƒ€์ž…์œผ๋กœ ์ž‘์—…ํ•˜์ง€ ์•Š์„๊นŒ์š”? ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ IEqualityComparer๋ฅผ ์ง€์›ํ•ด์•ผ ํ•˜๋Š” ์ด์œ .

โ€”
๋‹น์‹ ์ด ์–ธ๊ธ‰๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ฒƒ์„ ๋ฐ›๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
์ด ์ด๋ฉ”์ผ์— ์ง์ ‘ ๋‹ต์žฅํ•˜๊ณ  GitHub https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdotnet%2Fcorefx%2Fissues%2F1973%23issuecomment-388051258&data=02์—์„œ ํ™•์ธํ•˜์„ธ์š”. 7C01 7C % % % % 7Cc45ea16cd3034ddd69d808d5b678ff33 7C84df9e7fe9f640afb435aaaaaaaaaaaa % 7C1 % 7C0 % 7C636615553141417289 ๋ฐ SDATA = xRI27JtyaAwnZ2anY05oTlxmPY5AaGVl 2BRdXK2uR0 % % % 2F8 ๋ฐ 3D = 0 ์˜ˆ์•ฝ ๋˜๋Š” ์‹ค์„ ์†Œ๊ฑฐ https://eur01.safelinks.protection.outlook.com/?url=https%3A% 2F % 2Fgithub.com % 2Fnotifications % 2Funsubscribe-% 2FAMuQLmqboBWyHweWHSUoE1YM2OrfHZZxks5txD7wgaJpZM4E9KK- ์ธ์ฆ ๋ฐ ๋ฐ์ดํ„ฐ = 02% 7C01 % 7C % 7Cc45ea16cd3034ddd69d808d5b678ff33 % 7C84df9e7fe9f640afb435aaaaaaaaaaaa % 7C1 % 7C0 % 7C636615553141417289 ๋ฐ SDATA = hLtAXEyFNVEgWike6tMwAfUVC % 2BucyjXUDwoLOLDV5gk % ๋ฐ 3D = 0 ์˜ˆ์•ฝ .

๋™์˜ํ•ฉ๋‹ˆ๋‹ค. ์ง‘ํ•ฉ์—์„œ ์ฐพ์„ ์ˆ˜ ์žˆ๋Š” ์ค‘๋ณต ์œ ํ˜•(๋Œ€์†Œ๋ฌธ์ž ๊ตฌ๋ถ„, ๋Œ€์†Œ๋ฌธ์ž ๊ตฌ๋ถ„ ๋“ฑ)์„ ์•Œ ์ˆ˜ ์žˆ๋Š” ์œ ์ผํ•œ ๋ฐฉ๋ฒ•์€ ๋น„๊ต์ž๋ฅผ ๋…ธ์ถœํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

Dictionary<TKey, TValue>.KeyCollection ์ด๋Ÿฌํ•œ ๋ชจ๋“  ๋ฐฉ๋ฒ•์„ ์ถ”๊ฐ€ํ•˜๋ฉด ์ƒ๋‹นํ•œ ์ฝ”๋“œ ํฌ๊ธฐ ๋น„์šฉ์ด ๋ฐœ์ƒํ•˜๋ฏ€๋กœ ๋‚ด ์ œ์•ˆ์ด ๋ฐ›์•„๋“ค์—ฌ์ง€์ง€ ์•Š์„ ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๊ธฐ ์‹œ์ž‘ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ์ธ์Šคํ„ด์Šคํ™”๋˜๋Š” ์ œ๋„ค๋ฆญ ์œ ํ˜•์— ์ƒˆ API๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์ด

๋‚˜๋Š” ๋‹น์‹ ์ด IReadOnlySet ์— ๋น„๊ต์ž๋ฅผ ๋‘˜ ์ˆ˜ ์—†์„ ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

SortedSet ๋Š” IComparer ๋ฅผ ๋ฐ›๋Š” ๋ฐ˜๋ฉด HashSet ๋Š” IEqualityComparer ๋ฐ›์Šต๋‹ˆ๋‹ค.

์ข‹์€ ์ , ๋น„๊ต์ž๋Š” ์ผ๋ฐ˜ ์ธํ„ฐํŽ˜์ด์Šค์— ์†ํ•˜์ง€ ์•Š๋Š” ๊ตฌํ˜„ ์„ธ๋ถ€ ์‚ฌํ•ญ์œผ๋กœ ๊ฐ„์ฃผ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

iOS์šฉ Outlook ๋‹ค์šด๋กœ๋“œ https://aka.ms/o0ukef


๋ณด๋‚ธ ์‚ฌ๋žŒ: Cory Nelson [email protected]
๋ณด๋‚ธ ๋‚ ์งœ: 2018๋…„ 5์›” 10์ผ ๋ชฉ์š”์ผ ์˜คํ›„ 5:04:06
๋ฐ›๋Š” ์‚ฌ๋žŒ: dotnet/corefx
์ฐธ์กฐ: ์•„๋ก  ๋งˆ์ด์–ด์Šค; ์–ธ๊ธ‰ํ•˜๋‹ค
์ œ๋ชฉ: Re: [dotnet/corefx] IReadOnlySet ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  HashSet, SortedSet์ด ๊ตฌํ˜„ํ•˜๋„๋ก ํ•˜์‹ญ์‹œ์˜ค(#1973).

๋‚˜๋Š” ๋‹น์‹ ์ด IReadOnlySet์— ๋น„๊ต์ž๋ฅผ ๋‘˜ ์ˆ˜ ์žˆ์„ ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

SortedSet์€ IComparer๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  HashSet์€ IEqualityComparer๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

โ€”
๋‹น์‹ ์ด ์–ธ๊ธ‰๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ฒƒ์„ ๋ฐ›๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
์ด ์ด๋ฉ”์ผ์— ์ง์ ‘ ๋‹ต์žฅํ•˜๊ณ  GitHub https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdotnet%2Fcorefx%2Fissues%2F1973%23issuecomment-388221165&data=02์—์„œ ํ™•์ธํ•˜์„ธ์š”. 7C01 7C % % % % 7C0ef6d84125be4c450fdc08d5b6d2b70a 7C84df9e7fe9f640afb435aaaaaaaaaaaa % 7C1 % 7C0 % 7C636615938478979295 ๋ฐ SDATA = PHkDQPiJBEIks8yNyIA7vKODM % 2BkMFI4PRX4lUUBu % 2Bi0 % ๋ฐ 3D = 0 ์˜ˆ์•ฝ ๋˜๋Š” ์‹ค์„ ์†Œ๊ฑฐ https://eur02.safelinks.protection.outlook.com/?url=https%3A% 2F % 2Fgithub.com % 2Fnotifications % 2Funsubscribe-% 2FAMuQLu5JGLcqrpMyGWLygbCsaSQSXFgNks5txNV2gaJpZM4E9KK- ์ธ์ฆ ๋ฐ ๋ฐ์ดํ„ฐ = 02ํผ์„ผํŠธ 7C01 % 7C % 7C0ef6d84125be4c450fdc08d5b6d2b70a % 7C84df9e7fe9f640afb435aaaaaaaaaaaa % 7C1 % 7C0 % 7C636615938478979295 ๋ฐ SDATA = 9pnuMULuDu9HWb7un % 2FWYq6iYdjTKFsjN7nKiToaeHkk % ๋ฐ 3D = 0 ์˜ˆ์•ฝ .

IUnorderedSet ๋ฐ IOrderedSet ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐ ์•ฝ๊ฐ„์˜ ๊ฐ€์น˜๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ์ง€๋งŒ IReadOnlySet ๋ฅผ ๋ฐ€์–ด์„œ ํƒˆ์„ ํ•˜๋Š” ๊ฒƒ์„ ์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

@pgolebiowski ์˜ ์ œ์•ˆ์ด ๋งˆ์Œ์—

c# public interface ISetCharacteristic<in T> { bool Contains(T item); }

๊ทธ๋Ÿฌ๋ฉด ๊ฐ„๊ฒฉ(์‹ค์ˆ˜)๊ณผ ๊ฐ™์€ ์…€ ์ˆ˜ ์—†๋Š” ์ง‘ํ•ฉ์—๋„ ์ ํ•ฉํ•ฉ๋‹ˆ๋‹ค. ๊ทธ์™€ IReadOnlySet ์‚ฌ์ด์—์„œ ICountableSet (์ผ๋ช… IEnumerableSet ), IUnorderedSet ๋ฐ IOrderedSet ์™€ ๊ฐ™์€ ๋ช‡ ๊ฐ€์ง€ ๋‹ค๋ฅธ ์ธํ„ฐํŽ˜์ด์Šค์— ์ž ์žฌ์ ์œผ๋กœ ์ ํ•ฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๋‚˜ IReadOnlySet ์žˆ์œผ๋ฉด ํ˜„์žฌ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๊ฒƒ๋ณด๋‹ค ํฌ๊ฒŒ ๊ฐœ์„ ๋  ๊ฒƒ์ด๋ผ๋Š” ๋ฐ ๋™์˜ํ•ฉ๋‹ˆ๋‹ค.

@NickRedwood์˜ ๊ฒฝ์šฐ +1

์˜คํ”ˆํ•œ์ง€ 3๋…„์ด ๋„˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ ‘๊ทผ ๋ฐฉ์‹์„ ๋ณ€๊ฒฝํ•˜์—ฌ ์ด๋ฅผ ์ˆ˜ํ–‰ํ•˜์‹ญ์‹œ์˜ค. @NickRedwood๊ฐ€ ์–ธ๊ธ‰ํ•œ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์†Œ๊ฐœํ•˜๋ฉด ์ด ์Šค๋ ˆ๋“œ์—์„œ ๋…ผ์˜ ์ค‘์ธ ๋‹ค๋ฅธ ๋ชจ๋“  ๊ฐœ์„  ์‚ฌํ•ญ์ด ํ—ˆ์šฉ๋ฉ๋‹ˆ๋‹ค. ๋ชจ๋“  ์ ‘๊ทผ ๋ฐฉ์‹์€ ์ด ์‚ฌ์†Œํ•œ ์ผ์— ๋Œ€ํ•ด ๋™์˜ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๊ธฐ๋ณธ์ ์ธ ์ด ๊ฐ„๋‹จํ•œ ์‚ฌํ•ญ์„ ์ถ”๊ฐ€ํ•œ ๋‹ค์Œ ๋ชจ๋‘ ์„ ํƒ ์‚ฌํ•ญ์ธ ์ž ์žฌ์ ์ธ ๊ฐœ์„  ์‚ฌํ•ญ์— ๋Œ€ํ•œ ๋˜ ๋‹ค๋ฅธ ๋ฌธ์ œ๋ฅผ ์ƒ์„ฑํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

@TylerBrinkley @safern @karelz @terrajobst

Contains ๋ฉ”์„œ๋“œ๋งŒ ์žˆ๋Š” IReadOnlySet<T> ์ธํ„ฐํŽ˜์ด์Šค์—๋Š” ๊ทธ๋‹ค์ง€ ๋งŽ์€ ์ด์ ์ด ์—†์Šต๋‹ˆ๋‹ค. ์ด ๋ฐฉ๋ฒ•์€ ์œ ์šฉํ•˜๋ฉด์„œ ์ด๋ฏธ์— ํฌํ•จ ICollection<T> ๋˜ํ•œ ๊ฐ–๋Š”๋‹ค ์ธํ„ฐํŽ˜์ด์Šค IsReadOnly ๋“ฑ๋กํ•˜๋Š” ๋‹จ๊ณ„์˜ ๋ณ€ํ˜• ๋ฐฉ์‹ ์—ฌ๋ถ€๋ฅผ ์ง€์ •ํ•˜๊ธฐ์œ„ํ•œ ICollection<T> ์ง€์›๋œ๋‹ค. ICollection<T> ๊ตฌํ˜„ํ•˜๊ณ  IsReadOnly return true . ์ง€์›ํ•  ๊ฒƒ์œผ๋กœ ์˜ˆ์ƒ๋˜๋Š” ์œ ์ผํ•œ ๋‹ค๋ฅธ ๊ธฐ๋Šฅ์€ ์—ด๊ฑฐ ๊ฐ€๋Šฅํ•œ Count ์†์„ฑ๊ณผ ๋„ˆ๋ฌด ์ œํ•œ์ ์œผ๋กœ ๋ณด์ด์ง€ ์•Š๋Š” CopyTo ๋ฉ”์„œ๋“œ์ž…๋‹ˆ๋‹ค.

์ œ์•ˆ๋œ IReadOnlySet<T> ๊ฐ€ IReadOnlyCollection<T> ๊ธฐ๋ฐ˜์œผ๋กœ ๊ตฌํ˜„๋œ๋‹ค๋ฉด ๋งค์šฐ ๊ธฐ์  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ํ˜„์žฌ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๊ฒƒ์— ๋Œ€ํ•œ ํฐ ๊ฐœ์„ ์ด ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค. (@TylerBrinkley์€ - ๋‹น์‹ ์ด ์˜๋ฏธ ๊ฐ€์ • IReadOnlyCollection<T> ๋Œ€์‹  ICollection<T> .

๋” ๊ธฐ๋ณธ์ ์ธ ์ธํ„ฐํŽ˜์ด์Šค์— ์˜ค๋ฅ˜๊ฐ€ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. Set์— ๋Œ€ํ•œ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ์žˆ๋‹ค๋ฉด Contains ๋ฉ”์†Œ๋“œ๊ฐ€ ์žˆ๋Š” ๋‹จ์ผ ๋ฉ”์†Œ๋“œ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๊ทธ๊ฒƒ์€ ์ข‹์€ ์ˆ˜ํ•™์  ๊ธฐ์ดˆ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉฐ ๋งค์šฐ ๊นจ๋—ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๊ธฐ์กด ํด๋ž˜์Šค๋กœ ๊ฐœ์กฐํ•  ๋•Œ๋Š” ๊ฐœ์กฐ๋ฅผ ๋œ ํ•˜๋Š” ๊ฒƒ์ด ๋” ๋‚ซ๋‹ค๋Š” ๊ฒƒ์„ ์ธ์ •ํ•˜๋ฉฐ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ํ•˜๋‚˜๋งŒ ๊ฐœ์กฐ๋˜์–ด์•ผ ํ•œ๋‹ค๋ฉด IReadOnlySet<T> ๊ธฐ๋ฐ˜ IReadOnlyCollection<T> ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

IReadOnlyCollection<> ์—๋Š” .Contains IReadOnlyCollection<> ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ๊ณต๋ณ€์ด ๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

์ข‹์€ ์ง€์ ์ด๋ฉฐ ์ด์ „ ๊ฒŒ์‹œ๋ฌผ์„ ๋ฐ˜๊ณต๋ณ€์œผ๋กœ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ์Šค๋ ˆ๋“œ์˜ ์ดˆ๊ธฐ์— ๊ฒŒ์‹œ๋œ ์ ‘๊ทผ ๋ฐฉ์‹์ด ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ํ•œ IReadOnlySet<T> ๋Š” ๋ถˆ๋ณ€ํ•ด์•ผ ํ•˜๋ฉฐ ์ด์— ๋Œ€ํ•ด ํ™•์‹ ์ด ์„œ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

@TylerBrinkley ๊ฐœ์ธ์ ์œผ๋กœ ์ €๋Š” IsReadOnly ์†์„ฑ์˜ ํŒฌ์ด ์•„๋‹ˆ๋ฏ€๋กœ ๋Ÿฐํƒ€์ž„ ๋Œ€์‹  ์ปดํŒŒ์ผ ํƒ€์ž„์— ์ด ์ •๋ณด๋ฅผ ์•Œ๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค. IReadOnlyCollection<T> ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๊ฒฝ์šฐ ํ˜ธ์ถœ์ž ๋˜๋Š” ์ˆ˜์‹ ์ž๊ฐ€ ์ปฌ๋ ‰์…˜์„ ํ†ตํ•œ ์ž ์žฌ์  ๋ฐ˜๋ณต ๋Œ€์‹  ์กฐํšŒ๊ฐ€ ๋น ๋ฅด๋‹ค๋Š” ๊ฒƒ์„ ์•„๋Š” ๊ฒƒ์ด ์—ฌ์ „ํžˆ ์œ ์šฉํ•  ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. "์„ธํŠธ"๋Š” ๊ทธ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

Contains ๋ฉ”์„œ๋“œ Set ๊ฐ€ ํ•ด์•ผ ํ•  ์ผ์„ ์ •์˜ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ Collection ๊ฐ€ ํ•ด์•ผ ํ•  ์ผ์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. ๋‚ด ๋ง์€ Contains ๋Š” ISet ์˜ ๊ตฌ์„ฑ์›๋„ ์•„๋‹ˆ์ง€๋งŒ ISet ์ƒ์†๋ฐ›์€ ICollection ์˜ ๊ตฌ์„ฑ์›์ž…๋‹ˆ๋‹ค. ISet ์˜ ๋‹ค๋ฅธ ๊ตฌ์„ฑ์›์€ Set ์ด ์ˆ˜ํ–‰ํ•ด์•ผ ํ•˜๋Š” ์ž‘์—…์„ ์ •์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋‚˜๋Š” ๋Œ€๋ถ€๋ถ„์˜ ์‚ฌ๋žŒ๋“ค์ด Contains ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ๋งŒ ์„ธํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์ดํ•ดํ•˜์ง€๋งŒ ์„ธํŠธ์—๋Š” ๊ทธ๊ฒƒ๋ณด๋‹ค ํ›จ์”ฌ ๋” ๋งŽ์€ ๊ฒƒ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

@TylerBrinkley ํ•˜์ง€๋งŒ ์ด ์‹œ์ ์—์„œ IReadOnlyCollection<T>.Contains(T) ๋ฅผ ์ •์˜ํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๊นŒ? ๋‚˜๋Š” ์•„๋‹ˆ๋ผ๊ณ  ๊ฐ€์ •ํ–ˆ๋‹ค. ์ด๊ฒƒ์ด ์œ ์ผํ•œ ์˜ต์…˜์ด IReadOnlySet<T> ๋ฅผ ๋„์ž…ํ•˜๊ณ  ๋„์ž…๋  ๋•Œ IReadOnlySet<T>.Contains(T) ๊ฐ€ ์„ ์–ธ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

@jnm2 ๋งํ•œ๋‹ค:

IReadOnlyCollection<> ์—๋Š” .Contains IReadOnlyCollection<> ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ์™œ๋ƒํ•˜๋ฉด ๊ทธ๋ ‡๊ฒŒ ํ•˜๋ฉด ๊ณต๋ณ€์ด ๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

์ด๊ฒƒ์ด ์ง€๊ธˆ ๋‚˜์—๊ฒŒ ๊ฐ€์žฅ ํฐ ๋ฌธ์ œ์ธ ๊ฒƒ ๊ฐ™๋‹ค. ํ™€์ˆ˜ ๊ฒƒ IReadOnlySet<T> ๋•Œ ๋ถˆ๋ณ€์œผ๋กœ IReadOnlyCollection<T> ๊ณต๋ณ€์ž…๋‹ˆ๋‹ค. ๊ธฐ์กด์˜ ๋งŽ์€ IReadOnly* ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ out T ๋กœ ์‹ ์ค‘ํ•˜๊ฒŒ ์„ค๊ณ„๋˜์—ˆ์œผ๋ฉฐ ์“ฐ๊ธฐ ๊ฐ€๋Šฅํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋Š” ๋ฐ˜๋“œ์‹œ ๋ถˆ๋ณ€์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์šฐ๋ฆฌ ๋Œ€๋ถ€๋ถ„์€ IReadOnlySet<T> ๊ฐ€ ์ตœ์†Œํ•œ Contains(T) ๋ฉ”์„œ๋“œ๋ฅผ ์„ ์–ธํ•˜๊ธฐ๋ฅผ ์›ํ•˜์ง€๋งŒ ๊ทธ๋ ‡๊ฒŒ ํ•˜๋ฉด ๊ณต๋ณ€์„ฑ์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ICollection ์ •๋ง Contains(T) ๋ฅผ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋Š” ์˜ฌ๋ฐ”๋ฅธ ์œ„์น˜๋ผ๋ฉด ๊ฐ€๋Šฅํ•œ๊ฐ€์š”? Collection<T> ๋ฐ HashSet<T> ์˜ํ•ด ๊ตฌํ˜„๋˜๊ณ  ๋ถˆ๋ณ€์ธ IReadOnlyProbableCollection<T>.Contains(T) ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ?

@NickRedwood์˜ ISetCharacteristic<T> ์ œ์•ˆ์ด ๋” ๊น”๋”ํ•ด ๋ณด์ž…๋‹ˆ๋‹ค. ์‹ฌ์ง€์–ด ์œ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” Count ๋ฅผ ๊ตฌํ˜„ํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค๋Š” ์ด์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฐœ์ธ์ ์œผ๋กœ ์ €๋Š” IsReadOnly ์†์„ฑ์˜ ํŒฌ์ด ์•„๋‹ˆ๋ฏ€๋กœ ๋Ÿฐํƒ€์ž„ ๋Œ€์‹  ์ปดํŒŒ์ผ ํƒ€์ž„์— ์ด ์ •๋ณด๋ฅผ ์•Œ๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค.

๊ทธ ์‚ฌ๋žŒ์€ ๋ง์„ ์ž˜ํ•˜๋‹ˆ ํฌ๋„์ฃผ๋ฅผ ๋” ๋ถ€์–ด ์ฃผ์‹ญ์‹œ์˜ค.

@binki IReadOnlyCollection<T> ๊ฐ€ ํฌํ•จ๋˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— IReadOnlySet<T> ์— Contains ๋ฉ”์„œ๋“œ๊ฐ€ ์žˆ์–ด์•ผ ํ•œ๋‹ค๋Š” ๋ฐ ๋™์˜ํ•˜์ง€๋งŒ ๋‹ค๋ฅธ ๋ชจ๋“  ๋น„ ๋Œ์—ฐ๋ณ€์ด ISet<T> ๋„ ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค

์œ„์—์„œ ์–ธ๊ธ‰ํ•œ Dictionary.KeyCollection ์‚ฌ์šฉ ์‚ฌ๋ก€ ์™ธ์— ์ด ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ถ”๊ฐ€ํ•˜๊ธฐ ์œ„ํ•ด ์–ด๋–ค ๋‹ค๋ฅธ ์‚ฌ์šฉ ์‚ฌ๋ก€๋ฅผ ์ƒ๊ฐํ•ด๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ?

์ข‹์Šต๋‹ˆ๋‹ค. API ๋””์ž์ธ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

public interface IReadOnlySet<T> : IReadOnlyCollection<T> {    
    bool Contains(T item);
}

๋ชจ๋‘๊ฐ€ ๋™์˜ํ•  ์ˆ˜ ์žˆ๋Š” ๋””์ž์ธ์˜ ์œ ์ผํ•œ ๊ณตํ†ต ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค.

์ด์ œ ์—ฌ๊ธฐ์„œ ๋””์ž์ธ์„ ๋งˆ์น˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์•ž์œผ๋กœ ์—ฐ์žฅํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ๋‹ค๋ฅธ ํ˜ธ์—์„œ ํ•˜์„ธ์š”. ์ด๊ฒƒ์€ ์ œํ’ˆ์— ์žˆ์–ด์•ผ ํ•˜๋Š” ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค.

๋ˆ„๊ตฌ๋ฅผ ์œ„ํ•œ ๊ฒƒ์ธ๊ฐ€, ๋ˆ„๊ตฌ๋ฅผ ๋ฐ˜๋Œ€ํ•˜๋Š” ๊ฒƒ์ธ๊ฐ€?

@ashmind ์˜ ์ œ์•ˆ์ด ๋งˆ์Œ์— ๋“ญ๋‹ˆ๋‹ค . Dictionary.Keys๊ฐ€ ๊ธฐ์ˆ ์ ์œผ๋กœ IReadOnlySet<TKey> ์ธ ์ด ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉด ์ •๋ง ์ข‹์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์ด๊ฒƒ์„ api-ready-for-review ๋กœ ํ‘œ์‹œํ•ด ์ฃผ์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ? ๋‚˜๋Š” ์ด ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ๋‹ค์‹œ ํ•„์š”ํ•˜๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ ๋˜์—ˆ๊ณ  ์—ฌ์ „ํžˆ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์ด๊ฒƒ์ด ์•„์ง ๊ตฌํ˜„๋˜์ง€ ์•Š์€ ์ด์œ ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

[ํŽธ์ง‘] ์‚ฌ๊ณผ - ๋‚ด ์›๋ž˜ ์‘๋‹ต์ด ๋‹ค๋ฅธ API์™€ ํ˜ผ๋™๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋‚˜๋Š” ์ด๊ฒƒ์— ๋Œ€ํ•ด ๊ฐ•ํ•œ ์˜๊ฒฌ์„ ๊ฐ€์ง€๊ณ  ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ…์ŠคํŠธ๊ฐ€ ํŽธ์ง‘๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ํ˜ผ๋ž€์„ ๋“œ๋ ค ์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค!

์ด๊ฒƒ์ด ์•„์ง ๊ตฌํ˜„๋˜์ง€ ์•Š์€ ์ด์œ ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

API๋Š” ์•„์ง ์˜์—ญ ์†Œ์œ ์ž์˜ ๊ด€์‹ฌ์„ ๋ฐ›์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค - @safern. ์ปฌ๋ ‰์…˜ ์šฐ์„  ์ˆœ์œ„ ๋ชฉ๋ก์—์„œ ์–ผ๋งˆ๋‚˜ ๋†’์€์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ง€์ง€์œจ์ด ์ƒ๋‹นํžˆ ๋†’์Šต๋‹ˆ๋‹ค.
์ง„์‹ค์€ ํ˜„์žฌ .NET Core 3.0์„ ์ž ๊ทธ๊ณ  ์žˆ์œผ๋ฏ€๋กœ 3.0์—์„œ๋Š” ์ค‘์š”ํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ์ตœ์†Œํ•œ ๋‹ค์Œ ๋ฆด๋ฆฌ์Šค๋ฅผ ๊ธฐ๋‹ค๋ ค์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์ด๊ฒƒ์ด ๊ธฐ๋ณธ ์ œ๊ณต๋˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฒƒ๋„ ๋†€๋ž์Šต๋‹ˆ๋‹ค.

๋ถˆ๋ณ€ ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ๋Š” ์ฝ”๋“œ ์œ ์ง€ ๊ด€๋ฆฌ๋ฅผ ๊ฐœ์„ ํ•˜๋Š” ๋ฐ ํฐ ๋„์›€์ด ๋  ์ˆ˜ ์žˆ์ง€๋งŒ ์˜๋ฏธ ์ฒด๊ณ„๋ฅผ ์ง€์ •ํ•˜๊ณ  ์„œ๋กœ ๋‹ค๋ฅธ ๊ตฌํ˜„์ด ํ•จ๊ป˜ ์ž‘๋™ํ•˜๋„๋ก ํ•˜๋Š” ํ‘œ์ค€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ธํ„ฐํŽ˜์ด์Šค ์—†์ด๋Š” ์‚ฌ์šฉํ•˜๊ธฐ ์–ด๋ ต์Šต๋‹ˆ๋‹ค.

์ด๊ฒƒ์ด ์—†์œผ๋ฉด ๋ถˆ๋ณ€ ์ง‘ํ•ฉ์„ ๋งค๊ฐœ๋ณ€์ˆ˜/๋ฐ˜ํ™˜ ๊ฐ’์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•˜๋Š” ๊ฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋œ ํšจ์œจ์ ์ด๊ณ  ์˜๋ฏธ๋ก ์ ์œผ๋กœ ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์€ IEnumerable์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ์„œ๋ช…๊ณผ ํ˜ธํ™˜๋˜์ง€ ์•Š๋Š” ์ž์ฒด ์ธํ„ฐํŽ˜์ด์Šค/ํด๋ž˜์Šค๋ฅผ ์„œ๋ช…์— ์‚ฌ์šฉํ•˜๋Š” ๋ฐ ์˜์กดํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Contains ์กฐํšŒ ์ธก๋ฉด์—์„œ ํšจ์œจ์ ์ด๊ณ  ๋งค๊ฐœ๋ณ€์ˆ˜/๋ฐ˜ํ™˜ ๊ฐ’์˜ ๊ตฌ์ฒด์ ์ธ ์œ ํ˜•์„ ์ง€์ •ํ•˜์ง€ ์•Š๋Š” ์ด์— ๋Œ€ํ•œ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์ด ์žˆ๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค. ๋‚ด ๋จธ๋ฆฌ ๊ผญ๋Œ€๊ธฐ์—์„œ ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ์„ ์€ ์„œ๋ช…์—์„œ IEnumerable์„ ์‚ฌ์šฉํ•˜๊ณ  ReadOnlyDictionary.Keys๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๊ฒƒ์ด์ง€๋งŒ, ํŠนํžˆ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ๋Š” ์•ฝ๊ฐ„ ๋ถˆ์พŒํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. Linq์˜ Enumerable.Contains ๋Š” Contains ์˜ ์ปฌ๋ ‰์…˜ ๊ตฌํ˜„์„ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ ํ˜ธํ™˜๋˜๋Š” ๋™์•ˆ ํšจ์œจ์ ์ด์–ด์•ผ ํ•˜์ง€๋งŒ ์„ฑ๋Šฅ์ด ๋–จ์–ด์ง€๋Š” ๊ตฌํ˜„์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์˜๋„๋ฅผ ์ „๋‹ฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

@adamt06 ISet<T> ์ฐพ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

@scalablecory ๋‹น์‹ ์ด ์˜ณ์Šต๋‹ˆ๋‹ค. ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๋Š” ๊ตฌํ˜„์ด ์žˆ์œผ๋ฉฐ ImmutableHashSet<T>

ICollection์ด ์™œ ๊ทธ๋Ÿฐ์ง€ ์•Œ๊ณ /์ดํ•ดํ•˜๋Š” ์‚ฌ๋žŒ์ด ์žˆ์Šต๋‹ˆ๊นŒ?IReadOnlyCollection์„ ํ™•์žฅํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.??
๋‚˜๋Š” ์ด๊ฒƒ์ด ์ด ์Šค๋ ˆ๋“œ์™€ ์•ฝ๊ฐ„ ๊ด€๋ จ์ด ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ์ƒˆ ์Šค๋ ˆ๋“œ๋ฅผ ์—ฌ๋Š” ๋Œ€์‹ . ์–ด์ฉŒ๋ฉด ๋‚ด๊ฐ€ ๋ญ”๊ฐ€๋ฅผ ์˜คํ•ดํ•˜๊ณ  ์žˆ๋Š” ๊ฒƒ์ผ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

๋˜ ๋‹ค๋ฅธ ์ƒ๊ฐ์ด์ง€๋งŒ ์ฃผ์ œ์—์„œ ์™„์ „ํžˆ ๋ฒ—์–ด๋‚ฌ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ReaOnlyCollection์— ๋‹ค์Œ์ด ์—†๋Š” ์ด์œ ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

c# bool Contains(T item); void CopyTo(T[] array, int arrayIndex);

๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ๊นจ๋Š” ๊ฒƒ๊ณผ ๊ด€๋ จ์ด ์žˆ์ง€๋งŒ ์„ธ๋ถ€ ์‚ฌํ•ญ์€ ๊ธฐ์–ต๋‚˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

ReadOnlyCollection์—๋Š” ๋‹ค์Œ์ด ํฌํ•จ๋ฉ๋‹ˆ๋‹ค.
https://docs.microsoft.com/en-us/dotnet/api/system.collections.objectmodel.readonlycollection-1.contains
https://docs.microsoft.com/en-us/dotnet/api/system.collections.objectmodel.readonlycollection-1.copyto

์•„, IReadOnlyCollection์ด ๊ทธ๊ฒƒ๋“ค์„ ๊ฐ€์ง€๊ณ  ์žˆ์ง€ ์•Š๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ๊ณต๋ณ€ ํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

ํ™•์‹คํ•˜์ง€ ์•Š์ง€๋งŒ ๋ช…์‹œ์  ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌํ˜„๊ณผ ๊ด€๋ จ์ด ์žˆ์–ด ์ด์ „ ๋ฒ„์ „๊ณผ์˜ ํ˜ธํ™˜์„ฑ ๋ฌธ์ œ๋ฅผ ์ผ์œผํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์ธํ„ฐํŽ˜์ด์Šค์—์„œ ์ƒ์†ํ•˜๋„๋ก ๊ธฐ์กด ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๊ฒƒ์ด ๋ฌธ์ œ๊ฐ€ ๋˜๋Š” ์ด์œ ๋ฅผ ์•Œ ์ˆ˜ ์žˆ์ง€๋งŒ IReadOnlySet<T> ์ƒˆ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋งŒ๋“ค๊ณ  HashSet ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์ด ๋ฌธ์ œ๊ฐ€ ๋˜๋Š” ์ด์œ ๋ฅผ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค.

์ข‹์•„์š”. ํ•˜์ง€๋งŒ ์—ฌ์ „ํžˆ ICollection์ด ํ‘œ์‹œ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.ํ•ด์„œ๋Š” ์•ˆ๋œ๋‹ค:
c# ICollection<T> : IReadOnlyCollection<out T>
์ฝ๊ธฐ/์“ฐ๊ธฐ ์ปฌ๋ ‰์…˜์ด ์ฝ๊ธฐ ์ „์šฉ ์ปฌ๋ ‰์…˜์˜ ํ™•์žฅ์ด ๋˜์–ด์„œ๋Š” ์•ˆ ๋˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

@generik0

์ข‹์•„์š”. ๊ทธ๋Ÿฌ๋‚˜ ์—ฌ์ „ํžˆ ICollection์ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ‘œ์‹œ๋˜์ง€ ์•Š์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค.

ICollection<out T> : IReadOnlyCollection<out T>

์ฝ๊ธฐ/์“ฐ๊ธฐ ์ปฌ๋ ‰์…˜์ด ์ฝ๊ธฐ ์ „์šฉ ์ปฌ๋ ‰์…˜์˜ ํ™•์žฅ์ด ๋˜์–ด์„œ๋Š” ์•ˆ ๋˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

๋จผ์ € ICollection<T> ์—๋Š” .Add(T item) ๋ฉค๋ฒ„๊ฐ€ ์žˆ์œผ๋ฏ€๋กœ ICollection<out T> ๋ฅผ ์„ ์–ธํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

๋‘˜์งธ, ICollection<T> ๋Š” .net-2.0์— ํ‘œ์‹œ ๋˜๊ณ  IReadOnlyCollection<out T> ๋Š” .net-4.5์— ํ‘œ์‹œ ๋ฉ๋‹ˆ๋‹ค. ICollection<T> ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ปดํŒŒ์ผํ•œ ๋‹ค์Œ ICollection<T> ๊ฐ€ ์ƒˆ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๋„๋ก ๋ณ€๊ฒฝ๋˜๋ฉด ICollection<T> ๋งŒ ๊ตฌํ˜„ํ•˜๋Š” ๋ชจ๋“  ํ•ญ๋ชฉ์—๋Š” ํ•ด๋‹น ๋ฐ”์ด๋„ˆ๋ฆฌ๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์— ๊ธฐ์กด ์ปดํŒŒ์ผ๋œ ๋ฐ”์ด๋„ˆ๋ฆฌ๊ฐ€ ๋Ÿฐํƒ€์ž„์— ์ค‘๋‹จ๋ฉ๋‹ˆ๋‹ค. IReadOnlyCollection<T> ์Šฌ๋กฏ์€ ์ปดํŒŒ์ผ๋Ÿฌ์— ์˜ํ•ด (์ž๋™์œผ๋กœ) ์ฑ„์›Œ์ง‘๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ICollection<T> ๊ฐ€ IReadOnlyCollection<T> ๋ฅผ ๊ตฌํ˜„ํ•˜์ง€ ๋ชปํ•˜๊ฒŒ ํ•˜๋Š” ํ˜ธํ™˜์„ฑ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.

๋‚˜๋Š” ์ด๊ฒƒ์ด ์ด SO ๋‹ต๋ณ€์— ์˜ํ•ด ๋ช…ํ™•ํ•˜๊ฒŒ ํ•ด๊ฒฐ๋˜์—ˆ๋‹ค๊ณ  ์ƒ๊ฐํ•˜์ง€ ์•Š์ง€๋งŒ ์ด์— ๋Œ€ํ•œ SO๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค: https://stackoverflow.com/a/14944400 .

@binki " " ICollection์— ๊ณ ์ •, ์˜คํƒ€ ์ง€์ ํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค..
DotNetStandard ๋ฐ net461. ๊ทธ๋ฆฌ๊ณ  ์ด๊ฒƒ์ด ๋ณ€ํ™”๊ฐ€ ์žˆ์–ด์•ผ ํ•  ๊ณณ์ž…๋‹ˆ๋‹ค. ๋„ท์Šคํƒ ๋‹ค๋“œ 2+

๋ฐ˜๋ณตํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค...
์ฝ๊ธฐ/์“ฐ๊ธฐ ์ปฌ๋ ‰์…˜์ด ์ฝ๊ธฐ ์ „์šฉ ์ปฌ๋ ‰์…˜์˜ ํ™•์žฅ์ด ๋˜์–ด์„œ๋Š” ์•ˆ ๋˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

๊ทธ๋ฆฌ๊ณ  ๋œ ๋…ธ์ถœ์‹œํ‚ค๊ธฐ ์œ„ํ•ด ์˜ˆ๋ฅผ ๋“ค์–ด "ToArray()"๋กœ ์ปฌ๋ ‰์…˜์„ ์บ์ŠคํŒ…ํ•ด์•ผ ํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

๊ทธ๋ฆฌ๊ณ  ๋ฌธ์ œ๋ฅผ ์ผ์œผํ‚ค์ง€ ์•Š๊ณ  ์ƒ์œ„ ๋ฒ„์ „์— ์ƒˆ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ICollection์—๋Š” ์ด๋ฏธ IReadOnlyCollection ๋ฉ”์„œ๋“œ๊ฐ€ ๊ตฌํ˜„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ฃผ์„์€ ๊นจ์ ธ์•ผ ํ•ฉ๋‹ˆ๋‹ค... :-/

@generik0 ๋‹น์‹ ์ด ์ƒ๊ฐํ•˜๊ณ  ์žˆ๋Š” ์†Œ์Šค ํ˜ธํ™˜์„ฑ์„ ๊นจ๋œจ๋ฆฌ์ง€ ์•Š์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค [์ƒ๊ฐํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค; ๊ทธ๋Ÿด ๊ฒƒ์ด๋‹ค], ํ•˜์ง€๋งŒ C#์ด ์•„๋‹Œ IL ํ…Œ์ด๋ธ”์—์„œ ์ž‘๋™ํ•˜๋Š” ๋ฐ”์ด๋„ˆ๋ฆฌ ํ˜ธํ™˜์„ฑ์„ ๊นจ๋œจ๋ฆด ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์ข‹์•„ @jnm2 ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
๋‚˜๋Š” ์ด์ œ ์ฃผ์ œ๋ฅผ ๋ฒ—์–ด๋‚œ ํ˜ธ์–ธ์žฅ๋‹ด์„ ์ค‘๋‹จํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋‹จ์ง€ ๊ทธ๊ฒƒ์ด ๋‚˜์œ ์•„ํ‚คํ…์ฒ˜๋ผ๊ณ  ์ƒ๊ฐํ•˜์‹ญ์‹œ์˜ค. ๋“ค์–ด์ฃผ์‹œ๊ณ  ์„ค๋ช…ํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค :-)

@jnm2

@generik0 ๋‹น์‹ ์ด ์ƒ๊ฐํ•˜๋Š” ์†Œ์Šค ํ˜ธํ™˜์„ฑ์„ ๊นจ๋œจ๋ฆฌ์ง€ ์•Š๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ด์ง€๋งŒ C#์ด ์•„๋‹Œ IL ํ…Œ์ด๋ธ”์—์„œ ์ž‘๋™ํ•˜๋Š” ๋ฐ”์ด๋„ˆ๋ฆฌ ํ˜ธํ™˜์„ฑ์„ ๊นจ๋œจ๋ฆด ๊ฒƒ์ž…๋‹ˆ๋‹ค.

(์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค.) ์†Œ์Šค๊ฐ€ .net-4.5 ์ด์ „ ๋ฒ„์ „์—์„œ ๋ช…์‹œ์ ์œผ๋กœ ICollection<T> ๋ฅผ ๊ตฌํ˜„ํ•œ ๊ฒฝ์šฐ ์†Œ์Šค ํ˜ธํ™˜์„ฑ๋„ ๊นจ์ง‘๋‹ˆ๋‹ค. IReadOnlyCollection<T>.Count ๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ๊ตฌํ˜„ํ•˜์ง€ ๋ชปํ•ด ํด๋ž˜์Šค๊ฐ€ ์ปดํŒŒ์ผ๋˜์ง€ ์•Š๊ธฐ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋ฐ”์ด๋„ˆ๋ฆฌ ํ˜ธํ™˜์„ฑ์€ ๊ด‘๋ฒ”์œ„ํ•œ .net ๋ฒ„์ „์„ ๋Œ€์ƒ์œผ๋กœ ํ•˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋” ํฐ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. ์ด์ „ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ๋Œ€์ƒ์œผ๋กœ ํ•˜๋Š” ๋Œ€์‹  ๋‘˜ ๋‹ค ๋Œ€์ƒ์œผ๋กœ ์ง€์ •ํ•ด์•ผ ํ•จ).

ICollection<T> ๊ฐ€ .NET Core 3.0+์— ๋Œ€ํ•ด IReadOnlyCollection<T> ๋ฅผ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ C#8์— ๊ธฐ๋ณธ ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌํ˜„ ์ง€์›์ด ์ถ”๊ฐ€๋˜์—ˆ๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.

ํ™•์žฅ์ด ํ•„์š”ํ•  ์ˆ˜๋„ ์žˆ๊ณ  ์ตœ์†Œํ•œ ๋™์ผํ•œ ์ปฌ๋ ‰์…˜์ผ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ienumerable ๋˜๋Š” icollection์„ reaadonlycollection์œผ๋กœ ๊ฐ€์ ธ์™€์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ ... ์–ด๋–ค ์ƒ๊ฐ์ด ์žˆ์œผ์‹ญ๋‹ˆ๊นŒ?

[ @jnm2 ๋Œ“๊ธ€ ํŽธ์ง‘]
c# public static class CollectionExtensions { public static IReadOnlyCollection<T> CastAsReadOnlyCollection<T>(this IEnumerable<T> collection) { if((collection is IReadOnlyCollection<T> readOnlyCollection )) { return readOnlyCollection ; } throw new ArgumentException($"{collection.GetType()} not supported as readonly collection"); } }

@generik0 ํ•ด๋‹น ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๋Œ€์‹  enumerable as IReadOnlyCollection<T> ?? throw ... ๋˜๋Š” (IReadOnlyCollection<T>)enumerable ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

@jnm2 ์˜ด . ๋‹น์‹ ์ด ๋งž์Šต๋‹ˆ๋‹ค. ๊ฐ€๋”์€ ๋ช…๋ฃŒํ•œ ๊ทธ๋ฆผ์ด ์•ˆ ๋ณด์ด๊ณ  ๋„ˆ๋ฌด ๋ณต์žกํ•ด์ง€๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค!!!

๋‚˜๋Š” ๋‹จ์ˆœํ•จ์„ ์–ป๊ธฐ ์œ„ํ•ด ์—ฌ์ „ํžˆ ํ™•์žฅ์„ ํ˜ธ์ถœ ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค ;-)
๊ณ ๋งˆ์›Œ ์นœ๊ตฌ....

์—ฌ๊ธฐ ์ƒํƒœ๊ฐ€ ์–ด๋–ป์Šต๋‹ˆ๊นŒ? ๋‚˜๋Š” ํ‘œ์ค€ lib์—์„œ ์ด ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ •๋ง ์›ํ•˜๊ณ  HashSet<>๊ฐ€ ๊ทธ๊ฒƒ์„ ๊ตฌํ˜„ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

Shapes ์ œ์•ˆ์ด (์ž˜ํ•˜๋ฉด) ๊ตฌํ˜„๋  ๋•Œ๊นŒ์ง€ ์ž ์‹œ ๋” ๊ธฐ๋‹ค๋ฆฌ๋Š” ๊ฒƒ์ด ์ตœ์„ ์˜ ๋ฐฉ๋ฒ•์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ ์›ํ•˜๋Š” ์„ธํŠธ ์œ ํ˜•์„ ๋‚˜ํƒ€๋‚ด๋Š” ๋ชจ์–‘ ๊ทธ๋ฃน์„ ๋งŒ๋“ค๊ณ  HashSet<T> ์™€ ๊ฐ™์€ ๊ธฐ์กด ์„ธํŠธ๊ฐ€ ์ด๋ฅผ ์ค€์ˆ˜ํ•˜๋„๋ก ๊ตฌํ˜„์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ •ํ™•ํžˆ ์ด๊ฒƒ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ์ปค๋ฎค๋‹ˆํ‹ฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ๋“ฑ์žฅํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋‹ค์–‘ํ•œ ์œ ํ˜•์˜ ์ง‘ํ•ฉ(๋‚ดํฌ(์ˆ ์–ด) ๋ฐ ํ™•์žฅ(๋‚˜์—ด๋จ), ์ •๋ ฌ, ๋ถ€๋ถ„ ์ •๋ ฌ, ์ •๋ ฌ๋˜์ง€ ์•Š์Œ, ์…€ ์ˆ˜ ์žˆ์Œ, ์…€ ์ˆ˜ ์žˆ๋Š” ๋ฌดํ•œ, ์…€ ์ˆ˜ ์—†๋Š” ๋ฌดํ•œ, ๊ฐ€๋Šฅํ•˜๊ฒŒ๋Š” Rational๊ณผ ๊ฐ™์€ ์ˆ˜ํ•™์  ๋„๋ฉ”์ธ ํฌํ•จ)์„ ๋ชจ๋‘ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. , ์ž์—ฐ์ˆ˜ ๋“ฑ) ์ด๋Ÿฌํ•œ ์ง‘ํ•ฉ์— ๋Œ€ํ•ด ์ •์˜๋œ ๋ชจ๋“  ํ•ฉ์ง‘ํ•ฉ, ๊ต์ง‘ํ•ฉ, ์นด๋””๋„๋ฆฌํ‹ฐ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค๋ฅธ ๋ชจ์–‘์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๊ฒƒ์€ ๋‚˜์—๊ฒŒ 5๋…„ ํ›„์ฒ˜๋Ÿผ ๋“ค๋ฆฐ๋‹ค. ํ•˜๋ฃจ ๋งŒ์— ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ„๋‹จํ•œ ๋ณ€๊ฒฝ์ด ์ผ์–ด๋‚˜์ง€๋„ ์•Š์€ 1000๋ฐฐ ๋” ํฐ ์•„์ง ์ง€์ •๋˜์ง€ ์•Š์€ ๊ธฐ๋Šฅ์„ ๊ธฐ๋‹ค๋ ค์•ผ ํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

๊ทธ๊ฒƒ์€ ๋‚˜์—๊ฒŒ 5๋…„ ํ›„์ฒ˜๋Ÿผ ๋“ค๋ฆฐ๋‹ค. ํ•˜๋ฃจ ๋งŒ์— ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ„๋‹จํ•œ ๋ณ€๊ฒฝ์ด ์ผ์–ด๋‚˜์ง€๋„ ์•Š์€ 1000๋ฐฐ ๋” ํฐ ์•„์ง ์ง€์ •๋˜์ง€ ์•Š์€ ๊ธฐ๋Šฅ์„ ๊ธฐ๋‹ค๋ ค์•ผ ํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

๋‚˜๋Š” ๋‹จ์ง€ IReadOnlySet<T> ์— ๋Œ€ํ•œ ์ง„์ „์ด ์—†๋Š” ๊ฒƒ์— ์‘๋‹ตํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค - ์ด ๋ฌธ์ œ๋Š” ์ด๋ฏธ 4๋…„ ํ›„์— ๊ณต๊ฐœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๋งˆ์ดํฌ๋กœ์†Œํ”„ํŠธ ๋ฐฉ์‹: ๊ฐ€์žฅ ๊ฐ„๋‹จํ•˜๊ณ  ์œ ์šฉํ•œ ๊ฒƒ์€ ์ˆ˜์‹ญ ๋…„์ด ๊ฑธ๋ฆฝ๋‹ˆ๋‹ค. ์ •์‹ ์ด ๋ฒˆ์ฉ ๋“ ๋‹ค. 5๋…„๊ณผ ๊ณ„์‚ฐ.

๋” ์›ƒ๊ธด๊ฑด ์—ฌ๊ธฐ๋„ ์žˆ์Œ
https://docs.microsoft.com/en-us/dotnet/api/microsoft.sqlserver.management.sdk.sfc.ireadonlyset-1

@terrajobst ์ƒ๊ฐ?

  • ์šฐ๋ฆฌ๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ์ด๊ฒƒ์ด ์ธํ„ฐํŽ˜์ด์Šค ๊ณ„์ธต ๊ตฌ์กฐ์˜ ๊ตฌ๋ฉ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ๊ธฐ์กด ์„ธํŠธ ๊ตฌํ˜„์— ๊ตฌํ˜„ํ•˜๋Š” ๋ฐ ์ง‘์ค‘ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๋Š” ISet<T> IReadOnlySet<T> ISet<T> ํ™•์žฅํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค(๋‹ค๋ฅธ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅํ•œ ์ธํ„ฐํŽ˜์ด์Šค์— ๋Œ€ํ•ด ํ•  ์ˆ˜ ์—†์—ˆ๋˜ ๊ฒƒ๊ณผ ๊ฐ™์€ ์ด์œ ๋กœ). ๋‚˜์ค‘์— ReadOnlySet<T> ๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. IReadOnlySet<T> ๊ฐ€ ISet<T> ์—์„œ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅํ•œ API๋ฅผ ๋บ€ ๊ฐ’์ธ์ง€ ๋‹ค์‹œ ํ™•์ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ๋˜ํ•œ ImmutableSortedSet<T> ๋ฐ ImmutableHashSet<T> (๋ฐ ํ•ด๋‹น ๋นŒ๋”)์— IReadOnlySet<T> ๋ฅผ ๊ตฌํ˜„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ISet<T> ์˜ ๋‹ค๋ฅธ ๊ตฌํ˜„์„ ๊ฒ€์ƒ‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
 namespace System.Collections.Generic {
+    public interface IReadOnlySet<out T> : IReadOnlyCollection<T>, IEnumerable, IEnumerable<T> {
+        bool Contains(T value);
+        bool IsProperSubsetOf(IEnumerable<T> other);
+        bool IsProperSupersetOf(IEnumerable<T> other);
+        bool IsSubsetOf(IEnumerable<T> other);
+        bool IsSupersetOf(IEnumerable<T> other);
+        bool Overlaps(IEnumerable<T> other);
+        bool SetEquals(IEnumerable<T> other);
+    }
-    public class HashSet<T> : ICollection<T>, IDeserializationCallback, IEnumerable, IEnumerable<T>, IReadOnlyCollection<T>, ISerializable, ISet<T> {
+    public class HashSet<T> : ICollection<T>, IDeserializationCallback, IEnumerable, IEnumerable<T>, IReadOnlyCollection<T>, ISerializable, ISet<T>, IReadOnlySet<T> {
     }
-    public class SortedSet<T> : ICollection, ICollection<T>, IDeserializationCallback, IEnumerable, IEnumerable<T>, IReadOnlyCollection<T>, ISerializable, ISet<T> {
+    public class SortedSet<T> : ICollection, ICollection<T>, IDeserializationCallback, IEnumerable, IEnumerable<T>, IReadOnlyCollection<T>, ISerializable, ISet<T>, IReadOnlySet<T> {
     }
 }

ํ•ด๋ด, ๊ฐํžˆ!

@terrajobst

์šฐ๋ฆฌ๋Š” ISet<T> IReadOnlySet<T> ISet<T> ํ™•์žฅํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค(๋‹ค๋ฅธ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅํ•œ ์ธํ„ฐํŽ˜์ด์Šค์— ๋Œ€ํ•ด ํ•  ์ˆ˜ ์—†์—ˆ๋˜ ๊ฒƒ๊ณผ ๊ฐ™์€ ์ด์œ ๋กœ).

๊ธฐ๋ณธ ์ธํ„ฐํŽ˜์ด์Šค ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด๋„ ์ด๊ฒƒ์ด ์—ฌ์ „ํžˆ ์‚ฌ์‹ค์ž…๋‹ˆ๊นŒ? https://github.com/dotnet/corefx/issues/41409 ๋ฅผ ๋‹ซ์•„์•ผ ํ•œ๋‹ค๋Š” ๋œป์ธ๊ฐ€์š”?

@terrajobst

์šฐ๋ฆฌ๋Š” ISet<T> IReadOnlySet<T> ISet<T> ํ™•์žฅํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค(๋‹ค๋ฅธ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅํ•œ ์ธํ„ฐํŽ˜์ด์Šค์— ๋Œ€ํ•ด ํ•  ์ˆ˜ ์—†์—ˆ๋˜ ๊ฒƒ๊ณผ ๊ฐ™์€ ์ด์œ ๋กœ).

๊ธฐ๋ณธ ์ธํ„ฐํŽ˜์ด์Šค ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด๋„ ์ด๊ฒƒ์ด ์—ฌ์ „ํžˆ ์‚ฌ์‹ค์ž…๋‹ˆ๊นŒ? dotnet/corefx#41409๋ฅผ ๋‹ซ์•„์•ผ ํ•œ๋‹ค๋Š” ๋œป์ธ๊ฐ€์š”?

์šฐ๋ฆฌ๋Š” ์ด๊ฒƒ์„ ๋…ผ์˜ํ–ˆ์Šต๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๋Š” DIM ์ด ์ž‘๋™

@terrajobst / @danmosemsft ๋ˆ„๊ตฌ์—๊ฒŒ ํ• ๋‹น๋˜์—ˆ์Šต๋‹ˆ๊นŒ?

๊ทธ๋ฆฌ๊ณ  ์šฐ๋ฆฌ๊ฐ€ ๋‹ฌ์„ฑํ•˜๊ณ ์ž ํ•˜๋Š” ์ž‘์—…์„ ๋ช…ํ™•ํžˆ ํ•˜๊ธฐ ์œ„ํ•ด @terrajobst ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
```
IReadOnlySet๋„ ๊ตฌํ˜„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.ImmutableSortedSet์—์„œ๋ฐ ImmutableHashSet(๊ทธ๋ฆฌ๊ณ  ๊ทธ๋“ค์˜ ๋นŒ๋”)
ISet์˜ ๋‹ค๋ฅธ ๊ตฌํ˜„์„ ๊ฒ€์ƒ‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค..
````
HashSet, SortedSet์— ์œ„์˜ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ.

์Šค์บ”ํ•˜๋Š” ๊ฒƒ์€ ๋ฌด์—‡์ด๋“  ์ฐพ๊ณ  ์˜์‹ฌ์Šค๋Ÿฌ์šด ๊ฒƒ ๊ฐ™์œผ๋ฉด ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.

์ด๊ฒƒ์ด ์—ฌ์ „ํžˆ ์žกํž ์ˆ˜ ์žˆ๋‹ค๋ฉด ๋‚˜๋Š” ๊ด€์‹ฌ์„ ๊ฐ€์งˆ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

@Jlalond ์•„๋‹ˆ, ๋‹น์‹ ์—๊ฒŒ ํ• ๋‹น๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ œ์•ˆ ๊ณ ๋งˆ์›Œ.

@danmosemsft @terrajobst
๊ทธ๋ƒฅ ์—…๋ฐ์ดํŠธ์ž…๋‹ˆ๋‹ค. ์ €๋Š” ์ด ์ž‘์—…์„ ํ•˜๊ณ  ์žˆ์œผ๋ฉฐ, ๊ฐœ์ธ์šฉ ์ฝ”์–ด Lib์— ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

๋งˆ์ง€๋ง‰ ์งˆ๋ฌธ Dan, ์ด๊ฒƒ์„ ์œ„ํ•ด Mono๋ฅผ ๋ณ€๊ฒฝํ•ด์•ผ ํ•ฉ๋‹ˆ๊นŒ? corefx๊ฐ€ ๋๋‚˜๊ณ  ๋ชจ๋…ธ๊ฐ€ ์‹œ์ž‘๋˜๋Š” ์œ„์น˜์— ๋Œ€ํ•ด ํ†ต์ฐฐ๋ ฅ์ด ์—†์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ๋งŒ์•ฝ ๋‹น์‹ ์ด ๊ทธ๊ฒƒ์ด ๋‚˜๋ฅผ ๋…๋ฆฝ์ ์ธ ์—ฐ๊ตฌ๋กœ๋ถ€ํ„ฐ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์•ˆ๋‹ค๋ฉด

@Jlalond Mono๋ฅผ ๋ณ€๊ฒฝํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. Mono ๋Ÿฐํƒ€์ž„์„ ์ด ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋กœ ์ด๋™ํ•˜๋Š” ์ด์œ  ์ค‘ ํ•˜๋‚˜๋Š” CoreCLR ๋˜๋Š” Mono ๋Ÿฐํƒ€์ž„๊ณผ ๋™์ผํ•œ ์ •ํ™•ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์›ํ™œํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•จ์ž…๋‹ˆ๋‹ค. ํ•ต์‹ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์€ ๋ถ€๋ถ„๋งŒ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
coreclrsrcSystem.Private.CoreLib ๋Œ€ mononetcoreSystem.Private.CoreLib. (๋Œ€๋ถ€๋ถ„์˜ ํ•ต์‹ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” librarySystem.Private.CoreLib ์™ธ๋ถ€์—์„œ ๊ณต์œ ๋ฉ๋‹ˆ๋‹ค). ๊ทธ๋ž˜์„œ ๋‹น์‹ ์ด ๊ทธ๊ฒƒ์„ ๋งŒ์ง€์ง€ ์•Š๋Š” ํ•œ - ๋‹น์‹ ์€ ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

@danmosemsft ์„ค๋ช…

์ด๋ด @danmosemsft ๋Š” ์ด๊ฒƒ์— ๋Œ€ํ•ด ํ›„์† ์กฐ์น˜๋ฅผ

์ฃผ์†Œ #32488

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰