summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-04-07 23:13:30 +0800
committerruki <[email protected]>2024-04-07 23:13:30 +0800
commit2a99fd133daea2808253ff1d8545d53c700709af (patch)
tree3aa36a4088a193f90d176efbc1c3d09ef8606c69
parent62194c3e5dff8141813f9f63993516de98dd367f (diff)
rename dlist to list
-rw-r--r--tests/modules/list/test.lua (renamed from tests/modules/dlist/test.lua)24
-rw-r--r--xmake/core/base/list.lua (renamed from xmake/core/base/dlist.lua)64
-rw-r--r--xmake/core/sandbox/modules/import/core/base/dlist.lua2
-rw-r--r--xmake/core/sandbox/modules/import/core/base/list.lua22
-rw-r--r--xmake/core/ui/panel.lua4
-rw-r--r--xmake/modules/private/async/jobpool.lua4
6 files changed, 71 insertions, 49 deletions
diff --git a/tests/modules/dlist/test.lua b/tests/modules/list/test.lua
index 31f939aa2..b1679a304 100644
--- a/tests/modules/dlist/test.lua
+++ b/tests/modules/list/test.lua
@@ -1,7 +1,7 @@
-import("core.base.dlist")
+import("core.base.list")
function test_push(t)
- local d = dlist.new()
+ local d = list.new()
d:push({v = 1})
d:push({v = 2})
d:push({v = 3})
@@ -17,7 +17,7 @@ function test_push(t)
end
function test_insert(t)
- local d = dlist.new()
+ local d = list.new()
local v3 = {v = 3}
d:insert({v = 1})
d:insert({v = 2})
@@ -34,7 +34,7 @@ function test_insert(t)
end
function test_remove(t)
- local d = dlist.new()
+ local d = list.new()
local v3 = {v = 3}
d:insert({v = 1})
d:insert({v = 2})
@@ -53,7 +53,7 @@ function test_remove(t)
end
function test_remove_first(t)
- local d = dlist.new()
+ local d = list.new()
d:push({v = 1})
d:push({v = 2})
d:push({v = 3})
@@ -70,7 +70,7 @@ function test_remove_first(t)
end
function test_remove_last(t)
- local d = dlist.new()
+ local d = list.new()
d:push({v = 1})
d:push({v = 2})
d:push({v = 3})
@@ -86,13 +86,13 @@ function test_remove_last(t)
end
end
-function test_insert_head(t)
- local d = dlist.new()
+function test_insert_first(t)
+ local d = list.new()
d:push({v = 2})
d:push({v = 3})
d:push({v = 4})
d:push({v = 5})
- d:insert_head({v = 1})
+ d:insert_first({v = 1})
t:are_equal(d:first().v, 1)
t:are_equal(d:last().v, 5)
local idx = 1
@@ -102,13 +102,13 @@ function test_insert_head(t)
end
end
-function test_insert_tail(t)
- local d = dlist.new()
+function test_insert_last(t)
+ local d = list.new()
d:push({v = 1})
d:push({v = 2})
d:push({v = 3})
d:push({v = 4})
- d:insert_tail({v = 5})
+ d:insert_last({v = 5})
t:are_equal(d:first().v, 1)
t:are_equal(d:last().v, 5)
local idx = 1
diff --git a/xmake/core/base/dlist.lua b/xmake/core/base/list.lua
index 3b893a622..e6958f74d 100644
--- a/xmake/core/base/dlist.lua
+++ b/xmake/core/base/list.lua
@@ -15,26 +15,26 @@
-- Copyright (C) 2015-present, TBOOX Open Source Group.
--
-- @author ruki
--- @file dlist.lua
+-- @file list.lua
--
-- load modules
local object = require("base/object")
-- define module
-local dlist = dlist or object { _init = {"_length"} } {0}
+local list = list or object { _init = {"_length"} } {0}
-- clear list
-function dlist:clear()
+function list:clear()
self._length = 0
self._first = nil
self._last = nil
end
-- insert item after the given item
-function dlist:insert(t, after)
+function list:insert(t, after)
if not after then
- return self:insert_tail(t)
+ return self:insert_last(t)
end
assert(t ~= after)
if after._next then
@@ -48,8 +48,8 @@ function dlist:insert(t, after)
self._length = self._length + 1
end
--- insert item in head
-function dlist:insert_head(t)
+-- insert the first item in head
+function list:insert_first(t)
if self._first then
self._first._prev = t
t._next = self._first
@@ -61,8 +61,8 @@ function dlist:insert_head(t)
self._length = self._length + 1
end
--- insert item in tail
-function dlist:insert_tail(t)
+-- insert the last item in tail
+function list:insert_last(t)
if self._last then
self._last._next = t
t._prev = self._last
@@ -75,7 +75,7 @@ function dlist:insert_tail(t)
end
-- remove item
-function dlist:remove(t)
+function list:remove(t)
if t._next then
if t._prev then
t._next._prev = t._prev
@@ -101,7 +101,7 @@ function dlist:remove(t)
end
-- remove the first item
-function dlist:remove_first()
+function list:remove_first()
if not self._first then
return
end
@@ -119,7 +119,7 @@ function dlist:remove_first()
end
-- remove last item
-function dlist:remove_last()
+function list:remove_last()
if not self._last then
return
end
@@ -137,37 +137,37 @@ function dlist:remove_last()
end
-- push item to tail
-function dlist:push(t)
- self:insert_tail(t)
+function list:push(t)
+ self:insert_last(t)
end
-- pop item from tail
-function dlist:pop()
+function list:pop()
self:remove_last()
end
-- shift item: 1 2 3 <- 2 3
-function dlist:shift()
+function list:shift()
self:remove_first()
end
-- unshift item: 1 2 -> t 1 2
-function dlist:unshift(t)
- self:insert_head(t)
+function list:unshift(t)
+ self:insert_first(t)
end
-- get first item
-function dlist:first()
+function list:first()
return self._first
end
-- get last item
-function dlist:last()
+function list:last()
return self._last
end
-- get next item
-function dlist:next(last)
+function list:next(last)
if last then
return last._next
else
@@ -176,7 +176,7 @@ function dlist:next(last)
end
-- get the previous item
-function dlist:prev(last)
+function list:prev(last)
if last then
return last._prev
else
@@ -185,12 +185,12 @@ function dlist:prev(last)
end
-- get list size
-function dlist:size()
+function list:size()
return self._length
end
-- is empty?
-function dlist:empty()
+function list:empty()
return self:size() == 0
end
@@ -198,11 +198,11 @@ end
--
-- e.g.
--
--- for item in dlist:items() do
+-- for item in list:items() do
-- print(item)
-- end
--
-function dlist:items()
+function list:items()
local iter = function (list, item)
return list:next(item)
end
@@ -210,17 +210,17 @@ function dlist:items()
end
-- get reverse items
-function dlist:ritems()
+function list:ritems()
local iter = function (list, item)
return list:prev(item)
end
return iter, self, nil
end
--- new dlist
-function dlist.new()
- return dlist()
+-- new list
+function list.new()
+ return list()
end
--- return module: dlist
-return dlist
+-- return module: list
+return list
diff --git a/xmake/core/sandbox/modules/import/core/base/dlist.lua b/xmake/core/sandbox/modules/import/core/base/dlist.lua
index 25047206d..924d27ab1 100644
--- a/xmake/core/sandbox/modules/import/core/base/dlist.lua
+++ b/xmake/core/sandbox/modules/import/core/base/dlist.lua
@@ -19,4 +19,4 @@
--
-- return module
-return require("base/dlist")
+return require("base/list")
diff --git a/xmake/core/sandbox/modules/import/core/base/list.lua b/xmake/core/sandbox/modules/import/core/base/list.lua
new file mode 100644
index 000000000..852fd5231
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/base/list.lua
@@ -0,0 +1,22 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file list.lua
+--
+
+-- return module
+return require("base/list")
diff --git a/xmake/core/ui/panel.lua b/xmake/core/ui/panel.lua
index 7baef5c3a..244aae073 100644
--- a/xmake/core/ui/panel.lua
+++ b/xmake/core/ui/panel.lua
@@ -26,7 +26,7 @@ local event = require("ui/event")
local point = require("ui/point")
local curses = require("ui/curses")
local action = require("ui/action")
-local dlist = require("base/dlist")
+local list = require("base/list")
-- define module
local panel = panel or view()
@@ -44,7 +44,7 @@ function panel:init(name, bounds)
self:option_set("selectable", true)
-- init child views
- self._VIEWS = dlist.new()
+ self._VIEWS = list.new()
-- init views cache
self._VIEWS_CACHE = {}
diff --git a/xmake/modules/private/async/jobpool.lua b/xmake/modules/private/async/jobpool.lua
index 653be2328..342cc096f 100644
--- a/xmake/modules/private/async/jobpool.lua
+++ b/xmake/modules/private/async/jobpool.lua
@@ -20,7 +20,7 @@
-- imports
import("core.base.object")
-import("core.base.dlist")
+import("core.base.list")
import("core.base.hashset")
-- define module
@@ -235,5 +235,5 @@ end
-- new a jobpool
function new()
- return jobpool {0, {name = "root"}, dlist.new(), {}}
+ return jobpool {0, {name = "root"}, list.new(), {}}
end