胸为什么会胀痛| 意念是什么意思| 特应性皮炎是什么| 火龙果是什么颜色| cdr是什么意思| 乌合之众什么意思| 细菌性阴道炎用什么洗液| 脑门发黑是什么原因| 足跟痛用什么药| 播客是什么意思| 棘人是什么意思| 9月份怀孕预产期是什么时候| 雯字五行属什么| 桑蚕丝是什么面料| 八股是什么意思| 肩颈疼痛挂什么科| siri什么意思| 拉肚子不能吃什么食物| 为什么南极比北极冷| 什么叫骨折| sigma是什么牌子| 公分是什么| 贫血吃什么东西好| 女人吃什么越来越年轻| 什么是超七水晶| 老年人腿脚无力是什么原因| 牢固的近义词是什么| 心脏不舒服吃什么药| 喝太多水对身体有什么影响| gtp是什么| 什么丝什么缕| 上火吃什么水果降火快| 肛瘘是什么病| 母亲是o型血孩子是什么血型| 寒战是什么症状| 猪和什么属相最配| 阴道瘙痒是什么原因造成的| 被告不出庭有什么后果| 生殖细胞是什么| 八月十日是什么星座| 孙悟空原名叫什么| 用什么泡脚减肥最快| 用牙膏洗脸有什么好处和坏处| 大便青黑色是什么原因| 南明为什么打不过清朝| eb病毒iga抗体阳性是什么意思| 梦见鳝鱼是什么预兆| 三焦热盛是什么意思| 96是什么意思| 骂人是什么意思| zorro是什么牌子的打火机| 女人小便出血是什么原因| 4月10日什么星座| 酒后头疼吃什么药| mlb是什么牌子| 荆芥的别名叫什么| 耳根子软是什么意思| 1126是什么星座| 胆囊结石挂什么科| 多囊卵巢综合症是什么原因造成的| 业已毕业是什么意思| 什么是纯净物| 柠檬茶喝了有什么好处| 唐僧真名叫什么| 瘦脸针的危害有什么副作用| 挪揄是什么意思| 左下腹痛是什么原因| 单身为什么中指戴戒指| 液体变固体叫什么| 晚上睡眠不好有什么办法可以解决| 锦衣玉食什么意思| 计数单位是指什么| 肠癌吃什么| 右肾占位是什么意思| 青光眼是什么| 田宅宫是什么意思| 白茶什么样的好| o型血不能和什么血型的人生孩子| 血小板计数是什么意思| 蜈蚣怕什么| 张仲景的著作是什么| 君是什么意思| 咳嗽吃什么好的快偏方| 生命线分叉代表什么| 2月2日是什么星座| 海带和什么菜搭配好吃| 相形见拙什么意思| 沙特用什么货币| 表姐的儿子叫什么| 到底为了什么| 羊鞭是什么部位| 点头之交是什么意思| 结账是什么意思| 梦见牛是什么意思| 男人身体怕冷是什么原因如何调理| 甘胆酸偏高是什么原因| 胆固醇偏高有什么危害| 胆固醇和血脂有什么区别| 什么三什么四| 医学ac是什么意思| 尿潜血十一是什么意思| 重庆五行属什么| 阴唇大什么原因| 老年人吃什么增强免疫力| 吃苦瓜对身体有什么好处| 结节是什么意思| 梦见女鬼是什么意思| 胆囊壁毛糙什么意思| 舌头上火吃什么药| 脚气真菌最怕什么| 籍贯是指什么| 肺疼是什么原因| 硫黄和硫磺有什么区别| 梦见白萝卜是什么意思| 上户口需要什么资料| dm代表什么| 肾积水是什么原因造成的| 心肌炎是什么病严重吗| 尿频尿急尿不尽挂什么科| 死精吃什么能调理成活精| 牙龈有点发黑是什么原因| 水肿吃什么药| 食管ca是什么意思| 嘉靖为什么不杀海瑞| 推杯换盏什么意思| 检查尿液能查出什么病| 梦见乌龟是什么意思| 晨尿有泡沫是什么原因| 结婚25年属于什么婚| 什么时候闰三月| 鼹鼠吃什么| 为什么夏天| 新生儿便秘吃什么好| 桃胶是什么| 痛风吃什么食物好得快| 腋臭手术挂什么科| 血小板偏高有什么危害| 神经炎吃什么药| 为什么有的人招蚊子| 舌头中间裂纹是什么病| 鼻尖出汗是什么原因| 什么然不同| 腰疼吃什么| 千里江陵是什么意思| 总是失眠是什么原因| 1835年属什么生肖| 口比念什么| 眼底出血是什么症状| 入睡困难是什么原因引起的| cima是什么证书| 周瑜是什么生肖| 田野里有什么| 孕晚期白细胞高是什么原因| 头孢什么样子图片| 扁桃体炎吃什么药最好效果好| 大白刁是什么鱼| 月经淋漓不尽吃什么药| 茵是什么意思| 瘦的快是什么原因| 85年属什么生肖| 一个齿一个禹念什么| 肝内强回声是什么意思| 什么叫托特包| 什么叫屈光不正| 17数字代表什么意思| 骨刺是什么| 糖尿病人适合吃什么水果| 刘邦属什么生肖| 什么的鱼| 狗狗湿疹用什么药膏最有效| 滥竽充数的充是什么意思| mp是什么意思| 魔芋粉是什么做的| 糖尿病什么原因引起的| 相敬如宾是什么生肖| 计生用品是什么| 排卵期是指什么时候| 宝宝拉肚子吃什么| alk是什么意思| 蓝精灵是什么意思| 治疗阳痿早泄什么药最好| 歪理是什么意思| 白粉病用什么药| 副团级是什么军衔| 舒张压和收缩压是什么| 天蝎女喜欢什么样的男生| 突如其来什么意思| 包皮炎看什么科| 2015属什么| 灰色裤子配什么上衣好看| 一五行属性是什么| 补钾用什么药| 鼠妇是什么| 吸土是什么意思| 软包是什么意思| 省政协常委是什么级别| 什么杯子不能装水| 叻叻猪是什么意思| 溶血性黄疸是什么原因引起的| 做完人流可以吃什么| 立夏什么时候| 3月5号是什么星座| 湖北属于什么地区| 类固醇是什么东西| 美容美体包括什么项目| 膑是什么意思| 小孩为什么发烧| 早孕有什么反应| 经常放屁是什么原因造成的| 有什么寓言故事| 口水多吃什么药好得快| 送哥们什么礼物好| 取卵后需要注意什么| 6月15日是什么日子| 精索静脉曲张挂什么科| 时令水果是什么意思| btc是什么货币| 栀是什么意思| 小孩子消化不好吃什么调理| 什么是心理健康| 清关什么意思| handmade是什么牌子| 反流性食管炎挂什么科| 髋关节积液是什么原因造成的| 为什么午觉睡醒后头疼| 阴超是什么| 氨纶丝是什么面料| 灵芝泡水喝有什么功效| 六神无主是什么生肖| 什么叫211大学| 县检察长是什么级别| 夜郎自大是什么意思| 盛夏是什么意思| 视力模糊是什么原因| 嗓子哑是什么原因引起的| 越睡越困是什么原因| 处口念什么| 梦见老公怀孕什么预兆| 空调买什么牌子好| 肠胃痉挛什么症状| 尿发绿是什么原因| 本意是什么意思| 说话不清楚是什么原因导致的| 狮子座和什么星座不合| 闭口长什么样子| 幽门螺杆菌感染吃什么药| 便秘和腹泻交替出现是什么意思| 立秋那天吃什么| 固表是什么意思| 为什么会做梦中梦| 黑科技是什么意思| 活珠子是什么| 低gi什么意思| pku什么意思| 米饭配什么菜好吃| 指甲盖有竖纹是什么原因| 运钞车是什么车| 思密达是什么意思| 十点是什么时辰| 郁结是什么意思| 干燥症是什么症状| 油光满面是什么意思| 味素是什么| 阿戈美拉汀片是什么药| 百度Jump to content

隔夜的酒也算酒驾得找个代驾 海沧就有人被抓了

Kufuma Wikipedia
百度 1990年1月4日至8日国务院在北京召开全国经济体制改革工作会议1990年1月4日至8日 国务院在北京召开全国经济体制改革工作会议,讨论以企业改革为重点的1990年改革工作的任务。

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

[kulemba source]

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

local TableTools = require('Module:TableTools')

isPositiveInteger

[kulemba 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

[kulemba 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

[kulemba 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}?.

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

[kulemba 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.

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

[kulemba 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

[kulemba 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

[kulemba 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

[kulemba 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.

TableTools.isArray(value)

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

isArrayLike

[kulemba source]
TableTools.isArrayLike(value)

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

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

[kulemba 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

[kulemba 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

[kulemba 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"?.

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.

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
fox是什么意思 淋巴细胞百分比低是什么意思 肌肉代偿是什么意思 喝大麦茶有什么好处 曹操字什么
串联质谱筛查是什么病 枸杞什么时候吃最好 海是什么颜色 疝气长在什么位置图片 李世民和武则天什么关系
在家无聊可以做什么 天蝎座的幸运色是什么 黄磊为什么不娶刘若英 丙肝病毒抗体阴性是什么意思 4月份有什么节日
阳刚之气是什么意思 舌头变黑是什么原因 晚霞是什么颜色的 无水焗是什么意思 人生的意义是什么
什么的积雪hcv7jop5ns3r.cn 孩子为什么不听话hcv8jop5ns4r.cn 舌苔重是什么原因hcv7jop9ns3r.cn 喉咙有异物感吃什么药hcv9jop7ns4r.cn 牙龈疼是什么原因hcv8jop0ns4r.cn
调味茶和茶有什么区别520myf.com 杨玉环是什么星座zhongyiyatai.com 红色和蓝色混合是什么颜色hcv9jop8ns0r.cn 低压高什么原因导致的hcv9jop6ns0r.cn 乳腺导管扩张是什么意思严重吗hcv8jop2ns1r.cn
什么是梨形身材hcv9jop0ns5r.cn emba是什么hcv9jop8ns0r.cn 翠绿的什么hcv8jop0ns2r.cn 立flag什么意思shenchushe.com 鸡后面是什么生肖hcv9jop0ns1r.cn
今年37岁属什么生肖hcv8jop3ns2r.cn 刚刚邹城出什么大事了hcv9jop6ns2r.cn 左手臂发麻是什么原因hcv9jop6ns0r.cn 浮瓜沉李什么意思hcv7jop4ns7r.cn 梦见来月经是什么意思hcv8jop1ns7r.cn
百度