420chan now has a web-based IRC client available, right here
Leave these fields empty (spam trap):
Name
You can leave this blank to post anonymously, or you can create a Tripcode by using the float Name#Password
Comment
[*]Italic Text[/*]
[**]Bold Text[/**]
[~]Taimapedia Article[/~]
[%]Spoiler Text[/%]
>Highlight/Quote Text
[pre]Preformatted & Monospace text[/pre]
1. Numbered lists become ordered lists
* Bulleted lists become unordered lists
File

Sandwich


Community Updates

420chan now supports HTTPS! If you find any issues, you may report them in this thread
Storing lists as the factorized form of single numbers by Sophie Navingmag - Wed, 04 Jan 2017 17:30:26 EST ID:zu3jfUuo No.36440 Ignore Report Quick Reply
File: 1483569026042.png -(30588B / 29.87KB, 317x332) Thumbnail displayed, click image for full size. 30588
I was dealing with a SQL database earlier today and I was frustrated because I couldn't make a column hold a list of values in every possible row. I ended up just doing one-hot encoding (and adding 20 columns full of sparse binary data in the process) but I had a thought: what if you use all prime numbers as index values, then simply multiply them together to produce a single BIGINT value. Then, when retrieving data from the database, you simply factorize the value and the prime numbers it yields will tell you what members of the list are present in that row's entry. Like:

userID | movelist
1 -------| 1914

When I want to retrieve the move list for user 1, I'd just:
>SELECT movelist FROM db WHERE userID 1;
which yields 1914. Then I take this number and factorize it yielding [2, 3, 11, 29]. My movelist table looks like this:

index | move
2 ------| jump
3 ------| punch
5 ------| kick
7 ------| eat
11 ----| slash
13 ----| talk
17 ----| scream
19 ----| cry
23 ----| crush
29 ----| fly

I go through the list I generated by factorization and retrieve the details of each move. I eliminated 9 columns of data while only adding a factorization function (the movelist table would exist regardless). In large databases this can save you TONS of space. Now yes, you can only use the first 15 prime numbers before getting larger than BIGINTs can hold, but that's still 14 columns you can eliminate. There might even be a way to utilize different sets of the first 15 primes and store lists of indefinite length.

So my question is, can anyone think of a downside to this that I'm missing? I can't find anything about this on the net. Does it have a name?
>>
George Dabberfuck - Wed, 04 Jan 2017 18:19:57 EST ID:6HbnJEA/ No.36441 Ignore Report Quick Reply
Congratulations, you just invented a very inefficient alternative to bit fields:

https://en.wikipedia.org/wiki/Bit_field

What would you like to name your invention?
>>
Molly Woblingwill - Wed, 04 Jan 2017 20:22:12 EST ID:ztur2YT8 No.36442 Ignore Report Quick Reply
I agree that your solution sounds somewhat similar to bit-fields. Additionally, factoring (expensive) long composite numbers at lookup-time is much, much slower than the special-case of bit-fields (which basically uses powers of 2 from OEIS A000079 instead of prime numbers from OEIS A000040) where you can use simple bit-shifts, ANDs, and ORs to quickly test up to 64 bits in one CPU clock-cycle versus expensive loops and division operations for factorization.
>>
Archie Bubblegold - Thu, 05 Jan 2017 11:02:58 EST ID:zu3jfUuo No.36443 Ignore Report Quick Reply
1483632178501.jpg -(115916B / 113.20KB, 391x608) Thumbnail displayed, click image for full size.
>>36441
Lol I see. That makes a lot more sense to use.

I dub my invention "Cool Guy Database Compression" (CGDC)
>>
Edward Blommlefedge - Thu, 05 Jan 2017 22:03:09 EST ID:ztur2YT8 No.36444 Ignore Report Quick Reply
>>36443
That's a pretty awesome name.
>>
Oliver Fandock - Tue, 10 Jan 2017 11:04:16 EST ID:9QSfnS0r No.36446 Ignore Report Quick Reply
Using prime factorization this way is borderline retarded.

Srsly use bitfields.
1 ------| jump
2 ------| punch
4 ------| kick
8 ------| eat
16 ----| slash
32 ----| talk
64 ----| scream
128 ----| cry
256 ----| crush
512 ----| fly

People back in the day would have hit you over the head for that, now cpu cycles are cheap, but not that cheap.
The only advantage your method has is you can store multiple references to the same move in the same value, but as it looks you don't want to do this anyway.

And second if you are concerned about space savings don't use sql.
>>
Oliver Fandock - Tue, 10 Jan 2017 11:11:11 EST ID:9QSfnS0r No.36447 Ignore Report Quick Reply
Also your method won't save any space versus bitfields because of the pigeonhole principle.


Report Post
Reason
Note
Please be descriptive with report notes,
this helps staff resolve issues quicker.