Difference between Set and Array

#1

i come from a ruby background and the concept of Set is something im not familiar with.
How is it different from a regular Array, in what scenarios should i be choosing one over the other?

#2

They are similar but a Set is unordered and does not contain duplicates. An array can contain duplicates and order depends on the order items were inserted.

However, the current implementation of Set causes it to be ordered. This is just an implementation detail and should not be relied upon if you need a specific order.

2 Likes
#3

There could be a page in the book explaining the difference between:

  • Array
  • Set
  • Tuple
  • StaticArray
  • Slice
  • Deque

Edit: Deque added

3 Likes
#4

it’s the same as in Ruby, Ruby also has Set

#5

easy confuse with NamedTuple and Hash
{a:1} and {:a => 1}

in ruby, its same.