From 7397df30ab802b6f6e3b75c6094d1c1711604937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 29 Jul 2022 15:25:28 +0800 Subject: cleanup --- 3rd/EmmyLuaCodeStyle | 2 +- script/linked-table.lua | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/3rd/EmmyLuaCodeStyle b/3rd/EmmyLuaCodeStyle index 17b7ee0f..eda85bba 160000 --- a/3rd/EmmyLuaCodeStyle +++ b/3rd/EmmyLuaCodeStyle @@ -1 +1 @@ -Subproject commit 17b7ee0fdb694849ca6c4dc1ecf7b1ed8e957d76 +Subproject commit eda85bbaceee4f98cac87ef77870b236ac3b0997 diff --git a/script/linked-table.lua b/script/linked-table.lua index 4d87e943..a63a528c 100644 --- a/script/linked-table.lua +++ b/script/linked-table.lua @@ -8,10 +8,14 @@ mt._size = 0 local HEAD = {''} local TAIL = {''} +---@param node any +---@return boolean function mt:has(node) return self._left[node] ~= nil end +---@param node any +---@return boolean function mt:isValidNode(node) if node == nil or node == HEAD @@ -21,6 +25,9 @@ function mt:isValidNode(node) return true end +---@param node any +---@param afterWho any +---@return boolean function mt:pushAfter(node, afterWho) if not self:isValidNode(node) then return false @@ -41,6 +48,9 @@ function mt:pushAfter(node, afterWho) return true end +---@param node any +---@param beforeWho any +---@return boolean function mt:pushBefore(node, beforeWho) if node == nil then return false @@ -52,6 +62,8 @@ function mt:pushBefore(node, beforeWho) return self:pushAfter(node, left) end +---@param node any +---@return boolean function mt:pop(node) if not self:isValidNode(node) then return false @@ -71,14 +83,20 @@ function mt:pop(node) return true end +---@param node any +---@return boolean function mt:pushHead(node) return self:pushAfter(node, HEAD) end +---@param node any +---@return boolean function mt:pushTail(node) return self:pushBefore(node, TAIL) end +---@param node any +---@return any function mt:getAfter(node) if node == nil then node = HEAD @@ -90,10 +108,12 @@ function mt:getAfter(node) return right end +---@return any function mt:getHead() return self:getAfter(HEAD) end +---@return any function mt:getBefore(node) if node == nil then node = TAIL @@ -105,18 +125,24 @@ function mt:getBefore(node) return left end +---@return any function mt:getTail() return self:getBefore(TAIL) end +---@return boolean function mt:popHead() return self:pop(self:getHead()) end +---@return boolean function mt:popTail() return self:pop(self:getTail()) end +---@param old any +---@param new any +---@return boolean function mt:replace(old, new) if not self:isValidNode(old) or not self:isValidNode(new) then @@ -137,10 +163,14 @@ function mt:replace(old, new) return true end +---@return integer function mt:getSize() return self._size end +---@param start any +---@param revert? boolean +---@return fun():any function mt:pairs(start, revert) if revert then if start == nil then @@ -171,6 +201,9 @@ function mt:pairs(start, revert) end end +---@param start any +---@param revert? boolean +---@return string function mt:dump(start, revert) local t = {} for node in self:pairs(start, revert) do @@ -186,6 +219,7 @@ function mt:reset() self._size = 0 end +---@return linked-table return function () local self = setmetatable({}, mt) self:reset() -- cgit v1.2.3