Software /
code /
prosody
Comparison
util/array.lua @ 7976:2a7ef5fcaa77
util.array: Add O(n) equality check metamethod
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 16 Mar 2017 19:09:57 +0100 |
parent | 7700:0d70410efdcf |
child | 8017:ec7cab8e744d |
comparison
equal
deleted
inserted
replaced
7975:c64ddee9d671 | 7976:2a7ef5fcaa77 |
---|---|
29 end | 29 end |
30 | 30 |
31 function array_mt.__add(a1, a2) | 31 function array_mt.__add(a1, a2) |
32 local res = new_array(); | 32 local res = new_array(); |
33 return res:append(a1):append(a2); | 33 return res:append(a1):append(a2); |
34 end | |
35 | |
36 function array_mt.__eq(a, b) | |
37 if #a == #b then | |
38 for i = 1, #a do | |
39 if a[i] ~= b[i] then | |
40 return false; | |
41 end | |
42 end | |
43 else | |
44 return false; | |
45 end | |
46 return true; | |
34 end | 47 end |
35 | 48 |
36 setmetatable(array, { __call = new_array }); | 49 setmetatable(array, { __call = new_array }); |
37 | 50 |
38 -- Read-only methods | 51 -- Read-only methods |