豆是什么结构| 小孩为什么会细菌感染| 睡觉起来脸肿是什么原因引起的| 什么日什么秋| 朱祁镇为什么杀于谦| 不全纵隔子宫是什么意思| 为什么精液是黄色的| 酮体是什么| 晚上八点半是什么时辰| 尿蛋白是什么病| 没有美瞳护理液用什么代替| 女性乳房痒是什么原因| 女人做春梦预示着什么| 耳鸣脑鸣是什么原因引起的| 尿酸升高是什么原因| 什么是动态口令| 月加一笔是什么字| 乳糖不耐受是什么症状| 蓝精灵是什么意思| 媾是什么意思| 载脂蛋白a1偏高是什么原因| 吃什么排毒| 胃火吃什么药| 头孢和什么不能一起吃| 梦见自己吃面条是什么意思| 宁静什么意思| 胃疼去医院挂什么科| 大肠炒什么菜好吃| 局座是什么梗| 为什么大便是绿色的| out什么意思| feno是什么检查| 公安局跟派出所有什么区别| 精子长什么样| 梦见红鞋子是什么意思| ppi是什么意思| 率性是什么意思| 辗转什么意思| 假牛肉干是什么做的| 1992年属猴的是什么命| 12月16号是什么星座| 青海有什么特产| 美国为什么不敢打朝鲜| 头晕做什么检查| 什么像什么又像什么| 困难的反义词是什么| 不胜什么| 胸膜炎吃什么药好| 绒毛浆是什么| 大男子主义是什么意思| 两个马念什么字| 你什么意思| 白带发黄有异味用什么药| 无花果有什么营养| 白玉兰奖是什么级别的| 乳糖不耐受是什么症状| 喉软骨发育不良有什么症状| 下连是什么意思| 窦性心律过速是什么意思| 河马吃什么| 欲言又止什么意思| 情人节送什么给女孩子| 网是什么结构的字| 二氧化硅是什么氧化物| barbour是什么牌子| 血红蛋白低说明什么| 胎神什么意思| 溲黄是什么意思| 大连六院是什么医院| 妇女是什么意思| 什么是肺结节| 白细胞是什么意思| 爱理不理是什么意思| 经常腰酸是什么原因女性| 晨勃消失是什么原因| 前列腺素是什么| 什么样的青蛙| 冲床工是做什么的| 酱油是什么时候发明的| 什么是周记| 为什么会发烧| 青海湖里面有什么鱼| 什么叫肺大泡| 肠胃炎饮食要注意什么| 情何以堪是什么意思| 器质性疾病是什么意思| 什么东西能让皮肤变白| 脾胃虚弱有什么症状| 纤维硬结灶是什么意思| 996是什么| 人为什么会失眠| 前列腺钙化什么意思| 经常拉肚子什么原因| 桢字五行属什么| 繁花似锦是什么意思| 什么的寒冷| 更年期出汗吃什么药好| 小便憋不住尿裤子是什么情况| 梦见锁门是什么意思| 紫苏是什么| 市场部是做什么的| 早餐吃什么不会胖| 名落孙山的意思是什么| 什么东西清肺最好| 肌酐偏低是什么原因| 草头是什么菜| 全麦是什么意思| 小蛮腰是什么意思| 芹菜什么时候种| 火花是什么| 脚背浮肿是什么原因引起的| 均码是什么意思| 喉咙有异物感挂什么科| 舌头伸不出来是什么原因| 丰富的近义词和反义词是什么| 宫颈糜烂用什么药好| 睡觉打呼噜什么原因| 九月有什么节日| 芋头什么时候种植最好| 儿童吃什么钙片补钙效果好| 咳嗽咳出血是什么原因| 母胎单身是什么意思| 耿直是什么意思| 下面痒用什么药| 嘴角烂了擦什么药| 大红袍茶属于什么茶| lop胎位是什么意思| 三个又读什么| 劫持是什么意思| 什么食粮| 太阳线是什么意思| 主治医师是什么级别| 去拉萨需要准备什么| 潜血弱阳性什么意思| 尿失禁是什么意思| ab型血和b型血生的孩子是什么血型| poison是什么意思| 以貌取人是什么意思| 网调是什么意思| 皮下出血点是什么原因| 高筋面粉可以做什么| 嗓子疼发烧吃什么药| 鱼吃什么| 孩子注意力不集中缺什么微量元素| 婵字五行属什么| 坠积效应是什么意思| 什么食物可以化解结石| 什么是灰指甲| 肝损伤是怎么回事什么是肝损伤| 手淫过度有什么症状| 活性炭和木炭有什么区别| 什么的李逵| 总打嗝吃什么药| 打牙祭是什么意思| 减肥不能吃什么东西| 南红五行属什么| 小便尿不出来什么原因| 男人交公粮什么意思| 更年期失眠吃什么药| 遁形是什么意思| 女人胆固醇高什么原因| 什么病不能吃核桃| 中国是什么国家| 双侧甲状腺弥漫病变是什么意思| 血压高吃什么菜和水果能降血压| 牛肉和什么菜炒好吃| 薄荷有什么功效| 发烧拉稀是什么原因| 二姨子是什么意思| pass掉是什么意思| 八十岁叫什么之年| 花开两朵各表一枝什么意思| 腊八粥是什么节日| 木瓜是什么季节的| 秦朝灭亡后是什么朝代| 荠菜长什么样子图片| 自来卷的头发适合什么发型| 喝啤酒头疼是什么原因| 永浴爱河是什么意思| 灌肠是什么感觉| 闪亮的什么| 夭折是什么意思| 耽美剧是什么意思| 心脏五行属什么| 心是什么意思| 什么星座最花心| 为什么会堵奶| 孟子姓什么| 楚乔传2什么时候上映| 老人不睡觉是什么预兆| 皮疹是什么症状| 什么样才是包皮| 风寒感冒吃什么药| 炮制是什么意思| 高手过招下一句是什么| 喜五行属什么| 衍生物是什么意思| 嘴里发咸是什么原因| 鼻毛变白是什么原因| ce是什么意思| 幼犬拉稀吃什么药最好| 北京古代叫什么| edd是什么意思| 左胸下面是什么部位| sad什么意思| 大黄米和小黄米有什么区别| 吃荆芥有什么好处| 心脏是什么组织| 肛裂是什么感觉| 牙痛是什么原因引起的| emba是什么| 缺钠有什么症状和危害| 心胆气虚吃什么中成药| 护理是什么| 想呕吐是什么原因| 尼姑庵是什么意思| 超声波是什么意思| 知天命是什么年纪| 节食是什么意思| 5月9号什么星座| 右附件区囊肿是什么意思| 苋菜长什么样| 什么发色显白| 角质层是什么| 做梦梦见掉牙齿是什么意思| 什么样的情况下会怀孕| 手脱皮用什么药好得快| 喝什么对嗓子好| 奴才模样是什么生肖| 外阴瘙痒用什么洗液| a和ab型生的孩子是什么血型| 梦到屎是什么意思| 充饥是什么意思| 什么是疱疹怎么得的| 剖腹产什么时候可以洗澡| captain是什么意思| 肌酐300多属于什么期| 肺结核是什么| 吃榴莲有什么好处和坏处| 骨髓不造血是什么病| 肠镜前一天可以吃什么| 寄居蟹吃什么食物| 牛仔裙配什么上衣好看| 痛风吃什么比较好| 脸上长黑斑是什么原因引起的| 痛经吃什么止疼药| 螚什么意思| 副词什么意思| 折煞是什么意思| 头发麻是什么病的前兆| 拜谒是什么意思| 眼帘是什么意思| 三个火是什么字念什么| 眼睛视物模糊是什么原因| 什么是脑卒中| 风水宝地是什么生肖| 磨玻璃影是什么意思| 直辖市是什么级别| 承认是什么意思| 寡情是什么意思| 背叛什么意思| 孕妇吃什么最好| 降血压喝什么茶| 长期熬夜吃什么可以补回来| 百度Jump to content

斯巴鲁因高田气囊扩大召回范围 大陆涉及近15

Got?wa go 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

[edit source]

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

local TableTools = require('Module:TableTools')

isPositiveInteger

[edit source]
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.

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

[edit source]
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

[edit source]
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

[edit source]
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

[edit source]
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

[edit source]
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

[edit source]
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

[edit source]
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.

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

[edit source]
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

[edit source]
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

[edit source]
TableTools.isArray(value)

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

isArrayLike

[edit source]
TableTools.isArrayLike(value)

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

invert

[edit source]
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

[edit source]
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 }?. See also Module:Lua set for more advanced ways to create a set.

deepCopy

[edit source]
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

[edit source]
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

[edit source]
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

[edit source]
TableTools.inArray(arr, valueToFind)

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


------------------------------------------------------------------------------------
--                                   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
		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 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)
	-- 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

------------------------------------------------------------------------------------
-- 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 valueToFind is a member of the array, and false otherwise.
------------------------------------------------------------------------------------
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
斯里兰卡属于什么国家 突然流鼻血是什么原因 做梦梦到钱是什么预兆 茶宠为什么会变色 三级综合医院是什么意思
脑膜炎有什么症状 1964年是什么年 明朝北京叫什么 梦见玫瑰花是什么预兆 彼岸花代表什么星座
植脂末是什么东西 乌鸡煲汤放什么材料 中指和无名指发麻是什么原因 宝宝吃益生菌有什么好处和坏处 医学五行属什么
双鱼座和什么星座最配 为什么突然有狐臭了 体质指数是什么意思 老蜜蜡什么颜色最好 尿频尿不尽吃什么药
湿气重有什么表现症状hcv9jop5ns7r.cn 肝左叶囊性灶什么意思hcv9jop6ns0r.cn 虫合读什么beikeqingting.com 法国的货币叫什么hcv8jop2ns3r.cn 滑石粉有什么作用hcv8jop2ns6r.cn
晚上7点到9点是什么时辰hcv8jop9ns5r.cn 吃马齿苋有什么好处hcv8jop3ns9r.cn 蓦然是什么意思hcv7jop6ns6r.cn 孙策和孙权什么关系hcv9jop0ns9r.cn 宫保鸡丁是什么菜系hcv7jop7ns1r.cn
柠檬吃多了有什么坏处hcv9jop3ns8r.cn 眉毛淡的男人代表什么hebeidezhi.com 新生儿晚上哭闹不睡觉是什么原因hcv9jop6ns5r.cn 治疗幽门螺杆菌用什么药效果最好hcv7jop4ns6r.cn 抑郁症挂什么科hcv9jop3ns5r.cn
刷牙时牙酸是什么原因hcv8jop6ns0r.cn 属牛的生什么属相的孩子好hcv7jop6ns3r.cn 活好的女人有什么表现hkuteam.com 微针是什么hcv8jop4ns5r.cn edc是什么hcv8jop1ns8r.cn
百度