1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

paiza.ioでelixir その325

Last updated at Posted at 2024-11-15

概要

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

成果物

以上

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?