乙肝五项一五阳性什么意思| 梦见打人是什么意思| 手抖什么原因| 4.20什么星座| 为什么醋能让疣体脱落| 万条垂下绿丝绦的上一句是什么| 什么狗不会咬人| 婴儿足底采血查什么| 心率偏低是什么原因| 语重心长是什么意思| 脑出血什么症状| 钙盐沉积是什么意思| 华是什么意思| 开业送什么礼物好| 627是什么星座| 提肛有什么好处| 兔子爱吃什么| 孕中期宫缩是什么感觉| 牙痛 吃什么药| 破伤风挂什么科| 天蝎座与什么星座最配| 德比什么意思| 桑枝是什么| 老是干咳嗽是什么原因| 宝宝手脚冰凉是什么原因| 刀客是什么意思| 坐地户是什么意思| 喝白醋有什么好处| 一个草字头一个见念什么| 蜈蚣最怕什么药| 减肥期间可以吃什么| s925银是什么意思| 杭州五行属什么| 最毒妇人心是什么意思| 茔是什么意思| 双脚踝浮肿是什么原因| 中央电视台台长是什么级别| 退烧药吃多了有什么副作用| 金丝皇菊有什么功效| 什么是脊柱侧弯| nc是什么意思| 暑湿感冒吃什么药| bopv是什么疫苗| 鲤鱼爱吃什么| 阴道息肉长什么样| 痔疮有什么症状| 美团和美团外卖有什么区别| 印度讲什么语言| 今天突然拉稀拉出血什么原因| 和谐的什么| 文殊菩萨是管什么的| 威海有什么好玩的| 什么是马上风| 又字加一笔是什么字| 霸王别姬是什么意思| 量程是什么| 动人是什么意思| 耐人寻味什么意思| 国老是什么中药| 什么样的房子风水好| 总是失眠是什么原因| 为什么会排卵期出血| 乙肝五项第二项阳性是什么意思| 体能是什么| 英语专八是什么水平| 蓝痣有没有什么危害| 西湖醋鱼用什么鱼| 污蔑是什么意思| 狮子座和什么星座最配| 织物是什么材质| 海藻面膜有什么作用| 美育是什么| 二月初十是什么星座| 梦见洗澡是什么预兆| 吃恩替卡韦有什么副作用| 痔疮应该挂什么科室| 三进宫是什么意思| 中心性肥胖什么意思| 胸推是什么| 亲临是什么意思| 山丘是什么意思| 中老年人吃什么油好| 每天吃三颗红枣有什么好处| 为国为民是什么生肖| 三点水的字有什么| 什么睡姿对髋关节好| 什么不同成语| 镁是什么| 魂牵梦萦的意思是什么| 馕是什么意思| 农历六月是什么夏| 孕妇缺铁吃什么| 炭疽是什么| 美仑美奂什么意思| 淋巴结钙化是什么意思| 陪护是什么意思| 中午吃什么不会胖| 一是什么动物| 术后吃什么刀口恢复得快| 重磅是什么意思| 人生八苦是什么| 1977年什么命| 神经衰弱是什么| 胆囊息肉样病变是什么意思| 地贫是什么病| 勾心斗角是什么意思| 纠察是什么意思| 荒芜是什么意思| 大云是什么烟| 天的反义词是什么| 痛风吃什么水果最好| 口水为什么是臭的| 脑控是什么| 痛经 吃什么| 秦始皇为什么要焚书坑儒| 去疤痕挂什么科| 龙代表什么数字| 探店是什么意思| 荣字五行属什么| hpv检查前需要注意什么| 公筷是什么意思| 感冒了吃什么| 发炎是什么原因引起的| 心电图窦性心律什么意思| 什么地响| kor是什么意思| 智商135是什么水平| 吃炒黄豆有什么好处和坏处| 牙齿痛是什么原因| 脚后跟疼痛是什么原因| 柱镜是什么意思| 五月十二是什么星座| 益生菌不能和什么一起吃| 我在你心里是什么颜色| 车牌号选什么数字吉利| 什么水果糖分最低| 腹股沟在什么位置| 检查乙肝五项挂什么科| 温水煮青蛙是什么意思| 绿豆吃多了有什么坏处| 鲜卑人是现在的什么人| 富贵包去医院挂什么科| 恐龙是什么时候灭绝| 滑膜炎用什么药治疗最好最快| 血压什么时候量最准确| 闰月要给父母买什么| buffalo是什么牌子| 补骨头吃什么最好| 为什么猫怕水| 偏安一隅是什么意思| 香辛料是什么| 屋尘螨和粉尘螨是什么| 孕妇鼻子出血是什么原因| 肉苁蓉与什么搭配好| 舌苔厚发黄是什么原因| 返聘是什么意思| 小孩肚子疼吃什么药| 尸臭是什么味道| 什么水果含硒量最高| 刻薄是什么意思| 尿酸高适合吃什么食物| 李逵的绰号是什么| 小便解不出来是什么原因| 平顶山为什么叫平顶山| 乙肝表面抗体阳性是什么意思| 减肥晚上适合吃什么水果| qcy是什么牌子| 什么时候跑步减肥效果最好| 间接胆红素偏高是什么原因| 喉咙发炎是什么症状| 白泽是什么神兽| 非钙化斑块是什么意思| ag医学上是什么意思| lof是什么基金| 支气管炎哮喘吃什么药| hpv都有什么症状| 县武装部长是什么级别| 肠炎吃什么消炎药| 天鹅吃什么| 新的五行属性是什么| 养胃早餐吃什么好| 霜降是什么时候| 怀孕肚子会有什么反应| 九月十七是什么星座| 灰指甲什么样| 什么人不能吃猪肝| 中专是什么学历| 什么人容易老年痴呆| 胃气上逆是什么原因造成的| 梦见涨大水是什么意思| 什么东西驱蛇效果最好| 梦到自己拔牙齿是什么预兆| 公历是什么| 龟苓膏的原料是什么| 法益是什么意思| 嘴唇干是什么原因引起的| 下身痒是什么原因| 什么什么为难| 旺夫脸是什么脸型| 为什么会睡不着| 石斛与什么搭配最好| 虫草花是什么| 十三幺是什么意思| 便秘有什么症状| 流口水是什么原因引起的| 黄体功能不足是什么原因造成的| 游离脂肪酸是什么| 多五行属性是什么| 奚字五行属什么| 儿童过敏性皮炎用什么药膏| 6.25是什么日子| 吃什么能瘦肚子| 脚底拔罐对女人有什么好处| 小儿湿疹是什么原因造成的| 膝盖缝里面疼什么原因| 湿气太重吃什么| 腹泻是什么症状| 冷得直什么| 未时是什么时候| 丧是什么意思| 没有痔疮大便出血是什么原因| 吃什么可以淡斑| 姑姑的儿子叫什么| 鱼吐泡泡是什么原因| 天津立冬吃什么| 离子水是什么水| 杀阴虱用什么药最好| 杜甫自号什么| 沙眼用什么眼药水| 讲信修什么| 陈皮泡水喝有什么功效| 什么是一体机| 什么叫内痔什么叫外痔| 24节气分别是什么| 说话不清楚去医院挂什么科| 桥本甲状腺炎是什么| 手背发黄是什么原因| 碱是什么东西| 不成功便成仁的仁是什么意思| 什么食物含碘| 5月12日是什么星座| 什么叫因果| 移植后要注意什么| 蜜蜡属于什么五行属性| 酷暑难当是什么意思| 卵圆孔未闭是什么意思| 支原体和衣原体有什么区别| 虾仁和什么包饺子好吃| 吃什么补精| 喝红花有什么作用与功效| 早上起来眼皮肿是什么原因| 皮肤过敏吃什么药| 马冲什么生肖| 1022是什么星座| 贾字五行属什么| 腱鞘炎吃什么药最好| 乳腺结节低回声是什么意思| 肚子胀是什么原因| 支气管哮喘是什么原因引起的| 类风湿吃什么药最有效| 谁也不知道下一秒会发生什么| 肝脏是什么功能| 丝瓜吃了有什么好处| 什么是初心| 百度Vés al contingut

北京市怀柔区人民政府 关于干部职务任免的...

De la Viquipèdia, l'enciclopèdia lliure
Icona de documentació de mòdul Documentació del mòdul?[ mostra ] [ modifica el codi ] [ mostra l'historial ] [ refresca ]
百度 火箭迫不得已动用死亡五小来救场,而巴莫特就成为了他们的中锋人选,没想到这套阵容却取得了奇效。

Mòdul TableTools (codi · ús · discussió · proves · tests · casos prova | subpàgines · enlla?os)

A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]


--[[
------------------------------------------------------------------------------------
--                               TableTools                                       --
--                                                                                --
-- This module includes a number of functions for dealing with Lua tables.        --
-- It is a meta-module, meant to be called from other Lua modules, and should     --
-- not be called directly from #invoke.                                           --
------------------------------------------------------------------------------------
--]]

local libraryUtil = require('libraryUtil')

local p = {}

-- Define often-used variables and functions.
local floor = math.floor
local infinity = math.huge
local checkType = libraryUtil.checkType
local checkTypeMulti = libraryUtil.checkTypeMulti

--[[
------------------------------------------------------------------------------------
-- isPositiveInteger
--
-- This function returns true if the given value is a positive integer, and false
-- if not. Although it doesn't operate on tables, it is included here as it is
-- useful for determining whether a given table key is in the array part or the
-- hash part of a table.
------------------------------------------------------------------------------------
--]]
function p.isPositiveInteger(v)
	if type(v) == 'number' and v >= 1 and floor(v) == v and v < infinity then
		return true
	else
		return false
	end
end

--[[
------------------------------------------------------------------------------------
-- isNan
--
-- This function returns true if the given number is a NaN value, and false
-- if not. Although it doesn't operate on tables, it is included here as it is
-- useful for determining whether a value can be a valid table key. Lua will
-- generate an error if a NaN is used as a table key.
------------------------------------------------------------------------------------
--]]
function p.isNan(v)
	if type(v) == 'number' and tostring(v) == '-nan' then
		return true
	else
		return false
	end
end

--[[
------------------------------------------------------------------------------------
-- shallowClone
--
-- This returns a clone of a table. The value returned is a new table, but all
-- subtables and functions are shared. Metamethods are respected, but the returned
-- table will have no metatable of its own.
------------------------------------------------------------------------------------
--]]
function p.shallowClone(t)
	local ret = {}
	for k, v in pairs(t) do
		ret[k] = v
	end
	return ret
end

--[[
------------------------------------------------------------------------------------
-- removeDuplicates
--
-- This removes duplicate values from an array. Non-positive-integer keys are
-- ignored. The earliest value is kept, and all subsequent duplicate values are
-- removed, but otherwise the array order is unchanged.
------------------------------------------------------------------------------------
--]]
function p.removeDuplicates(t)
	checkType('removeDuplicates', 1, t, 'table')
	local isNan = p.isNan
	local ret, exists = {}, {}
	for i, v in ipairs(t) do
		if isNan(v) then
			-- NaNs can't be table keys, and they are also unique, so we don't need to check existence.
			ret[#ret + 1] = v
		else
			if not exists[v] then
				ret[#ret + 1] = v
				exists[v] = true
			end
		end	
	end
	return ret
end			

--[[
------------------------------------------------------------------------------------
-- numKeys
--
-- This takes a table and returns an array containing the numbers of any numerical
-- keys that have non-nil values, sorted in numerical order.
------------------------------------------------------------------------------------
--]]
function p.numKeys(t)
	checkType('numKeys', 1, t, 'table')
	local isPositiveInteger = p.isPositiveInteger
	local nums = {}
	for k, v in pairs(t) do
		if isPositiveInteger(k) then
			nums[#nums + 1] = k
		end
	end
	table.sort(nums)
	return nums
end

--[[
------------------------------------------------------------------------------------
-- affixNums
--
-- This takes a table and returns an array containing the numbers of keys with the
-- specified prefix and suffix. For example, for the table
-- {a1 = 'foo', a3 = 'bar', a6 = 'baz'} and the prefix "a", affixNums will
-- return {1, 3, 6}.
------------------------------------------------------------------------------------
--]]
function p.affixNums(t, prefix, suffix)
	checkType('affixNums', 1, t, 'table')
	checkType('affixNums', 2, prefix, 'string', true)
	checkType('affixNums', 3, suffix, 'string', true)

	local function cleanPattern(s)
		-- Cleans a pattern so that the magic characters ()%.[]*+-?^$ are interpreted literally.
		s = s:gsub('([%(%)%%%.%[%]%*%+%-%?%^%$])', '%%%1')
		return s
	end

	prefix = prefix or ''
	suffix = suffix or ''
	prefix = cleanPattern(prefix)
	suffix = cleanPattern(suffix)
	local pattern = '^' .. prefix .. '([1-9]%d*)' .. suffix .. '$'

	local nums = {}
	for k, v in pairs(t) do
		if type(k) == 'string' then			
			local num = mw.ustring.match(k, pattern)
			if num then
				nums[#nums + 1] = tonumber(num)
			end
		end
	end
	table.sort(nums)
	return nums
end

--[[
------------------------------------------------------------------------------------
-- numData
--
-- Given a table with keys like ("foo1", "bar1", "foo2", "baz2"), returns a table
-- of subtables in the format 
-- { [1] = {foo = 'text', bar = 'text'}, [2] = {foo = 'text', baz = 'text'} }
-- Keys that don't end with an integer are stored in a subtable named "other".
-- The compress option compresses the table so that it can be iterated over with
-- ipairs.
------------------------------------------------------------------------------------
--]]
function p.numData(t, compress)
	checkType('numData', 1, t, 'table')
	checkType('numData', 2, compress, 'boolean', true)
	local ret = {}
	for k, v in pairs(t) do
		local prefix, num = mw.ustring.match(tostring(k), '^([^0-9]*)([1-9][0-9]*)$')
		if num then
			num = tonumber(num)
			local subtable = ret[num] or {}
			if prefix == '' then
				-- Positional parameters match the blank string; put them at the start of the subtable instead.
				prefix = 1
			end
			subtable[prefix] = v
			ret[num] = subtable
		else
			local subtable = ret.other or {}
			subtable[k] = v
			ret.other = subtable
		end
	end
	if compress then
		local other = ret.other
		ret = p.compressSparseArray(ret)
		ret.other = other
	end
	return ret
end

--[[
------------------------------------------------------------------------------------
-- compressSparseArray
--
-- This takes an array with one or more nil values, and removes the nil values
-- while preserving the order, so that the array can be safely traversed with
-- ipairs.
------------------------------------------------------------------------------------
--]]
function p.compressSparseArray(t)
	checkType('compressSparseArray', 1, t, 'table')
	local ret = {}
	local nums = p.numKeys(t)
	for _, num in ipairs(nums) do
		ret[#ret + 1] = t[num]
	end
	return ret
end

--[[
------------------------------------------------------------------------------------
-- sparseIpairs
--
-- This is an iterator for sparse arrays. It can be used like ipairs, but can
-- handle nil values.
------------------------------------------------------------------------------------
--]]
function p.sparseIpairs(t)
	checkType('sparseIpairs', 1, t, 'table')
	local nums = p.numKeys(t)
	local i = 0
	local lim = #nums
	return function ()
		i = i + 1
		if i <= lim then
			local key = nums[i]
			return key, t[key]
		else
			return nil, nil
		end
	end
end

--[[
------------------------------------------------------------------------------------
-- size
--
-- This returns the size of a key/value pair table. It will also work on arrays,
-- but for arrays it is more efficient to use the # operator.
------------------------------------------------------------------------------------
--]]

function p.size(t)
	checkType('size', 1, t, 'table')
	local i = 0
	for k in pairs(t) do
		i = i + 1
	end
	return i
end


local function defaultKeySort(item1, item2)
	-- "number" < "string", so numbers will be sorted before strings.
	local type1, type2 = type(item1), type(item2)
	if type1 ~= type2 then
		return type1 < type2
	else -- This will fail with table, boolean, function.
		return item1 < item2
	end
end

--[[
	Returns a list of the keys in a table, sorted using either a default
	comparison function or a custom keySort function.
]]
function p.keysToList(t, keySort, checked)
	if not checked then
		checkType('keysToList', 1, t, 'table')
		checkTypeMulti('keysToList', 2, keySort, { 'function', 'boolean', 'nil' })
	end
	
	local list = {}
	local index = 1
	for key, value in pairs(t) do
		list[index] = key
		index = index + 1
	end
	
	if keySort ~= false then
		keySort = type(keySort) == 'function' and keySort or defaultKeySort
		
		table.sort(list, keySort)
	end
	
	return list
end

--[[
	Iterates through a table, with the keys sorted using the keysToList function.
	If there are only numerical keys, sparseIpairs is probably more efficient.
]]
function p.sortedPairs(t, keySort)
	checkType('sortedPairs', 1, t, 'table')
	checkType('sortedPairs', 2, keySort, 'function', true)
	
	local list = p.keysToList(t, keySort, true)
	
	local i = 0
	return function()
		i = i + 1
		local key = list[i]
		if key ~= nil then
			return key, t[key]
		else
			return nil, nil
		end
	end
end

--[[
	Returns true if all keys in the table are consecutive integers starting at 1.
--]]
function p.isArray(t)
	checkType("isArray", 1, t, "table")
	
	local i = 0
	for k, v in pairs(t) do
		i = i + 1
		if t[i] == nil then
			return false
		end
	end
	return true
end

-- { "a", "b", "c" } -> { a = 1, b = 2, c = 3 }
function p.invert(array)
	checkType("invert", 1, array, "table")
	
	local map = {}
	for i, v in ipairs(array) do
		map[v] = i
	end
	
	return map
end

--[[
	{ "a", "b", "c" } -> { ["a"] = true, ["b"] = true, ["c"] = true }
--]]
function p.listToSet(t)
	checkType("listToSet", 1, t, "table")
	
	local set = {}
	for _, item in ipairs(t) do
		set[item] = true
	end
	
	return set
end

--[[
	Recursive deep copy function.
	Preserves identities of subtables.
	
]]
local function _deepCopy(orig, includeMetatable, already_seen)
	-- Stores copies of tables indexed by the original table.
	already_seen = already_seen or {}
	
	local copy = already_seen[orig]
	if copy ~= nil then
		return copy
	end
	
	if type(orig) == 'table' then
		copy = {}
		for orig_key, orig_value in pairs(orig) do
			copy[deepcopy(orig_key, includeMetatable, already_seen)] = deepcopy(orig_value, includeMetatable, already_seen)
		end
		already_seen[orig] = copy
		
		if includeMetatable then
			local mt = getmetatable(orig)
			if mt ~= nil then
				local mt_copy = deepcopy(mt, includeMetatable, already_seen)
				setmetatable(copy, mt_copy)
				already_seen[mt] = mt_copy
			end
		end
	else -- number, string, boolean, etc
		copy = orig
	end
	return copy
end

function p.deepCopy(orig, noMetatable, already_seen)
	checkType("deepCopy", 3, already_seen, "table", true)
	
	return _deepCopy(orig, not noMetatable, already_seen)
end

--[[
	Concatenates all values in the table that are indexed by a number, in order.
	sparseConcat{ a, nil, c, d }  =>  "acd"
	sparseConcat{ nil, b, c, d }  =>  "bcd"
]]
function p.sparseConcat(t, sep, i, j)
	local list = {}
	
	local list_i = 0
	for _, v in p.sparseIpairs(t) do
		list_i = list_i + 1
		list[list_i] = v
	end
	
	return table.concat(list, sep, i, j)
end

--[[
-- This returns the length of a table, or the first integer key n counting from
-- 1 such that t[n + 1] is nil. It is similar to the operator #, but may return
-- a different value when there are gaps in the array portion of the table.
-- Intended to be used on data loaded with mw.loadData. For other tables, use #.
-- Note: #frame.args in frame object always be set to 0, regardless of 
-- the number of unnamed template parameters, so use this function for
-- frame.args.
--]]
function p.length(t)
	local i = 1
	while t[i] ~= nil do
		i = i + 1
	end
	return i - 1
end

function p.inArray(arr, valueToFind)
	checkType("inArray", 1, arr, "table")
	
	-- if valueToFind is nil, error?
	
	for _, v in ipairs(arr) do
		if v == valueToFind then
			return true
		end
	end
	
	return false
end

return p
淋漓不尽是什么意思 口且念什么 积福是什么意思 ab血型和o血型的孩子是什么血型 大拇指戴戒指是什么意思
做肠镜检查需要提前做什么准备 掉马是什么意思 来月经为什么会肚子痛 什么是姜黄 肺部纤维灶是什么意思
深井冰什么意思 钦字五行属什么 大腿麻木是什么原因 君王是什么意思 李小龙是什么生肖
逝者如斯夫是什么意思 nbr是什么材料 不适随诊是什么意思 晚上七八点是什么时辰 重症肌无力用什么药
翌日什么意思hcv9jop1ns8r.cn 1月22日什么星座hcv9jop2ns1r.cn 什么是直肠炎hcv8jop3ns5r.cn 三个毛念什么字hcv8jop7ns0r.cn 阿达子是什么hcv7jop4ns6r.cn
看见蝙蝠有什么预兆hcv8jop9ns5r.cn 心阳虚吃什么中成药hcv8jop4ns6r.cn 贴图是什么意思hcv8jop2ns6r.cn 北五行属什么hcv7jop6ns7r.cn 喝蜂蜜有什么好处hcv8jop8ns8r.cn
为什么狗不能吃巧克力hcv7jop7ns0r.cn 上火是什么意思hcv7jop6ns9r.cn butterfly什么意思hcv8jop6ns1r.cn 点子是什么意思sanhestory.com 什么展翅hcv9jop5ns3r.cn
什么蓝hcv8jop1ns1r.cn ipadair2什么时候上市的hcv9jop7ns3r.cn 穿什么好呢hcv9jop7ns5r.cn 一躺下就咳嗽是什么原因hcv9jop6ns2r.cn 法医是干什么的hcv8jop6ns5r.cn
百度