概要
paiza.ioでelixirやってみた。
HashSet、やってみた。
参考にしたページ
サンプルコード
set1 = Enum.into 2..6, HashSet.new
IO.inspect set1
IO.inspect "delete(set, term)"
IO.inspect Set.delete set1, 3
IO.inspect "difference(set1, set2)"
set2 = Enum.into 4..8, HashSet.new
IO.inspect Set.difference set1, set2
IO.inspect "disjoint?(set1, set2)"
IO.inspect Set.disjoint? set1, set2
set3 = Enum.into 7..10, HashSet.new
IO.inspect Set.disjoint? set1, set3
IO.inspect "equal?(set1, set2)"
set4 = Enum.into 7..10, HashSet.new
IO.inspect Set.equal? set1, set4
IO.inspect Set.equal? set3, set4
IO.inspect "intersection(set1, set2)"
IO.inspect Set.intersection set1, set2
IO.inspect Set.intersection set1, set3
IO.inspect "member?(hashset, term)"
IO.inspect Set.member? set1, 2
IO.inspect Set.member? set1, 7
IO.inspect "put(hashset, term)"
IO.inspect Set.put set1, 7
IO.inspect Set.put set1, 6
IO.inspect "size(hashset)"
IO.inspect Set.size set1
set5 = Enum.into 1..10, HashSet.new
IO.inspect Set.size set5
IO.inspect "subset?(set1, set2)"
IO.inspect Set.subset? Enum.into(2..4, HashSet.new), Enum.into(2..5, HashSet.new)
IO.inspect Set.subset? Enum.into(2..5, HashSet.new), Enum.into(2..4, HashSet.new)
IO.inspect "union(set1, set2)"
IO.inspect Set.union Enum.into(2..4, HashSet.new), Enum.into(4..8, HashSet.new)
実行結果
#HashSet<[2, 6, 3, 4, 5]>
"delete(set, term)"
#HashSet<[2, 6, 4, 5]>
"difference(set1, set2)"
#HashSet<[2, 3]>
"disjoint?(set1, set2)"
false
true
"equal?(set1, set2)"
false
true
"intersection(set1, set2)"
#HashSet<[6, 4, 5]>
#HashSet<[]>
"member?(hashset, term)"
true
false
"put(hashset, term)"
#HashSet<[7, 2, 6, 3, 4, 5]>
#HashSet<[2, 6, 3, 4, 5]>
"size(hashset)"
5
10
"subset?(set1, set2)"
true
false
"union(set1, set2)"
#HashSet<[7, 6, 2, 4, 3, 5, 8]>
成果物
以上