干净的反义词是什么| 什么烟比较好抽| 为什么阴道会放气| 看金鱼是什么梗| 什么是埋线双眼皮| 男性硬下疳是什么样子| 缺碘吃什么| 吃什么壮阳补肾| 轴距是什么意思| 心博是什么意思| zoom 是什么意思| 第二性征是什么意思| 深度睡眠是什么意思| 肾小球滤过率偏高说明什么| 7.23是什么星座| 关二爷是什么神| 界定是什么意思| 夏天脚底冰凉是什么原因| 3p是什么意思| 蚂蚁上树什么意思| 减肥期间可以吃什么水果| 花甲是什么意思| 心静自然凉是什么意思| 什么是大健康产业| jeep衣服什么档次| 胃恶心想吐是什么原因| 隐翅虫咬了用什么药| 寒食节是什么意思| 外阴瘙痒吃什么药| 上海有什么好玩的地方适合小孩子| 认真是什么意思| 尿素氮偏低是什么意思| his系统是什么| 蓦然是什么意思| 冬季吃什么| 草菅人命是什么意思| 鹅蛋脸适合什么刘海| 喝什么茶对睡眠有帮助| 十月十二号是什么星座| 牛虻是什么| 1997是什么年| 十二月二号是什么星座| 俗不可耐是什么意思| 后背酸疼是什么原因| 请大家知悉是什么意思| 尿黄是什么原因引起的| 青少年吃什么钙片有助于长高| 阴道炎吃什么药| 曹字五行属什么| 加尿素起什么作用| 戊肝是什么病| eis是什么意思| 琛读什么| 芒果不能和什么食物一起吃| 高烧用什么方法降温最快| md是什么牌子| 意象是什么| 梦见流水是什么征兆| 亥时右眼跳是什么预兆| 义字少一点念什么| 鸡血藤有什么作用| bs是什么意思| 结扎对女人有什么伤害| 泌尿系统感染吃什么药| 头晕脑胀吃什么药| 什么萌| 口甲读什么| 夜里咳嗽是什么原因| 有什么好看的美剧| 汤姆福特属于什么档次| 谛听是什么| darling什么意思| 9-11点是什么时辰| 腋毛脱落是什么原因| 淋巴结是什么| 不动明王是什么属相的本命佛| 虚岁27岁属什么生肖| 宫颈纳囊什么意思| 项链突然断了预示什么| 唐字五行属什么| 鼻后滴漏吃什么药| 口腔溃疡是什么原因引起的| 沙蚕是什么动物| 肾不好有什么症状| 褒义是什么意思| 手掌纹路多且杂乱是为什么| 机位是什么意思| 害怕什么| 甘甜是什么意思| 怀孕有积液是什么原因| 腺肌症是什么症状| 见路不走是什么意思| 铜锣湾有什么好玩的| 脑膜炎有什么症状| 喝什么茶叶减肥效果最好| 急性荨麻疹不能吃什么食物| 口臭挂什么科| 为什么头晕| 癸未日五行属什么| pink是什么颜色| 不但而且是什么关系| 虾皮是什么虾| 鸟吃什么食物| 什么叫血栓| 大便为什么是绿色的| 天上的星星为什么会发光| 医托是什么意思| 手指经常抽筋是什么原因| 浪琴军旗什么档次| 81年属鸡的是什么命| 棚户区改造和拆迁有什么区别| 2043年是什么年| 急性肠胃炎吃什么药效果好| 什么的金边| 什么的孩子| 胃子老是胀气是什么原因| nsaids是什么药| 脑浆是什么颜色| 太阳花是什么花| 锦纶是什么| 自慰什么意思| 艾滋病是什么引起的| 皇帝的新装是什么意思| 葡萄糖氯化钠注射作用是什么| 腿上长痣代表什么| 增加性功能吃什么药| 美工是做什么的| 肉桂是什么茶| 遥不可及什么意思| 八髎区疼是什么原因| 格格不入什么意思| 梦见好多虫子是什么意思| 警察和公安有什么区别| 夏天吃什么养生| 苦瓜吃多了有什么坏处| 尤文氏肉瘤是什么病| 脸上涂什么可以美白| crab是什么意思| 脯氨酸氨基肽酶阳性是什么意思| 喝中药为什么会拉肚子| 翻身是什么意思| ige是什么意思| 房颤挂什么科| 反胃是什么意思| 什么的绿叶| 诺贝尔奖为什么没有数学奖| 悉如外人的悉是什么意思| 奶酪和芝士有什么区别| 什么药清肺最好| 吃素对身体有什么好处| 啃手指甲是什么毛病| 牛筋草有什么作用| 结婚一年是什么婚| 四月初八是什么日子| 细胞骨架是由什么构成| 什么犹如什么造句| 拜土地公要准备什么东西| 肚子胀胀的是什么原因| 睡着了咳嗽是什么原因| 什么花草| 南昌有什么好玩的景点| 什么动作容易怀孕| 命途多舛是什么意思| 肺气囊是什么病| 木棉花的花语是什么| 什么颜色加什么颜色等于黑色| 福禄寿的禄是什么意思| 什么叫埋下伏笔| 启字五行属什么| 乙肝抗体是什么意思| 棉毛布是什么面料| 我国计划生育什么时候开始| iris是什么意思啊| 蒂芙尼算什么档次| 白头发吃什么可以改善| 流鼻血是什么原因引起的| 右下腹疼痛什么原因| 山竹有什么好处| 什么叫腱鞘炎| 结缔组织病是什么病| 晚上11点到12点是什么时辰| 指鹿为马指什么生肖| nf是什么| 莫名是什么意思| 福州立冬吃什么| 梅花什么时候开| 火碱对人体有什么害处| 省委组织部长是什么级别| 浅卡其色裤子配什么颜色上衣| 淋巴结挂什么科| 婴儿什么时候开始说话| 六个点是什么意思| 什么军官可以随身配枪| 乙肝携带者是什么意思| 闭日是什么意思| 6月出生是什么星座| 什么叫间质性肺病| 985大学什么意思| 脚踏一星是什么命| 耳朵烧是什么原因| 烧仙草是什么植物| 升结肠憩室是什么意思| 木字旁的字与什么有关| b超涂的液体是什么| 做梦钓到大鱼什么意思| 双肺纹理增强是什么意思| 早教是做什么的| 左手有点麻是什么原因| 蜂蜜加柠檬有什么功效和作用| 女s是什么| 黄宗洛黄海波什么关系| 可怜巴巴的意思是什么| 什么时候着床| 黄金为什么这么贵| 摸头杀是什么意思| foreverlove是什么意思| 午餐肉是什么肉| 流产挂什么科| 囊性结构是什么意思| 老年人口干是什么原因| 湿气重喝什么| 江西古代叫什么| 事物指的是什么| 2009年是什么年| 3.3是什么星座| 拿什么证明分居两年| 菠萝有什么功效和作用| 什么是小奶狗| lv是什么意思| 衬衫搭配什么裤子好看| 做胃镜前要注意什么| 黑色加什么颜色是棕色| 儿童经常流鼻血什么原因造成的| 碘伏过敏是什么症状| 口蜜什么剑| 紫颠是什么病怎样治| 七十岁老人装什么牙合适| 千里马比喻什么人| 亚麻是什么| 什么东西蛋白质含量高| 港澳通行证办理需要什么材料| 首长是什么意思| 室缺是什么意思| 满身红点是什么病| 结核杆菌dna检测是检查什么| 高抬贵手是什么意思| 红细胞体积偏高是什么意思| 嘴唇发麻什么病兆| 头痛是什么原因| 阁老相当于现在什么官| 童子是什么意思| 为什么医生爱开喜炎平| 缺钾吃什么补| 白细胞中性粒细胞高是什么原因| 宫颈活检lsil是什么病| 壳心念什么| 农历5月20日是什么星座| 洁身自爱是什么生肖| 血糖高要忌口什么| 任正非用的什么手机| 胃寒吃什么可以暖胃| 一什么沙滩| 洋葱有什么功效与作用| 徒孙是什么意思| 百度Jump to content

新华网评:中国特色大国外交激荡世界

Wikipedia ???
百度 ”北京结核病控制研究所防控科主任高志东介绍,在人口密集场所,如果传染性肺结核患者长期滞留,存在结核病聚集性发病的风险。

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.

Loading the module

[??????]

To use any of the functions, first you must load the module.

local TableTools = require('Module:TableTools')

isPositiveInteger

[??????]
TableTools.isPositiveInteger(value)

Returns true if 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.

isNan

[??????]
TableTools.isNan(value)

Returns true if value 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 value is used as a table key.)

shallowClone

[??????]
TableTools.shallowClone(t)

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. If you want to make a new table with no shared subtables and with metatables transferred, you can use mw.clone instead. If you want to make a new table with no shared subtables and without metatables transferred, use deepCopy with the noMetatable option.

removeDuplicates

[??????]
TableTools.removeDuplicates(t)

Removes duplicate values from an array. This function is only designed to work with standard arrays: keys that are not positive integers are ignored, as are all values after the first nil value. (For arrays containing nil values, you can use compressSparseArray first.) The function tries to preserve the order of the array: the earliest non-unique value is kept, and all subsequent duplicate values are removed. For example, for the table {5, 4, 4, 3, 4, 2, 2, 1} removeDuplicates will return {5, 4, 3, 2, 1}.

numKeys

[??????]
TableTools.numKeys(t)

Takes a table t and returns an array containing the numbers of any positive integer keys that have non-nil values, sorted in numerical order. For example, for the table {'foo', nil, 'bar', 'baz', a = 'b'}, numKeys will return {1, 3, 4}.

affixNums

[??????]
TableTools.affixNums(t, prefix, suffix)

Takes a table t and returns an array containing the numbers of keys with the optional prefix prefix and the optional suffix suffix. For example, for the table {a1 = 'foo', a3 = 'bar', a6 = 'baz'} and the prefix 'a', affixNums will return {1, 3, 6}. All characters in prefix and suffix are interpreted literally.

numData

[??????]
TableTools.numData(t, compress)

Given a table with keys like "foo1", "bar1", "foo2", and "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.

compressSparseArray

[??????]
TableTools.compressSparseArray(t)

Takes an array t 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. Any keys that are not positive integers are removed. For example, for the table {1, nil, foo = 'bar', 3, 2}, compressSparseArray will return {1, 3, 2}.

sparseIpairs

[??????]
TableTools.sparseIpairs(t)

This is an iterator function for traversing a sparse array t. It is similar to ipairs, but will continue to iterate until the highest numerical key, whereas ipairs may stop after the first nil value. Any keys that are not positive integers are ignored.

Usually sparseIpairs is used in a generic for loop.

for i, v in TableTools.sparseIpairs(t) do
   -- code block
end

Note that sparseIpairs uses the pairs function in its implementation. Although some table keys appear to be ignored, all table keys are accessed when it is run.

size

[??????]
TableTools.size(t)

Finds the size of a key/value pair table. For example, for the table {foo = 'foo', bar = 'bar'}, size will return 2. The function will also work on arrays, but for arrays it is more efficient to use the # operator. Note that to find the table size, this function uses the pairs function to iterate through all of the table keys.

keysToList

[??????]
TableTools.keysToList(t, keySort, checked)

Returns a list of the keys in a table, sorted using either a default comparison function or a custom keySort function, which follows the same rules as the comp function supplied to table.sort. If keySort is false, no sorting is done. Set checked to true to skip the internal type checking.

sortedPairs

[??????]
TableTools.sortedPairs(t, keySort)

Iterates through a table, with the keys sorted using the keysToList function. If there are only numerical keys, sparseIpairs is probably more efficient.

isArray

[??????]
TableTools.isArray(value)

Returns true if value is a table and all keys are consecutive integers starting at 1.

isArrayLike

[??????]
TableTools.isArrayLike(value)

Returns true if value is iterable and all keys are consecutive integers starting at 1.

invert

[??????]
TableTools.invert(arr)

Transposes the keys and values in an array. For example, invert{ "a", "b", "c" } yields { a=1, b=2, c=3 }.

listToSet

[??????]
TableTools.listToSet(arr)

Creates a set from the array part of the table arr. Indexing the set by any of the values of the array returns true. For example, listToSet{ "a", "b", "c" } yields { a=true, b=true, c=true }.

deepCopy

[??????]
TableTools.deepCopy(orig, noMetatable, alreadySeen)

Creates a copy of the table orig. As with mw.clone, all values that are not functions are duplicated and the identity of tables is preserved. If noMetatable is true, then the metatable (if any) is not copied. Can copy tables loaded with mw.loadData.

Similar to mw.clone, but mw.clone cannot copy tables loaded with mw.loadData and does not allow metatables not to be copied.

sparseConcat

[??????]
TableTools.sparseConcat(t, sep, i, j)

Concatenates all values in the table that are indexed by a positive integer, in order. For example, sparseConcat{ "a", nil, "c", "d" } yields "acd" and sparseConcat{ nil, "b", "c", "d" } yields "bcd".

length

[??????]
TableTools.length(t, prefix)

Finds the length of an array or of a quasi-array with keys with an optional prefix such as "data1", "data2", etc. It uses an exponential search algorithm to find the length, so as to use as few table lookups as possible.

This algorithm is useful for arrays that use metatables (e.g. frame.args) and for quasi-arrays. For normal arrays, just use the # operator, as it is implemented in C and will be quicker.

inArray

[??????]
TableTools.inArray(arr, valueToFind)

Returns true if valueToFind is a member of the array arr, and false otherwise.

merge

[??????]
TableTools.merge(...)

Given the arrays, returns an array containing the elements of each input array in sequence.

extend

[??????]
TableTools.extend(arr1, arr2)

Extends the first array in place by appending all elements from the second array.

See also

[??????]

------------------------------------------------------------------------------------
--                                   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
pm什么意思 橄榄色是什么颜色 什么原因导致胎停 火疖子是什么引起的 螯合是什么意思
计生用品是什么 为什么人会做梦 午火是什么火 梦见摘水果是什么意思 摩羯座哭了代表什么
肚脐眼臭是什么原因 为什么会尿道感染 睡眠障碍吃什么药最好 吃什么对肝好 汗疱疹用什么药好
什么叫精索静脉曲张啊 病毒性扁桃体炎吃什么药 至少是什么意思 间接是什么意思 上腹疼是什么原因
植鞣皮是什么皮hcv8jop4ns1r.cn 一九九八年属什么生肖cl108k.com 什么地端详hcv8jop1ns7r.cn 太阳穴长痘痘是什么原因hcv8jop2ns9r.cn 端水是什么意思hcv7jop9ns7r.cn
出的汗是凉的什么原因hcv9jop0ns4r.cn 心脏痛吃什么药效果好hcv9jop7ns1r.cn 肾炎是什么症状hcv9jop7ns4r.cn 斗战胜佛是什么意思hcv9jop0ns0r.cn 智商120是什么水平hcv8jop4ns3r.cn
心绞痛吃什么药inbungee.com 女性尿道口有小疙瘩是什么原因hcv8jop6ns6r.cn 澳门用什么钱币hcv9jop5ns4r.cn 例假量多是什么原因hcv8jop0ns9r.cn 热毒是什么hcv9jop4ns4r.cn
有机食品什么意思hcv9jop3ns7r.cn 颌下腺肿大是什么原因hcv9jop2ns0r.cn 鸡蛋胶是什么鱼胶hcv9jop2ns8r.cn 女子是什么意思hcv7jop9ns5r.cn 吃什么能降血糖bjhyzcsm.com
百度