Ah, without preserving order. That's a set of four 5-bit values, not a sequence of four 5-bit values.
Hmm, it's interesting to me that order would be expected. I nearly always think of storage and ordering as entirely separate problems.
Show HN: How to store a set of four 5-bit values in one 16-bit value
51–60 of 149 posts
Re: Show HN: How to store a set of four 5-bit values in one 16-bit value
#52Earlier quoted context omitted.
Usually, when you store a value, you want to be able to get exactly that value back. If you store multiple values without keeping the ordering, you lose that capability. I.e. you can't replace all possible uses of four 5-bit variables with one 16-bit variable, only those where the variables are interchangeable.
Many common data structures fail to preserve order. Maps (aka dictionaries) based on hash tables come to mind. Slightly adrift of the topic... I have a HAMT (hash array map trie) implementation that uses a 32-bit unsigned int as a bitfield to indicate which of the 32 possible children nodes are populated. With this trick I could encode any node with 5 or fewer bits flagged with a 16-bit unsigned int instead. I just c…
Re: Show HN: How to store a set of four 5-bit values in one 16-bit value
#53That is one big-ass makefile though. I realize it has some extra niceties but I have to ask, did you ever try make main without any makefile at all? If you haven't done so, delete the makefile now (you have it in version control anyway) and give it a try.
Is there a way to make it work with just make? I'm way too used to just typing make at this point and it's not too much work to just copy the same makefile everywhere.
Re: Show HN: How to store a set of four 5-bit values in one 16-bit value
#54Re: Show HN: How to store a set of four 5-bit values in one 16-bit value
#55Re: Show HN: How to store a set of four 5-bit values in one 16-bit value
#56how are you getting 3876 unique values for a set of 4 4 bit values (16, 16, 16, 16) ?
Re: Show HN: How to store a set of four 5-bit values in one 16-bit value
#57That is one big-ass makefile though. I realize it has some extra niceties but I have to ask, did you ever try make main without any makefile at all? If you haven't done so, delete the makefile now (you have it in version control anyway) and give it a try.
Is there a way to make it work with just make? I'm way too used to just typing make at this point and it's not too much work to just copy the same makefile everywhere.
Re: Show HN: How to store a set of four 5-bit values in one 16-bit value
#58Re: Show HN: How to store a set of four 5-bit values in one 16-bit value
#59Re: Show HN: How to store a set of four 5-bit values in one 16-bit value
#60Earlier quoted context omitted.
Your math is wrong. If two of the numbers happen to be the same, order no longer matters for those numbers, so your log2(4!) needs to be larger...
Right. So the true answer is log2((32*31*30*29)/(4*3*2) + (32*31*30)/2 + (32*31) + (32*31)/2) = 15.675 which is still smaller than 16.
log2((32*31*30*29)/(4*3*2*1) + (32*31*30)/(3*2*1) + (32*31)/(2*1) + 32/1) = 15.34
using the number of sets of values from {0, 2^5-1} with at most 4 elements?If on the other hand you want to store exactly 4 values, possibly with duplicates (while still ignoring order), you need to count multisets ( https://en.wikipedia.org/wiki/Bag_(mathematics)#Counting_mul... )
log2( (35*34*33*32)/(4*3*2*1) ) = 15.676