Data Types Flashcards
What data type should you use if order is important
Lists
What are maps O notation for random access?
O(log n)
What are lists’ random access O notation
O(n)
If you need to work w/ individual characters in a list, what data type should you use?
charlist
what kind of quotes do charlists use?
single
why should processes not hold long strings?
It’s an optimization. Long strings are shared across processes, but this optimization can lead to memory leaks.
What’s the O notation for finding a character in a sring?
O(n), just like lists
Explain drawbacks of String concatenation.
It’s slow, there’s a trick for doing it that Phoenix uses for templates. See page 31 of Designing Elixir Systems for how to use IO lists to do more perofmant string concatenations
When is the use of tuples preffered?
when the order means something, like in x, y co-ordinates
If you’re editing tuples a lot, what data structure should you switch too?
maps
What is the fastest Elixir data structure for random access?
tuples
Why is it good to send the function to the data rather than the data to a function?
Multiple processes may be running. Sending data from one process to another often means that each process needs a copy of the data which is wasteful. Also, it means potentially sending more data over the network if the processes are running on different machines. This makes sending the function faster as less data needs to be copied and/or sent over a given netowrk.
Should you prefer flat or deep data structures?
flat
Define the “functional core”
a group of functions and the type definitions representing the data layer, organized into modules