Mercurial > prosody-hg
comparison util/multitable.lua @ 554:9a695724681d
MultiTable: Remove all empty sub-tables when elements are removed
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Fri, 05 Dec 2008 05:24:10 +0500 |
| parents | 6db1f41e475a |
| children | b2464849c1b0 |
comparison
equal
deleted
inserted
replaced
| 552:6db1f41e475a | 554:9a695724681d |
|---|---|
| 20 | 20 |
| 21 | 21 |
| 22 local select = select; | 22 local select = select; |
| 23 local t_insert = table.insert; | 23 local t_insert = table.insert; |
| 24 local pairs = pairs; | 24 local pairs = pairs; |
| 25 local next = next; | |
| 25 | 26 |
| 26 module "multitable" | 27 module "multitable" |
| 27 | 28 |
| 28 local function get(self, ...) | 29 local function get(self, ...) |
| 29 local t = self.data; | 30 local t = self.data; |
| 53 t[key] = nil; | 54 t[key] = nil; |
| 54 end | 55 end |
| 55 end | 56 end |
| 56 local k = select(n, ...); | 57 local k = select(n, ...); |
| 57 if k then | 58 if k then |
| 58 r(t[k], n+1, _end, ...); | 59 v = t[k]; |
| 60 if v then | |
| 61 r(v, n+1, _end, ...); | |
| 62 if not next(v) then | |
| 63 t[k] = nil; | |
| 64 end | |
| 65 end | |
| 59 else | 66 else |
| 60 for _,b in pairs(t) do | 67 for _,b in pairs(t) do |
| 61 r(b, n+1, _end, ...); | 68 r(b, n+1, _end, ...); |
| 69 if not next(b) then | |
| 70 t[_] = nil; | |
| 71 end | |
| 62 end | 72 end |
| 63 end | 73 end |
| 64 end | 74 end |
| 65 | 75 |
| 66 local function remove(self, ...) | 76 local function remove(self, ...) |
