File tree Expand file tree Collapse file tree 1 file changed +36
-26
lines changed
Expand file tree Collapse file tree 1 file changed +36
-26
lines changed Original file line number Diff line number Diff line change @@ -190,38 +190,48 @@ function m.dump(tbl, option)
190190end
191191
192192--- 递归判断A与B是否相等
193- --- @param a any
194- --- @param b any
193+ --- @param valueA any
194+ --- @param valueB any
195195--- @return boolean
196- function m .equal (a , b )
197- local tp1 = type (a )
198- local tp2 = type (b )
199- if tp1 ~= tp2 then
200- return false
201- end
202- if tp1 == ' table' then
203- local mark = {}
204- for k , v in pairs (a ) do
205- mark [k ] = true
206- local res = m .equal (v , b [k ])
207- if not res then
208- return false
209- end
196+ function m .equal (valueA , valueB )
197+ local hasChecked = {}
198+
199+ local function equal (a , b )
200+ local tp1 = type (a )
201+ local tp2 = type (b )
202+ if tp1 ~= tp2 then
203+ return false
210204 end
211- for k in pairs (b ) do
212- if not mark [k ] then
213- return false
205+ if tp1 == ' table' then
206+ if hasChecked [a ] then
207+ return true
208+ end
209+ hasChecked [a ] = true
210+ local mark = {}
211+ for k , v in pairs (a ) do
212+ mark [k ] = true
213+ local res = equal (v , b [k ])
214+ if not res then
215+ return false
216+ end
217+ end
218+ for k in pairs (b ) do
219+ if not mark [k ] then
220+ return false
221+ end
214222 end
215- end
216- return true
217- elseif tp1 == ' number' then
218- if mathAbs (a - b ) <= 1e-10 then
219223 return true
224+ elseif tp1 == ' number' then
225+ if mathAbs (a - b ) <= 1e-10 then
226+ return true
227+ end
228+ return tostring (a ) == tostring (b )
229+ else
230+ return a == b
220231 end
221- return tostring (a ) == tostring (b )
222- else
223- return a == b
224232 end
233+
234+ return equal (valueA , valueB )
225235end
226236
227237local function sortTable (tbl )
You can’t perform that action at this time.
0 commit comments