モジュール:Setのソースを表示
←
モジュール:Set
ナビゲーションに移動
検索に移動
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループに属する利用者のみが実行できます:
登録利用者
。
このページのソースの閲覧やコピーができます。
-- Derivative work of: --[[ (The MIT license) Copyright (c) 2013, Wouter Scherphof (wouter.scherphof@gmail.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] -- Source: https://github.com/wscherphof/lua-set/tree/master/src -- "Straightforward Set library for Lua" local Set = {} Set.mt = {__index = Set} function Set:new(values) if getmetatable(values) == Set.mt then return values end local instance = {} if type(values) == "table" then if #values > 0 then for _,v in ipairs(values) do instance[v] = true end else for k in pairs(values) do instance[k] = true end end elseif values ~= nil then instance = {[values] = true} end return setmetatable(instance, Set.mt) end function Set:add(e) if e ~= nil then self[e] = true end return self end function Set:remove(e) if e ~= nil then self[e] = nil end return self end function Set:anelement() for e in pairs(self) do return e end end -- Union Set.mt.__add = function (a, b) local res, a, b = Set:new(), Set:new(a), Set:new(b) for k in pairs(a) do res[k] = true end for k in pairs(b) do res[k] = true end return res end -- Subtraction Set.mt.__sub = function (a, b) local res, a, b = Set:new(), Set:new(a), Set:new(b) for k in pairs(a) do res[k] = true end for k in pairs(b) do res[k] = nil end return res end -- Intersection Set.mt.__mul = function (a, b) local res, a, b = Set:new(), Set:new(a), Set:new(b) for k in pairs(a) do res[k] = b[k] end return res end -- String representation Set.mt.__tostring = function (set) local s = "{" local sep = "" for k in pairs(set) do s = s .. sep .. k sep = ", " end return s .. "}" end function Set:len() local num = 0 for _ in pairs(self) do num = num + 1 end return num end function Set:tolist() local res = {} for k in pairs(self) do table.insert(res, k) end return res end return Set
このページで使用されているテンプレート:
モジュール:Set/doc
(
ソースを閲覧
)
モジュール:Set
に戻る。
ナビゲーション メニュー
個人用ツール
ログイン
名前空間
モジュール
議論
English
表示
閲覧
履歴表示
その他
検索
案内
索引
脳科学辞典について
最近完成した項目
編集履歴
執筆にあたって
引用の仕方
著作権について
免責事項
問い合わせ
各学会編集のオンライン用語辞典
About us (in English)
Twitter (BrainScienceBot)
ツール
リンク元
関連ページの更新状況
特別ページ
ページ情報
他のプロジェクト