Mercurial > prosody-hg
comparison util/queue.lua @ 13956:f50a9746fec0
util.queue: Convenience functions for empty/full
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 25 Sep 2025 16:54:23 +0100 |
| parents | d10957394a3c |
| children |
comparison
equal
deleted
inserted
replaced
| 13955:01f95f3de6fc | 13956:f50a9746fec0 |
|---|---|
| 19 --luacheck: ignore 212/self | 19 --luacheck: ignore 212/self |
| 20 return { | 20 return { |
| 21 _items = t; | 21 _items = t; |
| 22 size = size; | 22 size = size; |
| 23 count = function (self) return items; end; | 23 count = function (self) return items; end; |
| 24 empty = function () return items == 0; end; | |
| 25 full = function () return items == size; end; | |
| 24 push = function (self, item) | 26 push = function (self, item) |
| 25 if items >= size then | 27 if items >= size then |
| 26 if allow_wrapping then | 28 if allow_wrapping then |
| 27 tail = (tail%size)+1; -- Advance to next oldest item | 29 tail = (tail%size)+1; -- Advance to next oldest item |
| 28 items = items - 1; | 30 items = items - 1; |
