1+ local System = System
2+ local Collection = System .Collection
3+ local buildArray = Collection .buildArray
4+ local checkIndex = Collection .checkIndex
5+ local arrayEnumerator = Collection .arrayEnumerator
6+
7+ local Array = {}
8+ local emptys = {}
9+
10+ Array .__ctor__ = buildArray
11+ Array .set = Collection .setArray
12+ Array .get = Collection .getArray
13+ Array .GetEnumerator = arrayEnumerator
14+
15+ function Array .getLength (this )
16+ return # this
17+ end
18+
19+ function Array .getCount (this )
20+ return # this
21+ end
22+
23+ function Array .getRank (this )
24+ return 1
25+ end
26+
27+ function Array .Empty (T )
28+ local t = emptys [T ]
29+ if t == nil then
30+ t = Array (T )(0 )
31+ emptys [T ] = t
32+ end
33+ return t
34+ end
35+
36+ Array .Exists = Collection .existsOfArray
37+ Array .Find = Collection .findOfArray
38+
39+ local findAll = Collection .findAllOfArray
40+ function Array .FindAll (t , match )
41+ return findAll (t , match ):toArray ()
42+ end
43+
44+ Array .FindIndex = Collection .findIndexOfArray
45+ Array .FindLast = Collection .findLastOfArray
46+ Array .FindLastIndex = Collection .findLastIndexOfArray
47+ Array .IndexOf = Collection .indexOfArray
48+ Array .LastIndexOf = Collection .lastIndexOfArray
49+ Array .Reverse = Collection .reverseArray
50+ Array .Sort = Collection .sortArray
51+ Array .TrueForAll = Collection .trueForAllOfArray
52+ Array .Copy = Collection .copyArray
53+
54+ System .define (" System.Array" , function (T )
55+ local cls = {
56+ __inherits__ = { System .IList_1 (T ), System .IList },
57+ __genericT__ = T
58+ }
59+ return cls
60+ end , Array )
61+
62+ function System .arrayFromTable (t , T )
63+ return setmetatable (t , System .Array (T ))
64+ end
65+
66+ local MultiArray = {}
67+
68+ function MultiArray .__ctor__ (this , rank , ...)
69+ this .__rank__ = rank
70+ local length = 1
71+ for _ , i in ipairs (rank ) do
72+ length = length * i
73+ end
74+ buildArray (this , length , ... )
75+ end
76+
77+ local function getIndex (this , ...)
78+ local rank = this .__rank__
79+ local id = 0
80+ local len = # rank
81+ for i = 1 , len do
82+ id = id * rank [i ] + select (i , ... )
83+ end
84+ return id , len
85+ end
86+
87+ function MultiArray .set (this , ...)
88+ local index , len = getIndex (this , ... )
89+ setArray (this , index , select (len + 1 , ... ))
90+ end
91+
92+ function MultiArray .get (this , ...)
93+ local index = getIndex (this , ... )
94+ return getArray (this , index )
95+ end
96+
97+ function MultiArray .getLength (this , dimension )
98+ if dimension == nil then
99+ return # this
100+ end
101+ local rank = this .__rank__
102+ checkIndex (rank , dimension )
103+ return this .__rank__ [dimension + 1 ]
104+ end
105+
106+ function MultiArray .getRank (this )
107+ return # this .__rank__
108+ end
109+
110+ MultiArray .GetEnumerator = arrayEnumerator
111+
112+ System .define (" System.MultiArray" , function (T )
113+ local cls = {
114+ __inherits__ = { System .IList_1 (T ), System .IList },
115+ __genericT__ = T
116+ }
117+ return cls
118+ end , MultiArray )
0 commit comments