|
I'm guessing this was generated by dreamweaver, or I hope it was, at least. If someone wrote this, they should be shot, regardless of if it works.code:
|
# ? Apr 23, 2008 00:54 |
|
|
# ? May 14, 2024 07:50 |
|
noonches posted:If someone wrote this, they should be shot, regardless of if it works. he was just optimizing it for download over 2400bps modems, half the HTML == twice as fast.
|
# ? Apr 23, 2008 02:23 |
An enumeration I found, the values of which are used in a database table.code:
|
|
# ? Apr 23, 2008 17:48 |
|
shopvac4christ posted:An enumeration I found, the values of which are used in a database table. Everything is a Foo!
|
# ? Apr 23, 2008 18:35 |
|
shopvac4christ posted:An enumeration I found, the values of which are used in a database table. Everyone remember this when they hear CS students complaining about CPU logic and close-to-the-metal programming classes!
|
# ? Apr 23, 2008 20:48 |
|
shopvac4christ posted:
Christ... everybody knows the way to do this is to make them all prime numbers so that you can just factor the resulting number to get the options that were selected.
|
# ? Apr 23, 2008 22:21 |
|
Wouldn't the correct solution be to use a bitmask? Define each enum value to 2^i (i = 0,1,2,...,n) and then just check if the relevant is set?
|
# ? Apr 24, 2008 13:15 |
|
atomic johnson posted:Christ... everybody knows the way to do this is to make them all prime numbers so that you can just factor the resulting number to get the options that were selected. chocojosh posted:Wouldn't the correct solution be to use a bitmask? Define each enum value to 2^i (i = 0,1,2,...,n) and then just check if the relevant is set? Gah, you're both wrong. Obviously the answer is a bloom filter. It's more extensible that way.
|
# ? Apr 24, 2008 13:31 |
|
Personally I would probably fork off an ec2 instance for each choice and pass the choice in as a boot parameter so it can be save to disk. You could then query each of the machines in parallel via a rest interface to quickly determine the set of choices.
|
# ? Apr 24, 2008 16:52 |
|
chocojosh posted:Wouldn't the correct solution be to use a bitmask? Define each enum value to 2^i (i = 0,1,2,...,n) and then just check if the relevant is set? No, because then you need a whole bit for each individual choice. Once you get past 32 choices it takes more than a word of memory, so it's very space-inefficient. With primes, you can fit 4294967296 different options in a word (well, not that many because not every number is prime, but it's still a hell of a lot more than 32).
|
# ? Apr 24, 2008 17:38 |
|
JoeNotCharles posted:No, because then you need a whole bit for each individual choice. Once you get past 32 choices it takes more than a word of memory, so it's very space-inefficient. With primes, you can fit 4294967296 different options in a word (well, not that many because not every number is prime, but it's still a hell of a lot more than 32).
|
# ? Apr 24, 2008 18:04 |
|
TSDK posted:I would say that you can only encode 9 flags using primes before you overflow a 32 bit unsigned word, but I just don't know who's joking or not any more You could let it overflow and just assume you're doing the math mod 2^32. I haven't looked, but I'd imagine you can go quite a ways before you ran into a collision.
|
# ? Apr 24, 2008 18:50 |
|
TSDK posted:I would say that you can only encode 9 flags using primes before you overflow a 32 bit unsigned word, but I just don't know who's joking or not any more you can get 10 if you use -1 as a flag and a signed 32 bit word. Though i guess that would make this a hybrid bit field-prime number encoding scheme.
|
# ? Apr 24, 2008 18:51 |
|
Aredna posted:You could let it overflow and just assume you're doing the math mod 2^32. I haven't looked, but I'd imagine you can go quite a ways before you ran into a collision. Anyone fancy putting the appropriate loading code in and testing?: code:
|
# ? Apr 24, 2008 19:27 |
|
Caching the prime numbers is memory-intensive. For the best performance profile you should calculate them on-demand each time.
|
# ? Apr 24, 2008 20:06 |
|
zootm posted:Caching the prime numbers is memory-intensive. For the best performance profile you should calculate them on-demand each time. This is especially true when you are using PRRBM (Pigeon Relay Ring Buffer Memory) - write times, read times, and serial access - the worst of all worlds!
|
# ? Apr 24, 2008 20:52 |
|
In all seriousness then, how would you encode N different options that can be on simultaneously? I always assumed the bitmask would work (and I would go so far to say that it is a simple and clear solution that should be efficient enough for small cases, n <= 8 or n <= 32).
|
# ? Apr 24, 2008 20:56 |
|
^^^ A bitwise mask is of course the best solution, but I find this method interesting if for no other reason than I hadn't thought about it before. The encoding works by multiplying all of the chosen primes together which will produce a unique number. If you picked the options represented by primes 2, 3, and 7, then you store 42. You can determine the prime factors of 42 later if you want to know what options were selected. It looks like you can use any combination of the first 20 prime numbers without a collision. I'm not posting my code either since it will be more than fitting for this thread. I wonder what the max number of prime numbers you can use would be, assuming you can use any prime number less than 2^32. Obviously it can't be more than 31. The real question is, what algorithm do you use to decode the number back to base primes? What if you don't know how many or which primes were used other than that they produced no collisions? Aredna fucked around with this message at 21:03 on Apr 24, 2008 |
# ? Apr 24, 2008 20:58 |
|
chocojosh posted:In all seriousness then, how would you encode N different options that can be on simultaneously? I always assumed the bitmask would work (and I would go so far to say that it is a simple and clear solution that should be efficient enough for small cases, n <= 8 or n <= 32). std::vector<bool> AFAIK is almost always implemented as a bitfield that uses proxy objects to modify its 'bool references'. I doubt that the 31 bits you save per bool really add up to anything significant, but it's a simple solution at least.
|
# ? Apr 24, 2008 21:04 |
|
Aredna posted:The real question is, what algorithm do you use to decode the number back to base primes? What if you don't know how many or which primes were used other than that they produced no collisions?
|
# ? Apr 24, 2008 21:17 |
|
Aredna posted:The real question is, what algorithm do you use to decode the number back to base primes? What if you don't know how many or which primes were used other than that they produced no collisions? since this is the coding horrors thread, the answer is easy. you calculate the every possible multiplication of the prime numbers as you've done, but modify that program to generate a header file full of #define's for all the values. Then use a massive switch statement to handle each one. No decoding necessary at runtime! code:
|
# ? Apr 24, 2008 21:17 |
|
Drx Capio posted:std::vector<bool> AFAIK is almost always implemented as a bitfield that uses proxy objects to modify its 'bool references'. I doubt that the 31 bits you save per bool really add up to anything significant, but it's a simple solution at least. Alright, so then you also second the bitmask suggestion (which means I'm not totally crazy). In C++ you can use the bitset
|
# ? Apr 24, 2008 22:07 |
|
chocojosh posted:Alright, so then you also second the bitmask suggestion (which means I'm not totally crazy). No, that's just a viable alternative if you're retarded and don't want to go with the prime factorization solution. Why would you use dynamic memory at runtime when you can quickly run through a sieve of eratosthenes and get some valid, unique flags?
|
# ? Apr 24, 2008 22:35 |
|
Drx Capio posted:std::vector<bool> AFAIK is almost always implemented as a bitfield that uses proxy objects to modify its 'bool references'. I doubt that the 31 bits you save per bool really add up to anything significant, but it's a simple solution at least. Yes, vector<bool> is a very appropriate topic for the coding horrors thread.
|
# ? Apr 25, 2008 02:24 |
|
JoeNotCharles posted:No, because then you need a whole bit for each individual choice. Once you get past 32 choices it takes more than a word of memory, so it's very space-inefficient. With primes, you can fit 4294967296 different options in a word (well, not that many because not every number is prime, but it's still a hell of a lot more than 32). I can't tell if youre joking or not, but 32 on/off options leads to 2^32 possible combinations of options, and you can't encode that in less than 2^32 numbers without losing some possible combinations.
|
# ? Apr 25, 2008 02:44 |
|
HappyHippo posted:I can't tell if youre joking or not, but 32 on/off options leads to 2^32 possible combinations of options, and you can't encode that in less than 2^32 numbers without losing some possible combinations. I was joking about the primes, yes, but when I said "you can't get more than 32 options" that was correct. I wasn't talking about combinations of options, I was talking about individual options.
|
# ? Apr 25, 2008 03:48 |
|
JoeNotCharles posted:I was joking about the primes, yes, but when I said "you can't get more than 32 options" that was correct. I wasn't talking about combinations of options, I was talking about individual options. Yes of course.
|
# ? Apr 25, 2008 04:26 |
|
Drx Capio posted:No, that's just a viable alternative if you're retarded and don't want to go with the prime factorization solution. Why would you use dynamic memory at runtime when you can quickly run through a sieve of eratosthenes and get some valid, unique flags? For simplicity? Am I missing something here or does it just seem to be much easier to use a vector<bool> (or bitset) and just count the enumerated bits? I honestly don't see what advantage there is to factoring prime numbers. Also, if you need 32 different options, then wouldn't you need to multiply the first 32 prime numbers together? That multiplication gives 31610054640417607788145206291543662493274686990 (47 digit number). I think that would require a significant amount of memory space.. I'm really lost as to who is joking right now
|
# ? Apr 25, 2008 08:08 |
|
chocojosh posted:For simplicity? Am I missing something here or does it just seem to be much easier to use a vector<bool> (or bitset) and just count the enumerated bits? I honestly don't see what advantage there is to factoring prime numbers. He's not looking for things that multiple together uniquely, it's addition.(I think)
|
# ? Apr 25, 2008 08:53 |
|
HappyHippo posted:I can't tell if youre joking or not, but 32 on/off options leads to 2^32 possible combinations of options, and you can't encode that in less than 2^32 numbers without losing some possible combinations. We're through the looking glass here folks
|
# ? Apr 25, 2008 08:57 |
|
minato posted:Unless you compress the result By my rough calculations, we should be able to store all of the values we're after up to 31610054640417607788145206291543662493274686990, in a little under 33 bits. Then when we want to figure out which values are set, we just multiply up the primes and then factor the number as usual. Job done. minato posted:We're through the looking glass here folks
|
# ? Apr 25, 2008 09:24 |
|
king_kilr posted:He's not looking for things that multiple together uniquely, it's addition.(I think) How would you be able to factor primes by addition? Let's pick the primes 2,3 and 5. If you use addition then 2 + 3 = 5. How would you distinguish 5 from representing 2 + 3 or from just representing 5. However, using prime numbers you can find a number that is the product of those primes (as every number can be represented as a unique product of primes). TSDK posted:What if, now hear me out guys, what if we use this compression scheme where we represent each prime by a particular power of two. So the i-th prime is encoded as 2^i, and then add these together to represent which primes are factors of the number we're compressing. Yeah, umm, that's called a bitmask Alright, this thread has been good for some laughs.
|
# ? Apr 25, 2008 13:15 |
|
The great thing about the prime factorisation solution is that you can have counted flags. It's like the flag equivalent of turning your amp up to 11.
|
# ? Apr 25, 2008 13:42 |
|
zootm posted:The great thing about the prime factorisation solution is that you can have counted flags. It's like the flag equivalent of turning your amp up to 11. I'm surprised nobody has mentioned this advantage yet. If I remember my Win32 API correctly, there's a window style called WS_EX_THICKFRAME. But it doesn't let me control the degree of thickness. code:
code:
|
# ? Apr 25, 2008 13:53 |
|
Flobbster posted:I'm surprised nobody has mentioned this advantage yet. If I remember my Win32 API correctly, there's a window style called WS_EX_THICKFRAME. But it doesn't let me control the degree of thickness. WS_EX_GIRTHYFRAME will do that too.
|
# ? Apr 25, 2008 16:16 |
|
Flobbster posted:I'm surprised nobody has mentioned this advantage yet. If I remember my Win32 API correctly, there's a window style called WS_EX_THICKFRAME. But it doesn't let me control the degree of thickness. this thread just took a sharp right heading straight down Hilarious St.
|
# ? Apr 25, 2008 18:16 |
|
chocojosh posted:How would you be able to factor primes by addition?
|
# ? Apr 25, 2008 18:39 |
|
I fuckin love pow(). It makes me read out the code like a hyperactive 15 year old that just killed Ogre in Tekken 3 after drinking a few gallons of bawls. Hell yes!! POW! Take that!! gently caress yeah MATH RULES WOOO
|
# ? Apr 25, 2008 18:55 |
|
king_kilr posted:What about 1, 4, 7 any addition of these numbers will be a unique sum(unless you need to add the same value multiple times, in which case primes are the only option). A bitmask can do the exact same thing and will use less space 1 2 4 (Decimal) 001 010 100 (Binary) 1 + 2 + 4 = 7 1 + 4 + 7 = 12 Also, king_kilr, what set of numbers would you use if you have 5 numbers that will always be a unique sum.. or 10 numbers.. or 100 numbers...
|
# ? Apr 25, 2008 19:12 |
|
|
# ? May 14, 2024 07:50 |
|
Jesus, what is it with you and your fetish for bitmaps?
|
# ? Apr 25, 2008 19:15 |