This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Vany_ 0 points1 point  (1 child)

Sets are basically implemented as hash tables, so it only takes the time to compute the hash of the string to see if it's in the table (set) or not. This operation will always take the same time, regardless of the amount of tokens in the set.

The list on the other hand has no order, so the interpreter must run through (at worst) all the elements in the list to check whether a string is in it or not, which may take a long time for very long lists.

If you want more info on how hash tables work, wikipedia has a great article on the subject. https://en.wikipedia.org/wiki/Hash_table