生理期是什么意思| 什么香什么鼻| 4月28日是什么星座| 身份证后四位代表什么| 隽读什么| 肠癌便血和痔疮便血有什么区别| 最贵的烟是什么| 两极分化是什么意思| 月经一直不干净吃什么药| 什么叫牙冠| 出球小动脉流什么血| 什么食物降火| 检查宫颈做什么检查| 什么是犯罪| 豌豆黄是什么| 烧心吃什么药| 23度穿什么衣服合适| 绛紫色是什么颜色| 传统是什么意思| 为什么减肥不掉秤| 甲状腺结节什么原因引起的| walls是什么意思| 凉瓜是什么瓜| 什么样的伤口需要缝针| 白牌车是什么身份| 女人喝甘草水有什么好处| 强光斑是什么意思| 人为什么要吃肉| 手机飞行模式是什么意思| kumpoo是什么牌子| 痰是绿色的是什么原因| 什么样的女人最吸引男人| 慢性浅表性胃炎伴糜烂吃什么药| 人体成分分析是检查什么| 吃什么补孕酮| 照字五行属什么| 临汾有什么大学| 角膜炎用什么眼药水| 嘴唇上起泡是什么原因| 大白菜什么时候种| 龟龄集适合什么人吃| 86年是属什么的| 搬家有什么讲究和忌讳| 一什么鼓| 味极鲜是什么| 百年好合是什么生肖| 什么叫打飞机| bees是什么意思| 阴唇肿是什么原因| 黄瓜又什么又什么| 疣是什么意思| 晚上十点是什么时辰| 神经系统由什么组成| 湿疹和热疹有什么区别| 授记是什么意思| 婚检男性检查什么| 表哥的孩子叫我什么| 玉米淀粉可以用什么代替| 女人佩戴什么增加阳气| 身体起水泡是什么病症| 空亡是什么意思| 八月二十是什么星座| 海为什么是蓝色| 疯癫是什么意思| 飞蚊症是什么原因造成的能治愈吗| kiki是什么意思| 医学检验技术是什么| 了是什么意思| gp是什么的缩写| 什么是处方药| 3.9是什么星座| 香港什么东西值得买| 9.28什么星座| 三大产能营养素是什么| 吃完螃蟹不能吃什么| 猴日冲虎是什么意思| 属兔本命佛是什么佛| 包皮手术后吃什么伤口愈合快| 浅表性胃炎吃什么药好使| 遗精是什么原因| 柴鸡是什么鸡| 剥离是什么意思| hpv感染是什么症状| 登高是什么意思| 名不见经传是什么意思| 什么是湿热体质| 季字五行属什么| 老是犯困是什么原因| 粉玫瑰花语是什么意思| jm是什么| 什么是淋巴肿瘤| 什么的尾巴有什么作用| 西红柿什么时候成熟| 水土不服吃什么药| 姨妈量少是什么原因| 长发公主叫什么名字| 婴儿血小板低是什么原因| 斯里兰卡用什么货币| 1955年属什么| 仙居杨梅什么时候上市| 白羊男喜欢什么样的女生| 免疫力低挂什么科| 天蝎座和什么星座不合| pt950是什么意思| 嘴唇上长痣代表什么| 陈赫开的火锅店叫什么| 什么人不适合喝咖啡| 子宫内膜增厚有什么影响| 梦见手机屏幕摔碎了是什么意思| 柯基为什么要断尾巴| 肾寒吃什么中成药| 阳起石是什么东西| 医院可以点痣吗挂什么科| 节操什么意思| 气虚是什么意思| 12月28日什么星座| 为什么感冒吃冰棒反而好了| 内秀是什么性格的人| jasonwood是什么牌子| 怀孕去医院检查挂什么科| 籽字五行属什么| 为什么精液是流出来的| 梦到捡金子首饰是什么意思| dos是什么| 孕妇现在吃什么水果好| 发烧反反复复是什么原因| 是的是什么意思| 螺蛳粉有什么危害| 空调制热效果不好什么原因| 中国四大发明是什么| 香雪酒属于什么酒| 生日蛋糕上写什么字比较有创意| 高血压注意什么事项| 吃丝瓜有什么功效和作用| 喉咙突然哑了什么原因| 圣女果是什么水果| 梦见移坟墓是什么预兆| 剖腹产第四天可以吃什么| 语无伦次是什么意思| 土是念什么| 脸无缘无故的肿是什么原因| 腊月初七是什么星座| 智齿旁边的牙齿叫什么| ips屏幕是什么意思| 什么的落日| 什么不惧| 木耳菜是什么菜| 胆囊炎吃什么中成药| honey什么意思| 降三高喝什么茶最好| 30年的婚姻是什么婚| 胃息肉吃什么药治疗| 什么是脊柱侧弯| 什么叫引流| 请惠存是什么意思| 达泊西汀有什么副作用| 骨灰盒什么材质的好| 杜康原是什么| 卡替治疗是什么意思| 荨麻疹忌口什么食物| 大便粗大是什么原因| 什么的果子| 明眸皓齿是什么意思| 二便是什么意思| 肚子隐隐作痛什么原因| 室上速是什么病| 免疫球蛋白是什么东西| 蛋白电泳是查什么的| 什么耳朵| 旭日阳刚为什么不火了| thenorthface是什么牌子| 10年属什么生肖| 白马王子是什么意思| 巡演是什么意思| 橙子和橘子有什么区别| 为什么会有胎记| 过继是什么意思| 尿酸高能吃什么水果| 肛门坠胀用什么药| 一什么火焰| 糖耐量是什么| 什么是拉拉| 中国黄金为什么比其它金店便宜| 东营有什么大学| 碱什么意思| 儒家思想是什么意思| 家用制氧机什么牌子好| 肾小球滤过率偏高说明什么| 人彘为什么还能活着| 鼻子旁边的痣代表什么| 什么叫多重耐药菌| 梦见怀孕流产是什么意思| 心里发慌什么原因| 乔木是什么意思| 嘴里起血泡是什么原因| 七月十日是什么日子| 美国为什么制裁伊朗| 祸水什么意思| 肚脐眼上面疼是什么原因| 仓鼠怀孕有什么特征| canon是什么意思| 梦见玫瑰花是什么预兆| 思源名字的寓意是什么| 大三阳是什么意思| 嗣子是什么意思| npc是什么意思啊| 三手烟是什么意思| 月经不调去医院要做什么检查| 无痛人流和普通人流有什么区别| im是什么| 什么的落日| ms是什么病| 什么感冒药效果最好| 嗓子疼感冒吃什么药| 喝完酒吃什么解酒最快| 猫传腹是什么病| 吃什么东西会误测怀孕| 站着说话不腰疼是什么意思| 虚有其表的意思是什么| 胃疼想吐是什么原因| 什么花能吃| 探囊取物是什么意思| 十一月份是什么星座| 孟德是什么意思| 阑尾炎痛起来什么感觉| 犯病是什么意思| 什么筷子好| 内分泌失调吃什么药好| 无头鱼是什么鱼| 95年是什么年| 将军是什么军衔| 寡情是什么意思| 什么金属最硬| 三聚磷酸钠是什么东西| 左眼皮肿是什么原因引起的| 虫可念什么| 一月十八是什么星座| 蒹葭苍苍是什么意思| 脚抽筋是什么原因引起的| eno什么意思| 派特ct主要检查什么| 维生素e吃多了有什么副作用| 病字旁加且念什么| 孕吐最早什么时候开始| 吃什么补肝| 边缘化是什么意思| 歪果仁是什么意思| 眼睑痉挛挂什么科| 神经性头疼吃什么药好| 替拉依是什么药| 伤寒病有什么症状| 什么人容易得精神病| 廉洁奉公是什么意思| 蚂蚁咬了用什么药| 吃什么东西补血快| 手指缝痒是什么原因| 什么是胃溃疡| 助教是干什么的| 控告是什么意思| 纪年是什么意思| 女人左下巴有痣代表什么| 廿读什么| 黄芪的读音是什么| 膀胱炎吃什么药好得快| 百度

------------------------------------------------------------------------------------
--                                   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)
	return type(v) == 'number' and v >= 1 and floor(v) == v and v < infinity
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)
	return type(v) == 'number' and v ~= v
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)
	checkType('shallowClone', 1, t, 'table')
	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(arr)
	checkType('removeDuplicates', 1, arr, 'table')
	local isNan = p.isNan
	local ret, exists = {}, {}
	for _, v in ipairs(arr) 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
		elseif not exists[v] then
			ret[#ret + 1] = v
			exists[v] = true
		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 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.
		return s:gsub('([%(%)%%%.%[%]%*%+%-%?%^%$])', '%%%1')
	end

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

	local nums = {}
	for k 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 _ 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
	elseif type1 == 'table' or type1 == 'boolean' or type1 == 'function' then
		return tostring(item1) < tostring(item2)
	else
		return item1 < item2
	end
end
------------------------------------------------------------------------------------
-- keysToList
--
-- Returns an array 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 arr = {}
	local index = 1
	for k in pairs(t) do
		arr[index] = k
		index = index + 1
	end

	if keySort ~= false then
		keySort = type(keySort) == 'function' and keySort or defaultKeySort
		table.sort(arr, keySort)
	end

	return arr
end

------------------------------------------------------------------------------------
-- sortedPairs
--
-- 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 arr = p.keysToList(t, keySort, true)

	local i = 0
	return function ()
		i = i + 1
		local key = arr[i]
		if key ~= nil then
			return key, t[key]
		else
			return nil, nil
		end
	end
end

------------------------------------------------------------------------------------
-- isArray
--
-- Returns true if the given value is a table and all keys are consecutive
-- integers starting at 1.
------------------------------------------------------------------------------------
function p.isArray(v)
	if type(v) ~= 'table' then
		return false
	end
	local i = 0
	for _ in pairs(v) do
		i = i + 1
		if v[i] == nil then
			return false
		end
	end
	return true
end

------------------------------------------------------------------------------------
-- isArrayLike
--
-- Returns true if the given value is iterable and all keys are consecutive
-- integers starting at 1.
------------------------------------------------------------------------------------
function p.isArrayLike(v)
	if not pcall(pairs, v) then
		return false
	end
	local i = 0
	for _ in pairs(v) do
		i = i + 1
		if v[i] == nil then
			return false
		end
	end
	return true
end

------------------------------------------------------------------------------------
-- invert
--
-- Transposes the keys and values in an array. For example, {"a", "b", "c"} ->
-- {a = 1, b = 2, c = 3}. Duplicates are not supported (result values refer to
-- the index of the last duplicate) and NaN values are ignored.
------------------------------------------------------------------------------------
function p.invert(arr)
	checkType("invert", 1, arr, "table")
	local isNan = p.isNan
	local map = {}
	for i, v in ipairs(arr) do
		if not isNan(v) then
			map[v] = i
		end
	end

	return map
end

------------------------------------------------------------------------------------
-- listToSet
--
-- Creates a set from the array part of the table. Indexing the set by any of the
-- values of the array returns true. For example, {"a", "b", "c"} ->
-- {a = true, b = true, c = true}. NaN values are ignored as Lua considers them
-- never equal to any value (including other NaNs or even themselves).
------------------------------------------------------------------------------------
function p.listToSet(arr)
	checkType("listToSet", 1, arr, "table")
	local isNan = p.isNan
	local set = {}
	for _, v in ipairs(arr) do
		if not isNan(v) then
			set[v] = true
		end
	end

	return set
end

------------------------------------------------------------------------------------
-- deepCopy
--
-- Recursive deep copy function. Preserves identities of subtables.
------------------------------------------------------------------------------------
local function _deepCopy(orig, includeMetatable, already_seen)
	if type(orig) ~= "table" then
		return orig
	end
	
	-- already_seen stores copies of tables indexed by the original table.
	local copy = already_seen[orig]
	if copy ~= nil then
		return copy
	end
	
	copy = {}
	already_seen[orig] = copy -- memoize before any recursion, to avoid infinite loops
	
	for orig_key, orig_value in pairs(orig) do
		copy[_deepCopy(orig_key, includeMetatable, already_seen)] = _deepCopy(orig_value, includeMetatable, already_seen)
	end
	
	if includeMetatable then
		local mt = getmetatable(orig)
		if mt ~= nil then
			setmetatable(copy, _deepCopy(mt, true, already_seen))
		end
	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 or {})
end

------------------------------------------------------------------------------------
-- sparseConcat
--
-- 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 arr = {}

	local arr_i = 0
	for _, v in p.sparseIpairs(t) do
		arr_i = arr_i + 1
		arr[arr_i] = v
	end

	return table.concat(arr, sep, i, j)
end

------------------------------------------------------------------------------------
-- length
--
-- Finds the length of an array, or of a quasi-array with keys such as "data1",
-- "data2", etc., using an exponential search algorithm. 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, prefix)
	-- requiring module inline so that [[Module:Exponential search]] which is
	-- only needed by this one function doesn't get millions of transclusions
	local expSearch = require("Module:Exponential search")
	checkType('length', 1, t, 'table')
	checkType('length', 2, prefix, 'string', true)
	return expSearch(function (i)
		local key
		if prefix then
			key = prefix .. tostring(i)
		else
			key = i
		end
		return t[key] ~= nil
	end) or 0
end

------------------------------------------------------------------------------------
-- inArray
--
-- Returns true if searchElement is a member of the array, and false otherwise.
-- Equivalent to JavaScript array.includes(searchElement) or
-- array.includes(searchElement, fromIndex), except fromIndex is 1 indexed
------------------------------------------------------------------------------------
function p.inArray(array, searchElement, fromIndex)
	checkType("inArray", 1, array, "table")
	-- if searchElement is nil, error?

	fromIndex = tonumber(fromIndex)
	if fromIndex then
		if (fromIndex < 0) then
			fromIndex = #array + fromIndex + 1
		end
		if fromIndex < 1 then fromIndex = 1 end
		for _, v in ipairs({unpack(array, fromIndex)}) do
			if v == searchElement then
				return true
			end
		end
	else
		for _, v in pairs(array) do
			if v == searchElement then
				return true
			end
		end
	end
	return false
end

------------------------------------------------------------------------------------
-- merge
--
-- Given the arrays, returns an array containing the elements of each input array
-- in sequence.
------------------------------------------------------------------------------------
function p.merge(...)
	local arrays = {...}
	local ret = {}
	for i, arr in ipairs(arrays) do
		checkType('merge', i, arr, 'table')
		for _, v in ipairs(arr) do
			ret[#ret + 1] = v
		end
	end
	return ret
end

------------------------------------------------------------------------------------
-- extend
--
-- Extends the first array in place by appending all elements from the second
-- array.
------------------------------------------------------------------------------------
function p.extend(arr1, arr2)
	checkType('extend', 1, arr1, 'table')
	checkType('extend', 2, arr2, 'table')

	for _, v in ipairs(arr2) do
		arr1[#arr1 + 1] = v
	end
end

return p
西施姓什么 呵呵的含义是什么意思 阴唇是什么颜色 不自觉是什么意思 天秤座和什么座最配对
脚底抽筋是什么原因引起的 胃疼能吃什么水果 吃什么对眼睛近视好 你太low了是什么意思 备孕不能吃什么
雷诺氏病是一种什么病 热毒吃什么药好得快 光是什么颜色 胸口痛吃什么药 觉悟是什么意思
巳是什么意思 什么是朱砂 晚上咳嗽什么原因 脖子疼什么原因 宝宝反复发烧是什么原因
玉和翡翠有什么区别0735v.com 空心菜又叫什么菜hcv8jop1ns7r.cn 内科检查什么wuhaiwuya.com 明前茶和明后茶有什么区别hcv9jop5ns6r.cn npc是什么意思xscnpatent.com
前胸出汗多是什么原因hcv8jop0ns2r.cn 孤独症是什么hcv7jop5ns2r.cn 张家界地貌属于什么地貌xinjiangjialails.com 正畸和矫正有什么区别hcv8jop8ns3r.cn 今天什么生肖冲什么生肖hcv8jop2ns1r.cn
盆腔炎吃什么消炎药效果好hcv8jop5ns6r.cn 办护照需要准备什么材料hcv8jop2ns3r.cn 闭麦是什么意思hcv8jop5ns1r.cn 来源朋友验证消息是什么意思hcv9jop6ns8r.cn 送男人什么礼物最难忘hcv7jop9ns8r.cn
pr是什么意思hcv8jop2ns7r.cn 1992年属猴的是什么命xscnpatent.com 喝牛奶什么时候喝最好hcv9jop2ns8r.cn 什么人不适合做厨师hcv8jop6ns4r.cn 灰菜有什么功效与作用aiwuzhiyu.com
百度