3 ms·
Compact is a fine description. If you can pin down exactly what benefit you expect a more compact representation to offer, that might suggest a word that better
by shoo 5y ago
Compact is a fine description. If you can pin down exactly what benefit you expect a more compact representation to offer, that might suggest a word that better communicates the intent of the encoding.
One potential benefit is that the number of invalid states that can be represented is reduced or eliminated. If a compact choice of type prevents the representation of invalid states, then that chops away some useless part of the state space you would otherwise need to carefully guard against with validation logic and test cases. Especially useful for structures that can potentially be edited or transformed outside of your control in ways that do not preserve the invariants you have in mind ("a stoplight value is always exactly one of the three colours").
Another potential benefit is that the number of bits needed to encode the values may be reduced. This probably doesn't matter unless you have extreme memory limitations or are writing a game engine and trying to squeeze the most work out of memory bandwidth by avoiding wasting the cache on bytes that don't contain information.
Yet another potential benefit (if no invalid states can be represented) would mean that if the value of two representations are different, then they correspond to two distinct states in your state space.
There are probably some settings where this kind of encoding is counterproductive. E.g. when fitting a linear regression model to predict a response from the input state, if there is no ordering between your states then it might be more natural to model the response variable as a function of n binary indicator variables instead of a single enum variable taking n integer values.