@@ -70,19 +70,11 @@ end, {
7070}, 1 )
7171
7272local HashSet = {
73- __ctor__ = function (this , ...)
74- local n = select (" #" , ... )
75- local collection , comparer
76- if n == 1 then
77- local c = ...
78- if type (c ) == " table" then
79- if c .GetEnumerator then
80- collection = c
81- end
82- comparer = c
83- end
84- elseif n == 2 then
85- collection , comparer = ...
73+ __ctor__ = function (this , collection , comparer )
74+ if type (collection ) ~= " table" then
75+ collection = nil
76+ elseif not collection .GetEnumerator then
77+ collection , comparer = nil , collection
8678 end
8779 this .dict = System .Dictionary (this .__genericT__ , System .Boolean )(comparer )
8880 if collection then
@@ -236,7 +228,35 @@ local HashSet = {
236228 return match (unWrap (k ))
237229 end )
238230 end ,
239- TrimExcess = System .emptyFn
231+ TrimExcess = System .emptyFn ,
232+ CopyTo = function (this , array , arrayIndex , count )
233+ arrayIndex = arrayIndex or 0
234+ count = count or this :getCount ()
235+ if array == nil then
236+ throw (ArgumentNullException (" array" ))
237+ end
238+ if arrayIndex < 0 then
239+ throw (System .ArgumentOutOfRangeException (" arrayIndex" ))
240+ end
241+ if count < 0 then
242+ throw (System .ArgumentOutOfRangeException (" count" ))
243+ end
244+ local arrayCount = array :getCount ()
245+ if arrayIndex >= arrayCount then
246+ throw (System .ArgumentException (" arrayIndex" ))
247+ end
248+ if arrayIndex + count > arrayCount then
249+ throw (System .ArgumentException (" count is greater than the available space from arrayIndex to the end of the destination array" ))
250+ end
251+ count = count + arrayIndex
252+ for _ , kv in each (this .dict ) do
253+ if arrayIndex >= count then
254+ return
255+ end
256+ array :set (arrayIndex , kv [1 ])
257+ arrayIndex = arrayIndex + 1
258+ end
259+ end
240260}
241261
242262function System .hashSetFromTable (t , T )
245265
246266System .HashSet = System .define (" System.Collections.Generic.HashSet" , function (T )
247267 return {
248- base = { System .ICollection_1 (T ), System .ISet_1 (T ) },
268+ base = { System .ISet_1 (T ), System .IReadOnlySet_1 (T ) },
249269 __genericT__ = T ,
250270 __genericTKey__ = T ,
251271 }
0 commit comments