Today I learned about String Interning. Which is the process of taking a string and turning it into a number that you can use to represent that string. Its often used in cases where you might have a fixed number of strings, and want to perform things like equality checks quicker than doing string equality. You can map each string to a unique integer then do the equality check on the integer instead.
And even cooler I was actually familiar with the concept, just not the name! This is how Strings and Symbols work in Ruby! A Symbol is an 'interned string', that are often used as hash keys in Ruby. This is nice since we don't have to do string hashing on each hash lookup. Pretty neat!
Links:
Top comments (0)