The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > Web Programming > PHP


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Reply
 
LinkBack Thread Tools    Display Modes   
  #11 (permalink)  
Old 07-29-2007, 02:19 PM
molotov molotov is offline
Novice
Join Date: Jul 2007
Posts: 37
iTrader: (0)
molotov is on a distinguished road
Quote:
Originally Posted by TeraTask View Post
See Want to Be a Computer Scientist? Forget Maths for the motivation behind this solution. There is a way of doing this better than just assigning the numbers above. I just don't have time to write it up.
Ah! That is very clever. I was trying to work out a way using primes or something with the idea that if the category % 2 = 0, you increase cost figuring out which categories or doing another lookup, but if my assumption that most books are only in one category is true, it might be worth the extra cost. I really don't know anything about the dataset though, so it was a shot in the dark.


Also, when working with powers of 2, shifting bits is more than twice as fast as pow().

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
The Following User Says Thank You to molotov For This Useful Post:
TeraTask (07-29-2007)
  #12 (permalink)  
Old 07-29-2007, 04:47 PM
TeraTask's Avatar
TeraTask TeraTask is offline
PT Admin
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 3
Join Date: Jun 2007
Location: Reno, NV
Posts: 441
iTrader: (0)
TeraTask is a splendid one to beholdTeraTask is a splendid one to beholdTeraTask is a splendid one to beholdTeraTask is a splendid one to beholdTeraTask is a splendid one to beholdTeraTask is a splendid one to behold
Quote:
Originally Posted by molotov View Post
Also, when working with powers of 2, shifting bits is more than twice as fast as pow().
Superior point!!!! Thanks.

__________________
Jeremy Miller
Content Farmer - Optimized Automated Blog Posting

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #13 (permalink)  
Old 08-24-2007, 11:52 AM
molotov molotov is offline
Novice
Join Date: Jul 2007
Posts: 37
iTrader: (0)
molotov is on a distinguished road
I found something interesting. It looks like the problem we're having is limited to the array keys, not PHP or MySQL. We're using unsigned BIGINTs, so that's not a problem until we get to 2^54 apparently, and if you run this snippet below, you'll see PHP doesn't have a problem dealing with large numbers:

PHP Code:
for ($i=0;$i<128;$i++)
{
    echo 
"$i = " pow(2$i) . "\n";

BUT, when you bit-shift, you run into the previous problem:

PHP Code:
for ($i=0;$i<128;$i++)
{
    echo 
"$i = " . (<< $i) . "\n";

I suppose that can be explained by shifting out of the memory blocks where these numbers are residing. Neat.

So anyway, what if we did something like this?
PHP Code:
  $my_subjects[] = array('name'    => 'subject',
                       
'options' => array(''.pow(2,0).''  => 'Arts & Photography',        ''.pow(2,1).''  => 'Audiocassettes',            ''.pow(2,2).''  => 'Audio CDs'
                                          
''.pow(2,3).''  => 'Audio Downloads',           ''.pow(2,4).''  => 'Bargain Books',             ''.pow(2,5).''  => 'Biographies & Memoirs'
                                          
''.pow(2,6).''  => 'Business & Investing ',     ''.pow(2,7).''  => 'Children\'s Books',         ''.pow(2,8).''  => 'Christian Books'
                                          
''.pow(2,9).''  => 'Comics & Graphic Novels',   ''.pow(2,10).'' => 'Computers & Internet',      ''.pow(2,11).'' => 'Cooking, Food & Wine'
                                          
''.pow(2,12).'' => 'e-Books',                   ''.pow(2,13).'' => 'Entertainment',             ''.pow(2,14).'' => 'Español'
                                          
''.pow(2,15).'' => 'Gay & Lesbian',             ''.pow(2,16).'' => 'Health, Mind & Body',       ''.pow(2,17).'' => 'History'
                                          
''.pow(2,18).'' => 'History',                   ''.pow(2,19).'' => 'Horror',                    ''.pow(2,20).'' => 'Literature & Fiction'
                                          
''.pow(2,21).'' => 'Mystery & Thrillers',       ''.pow(2,22).'' => 'Nonfiction',                ''.pow(2,23).'' => 'Outdoors & Nature '
                                          
''.pow(2,24).'' => 'Parenting & Families',      ''.pow(2,25).'' => 'Professional & Technical',  ''.pow(2,26).'' => 'Reference'
                                          
''.pow(2,27).'' => 'Religion & Spirituality',   ''.pow(2,28).'' => 'Romance',                   ''.pow(2,29).'' => 'Science'
                                          
''.pow(2,30).'' => 'Science Fiction & Fantasy'''.pow(2,31).'' => 'Sports',                    ''.pow(2,32).'' => 'Teen'
                                          
''.pow(2,33).'' => 'Travel',                    ''.pow(2,34).'' => 'Women\'s Fiction'
                                         
));
                                         
                                         
                                         
var_dump($my_subjects); 
It's kind of a hacky way of turning those numbers into strings. If anyone knows a better way, I'd love to hear it just because the type-abuse above feels so wrong


So now we have array indexes that are number strings, but can be shoved into MySQL as BIGINTs. Thoughts?

Here's the whole thing for easy copy-paste:
PHP Code:
<?php

echo "<pre>";

for (
$i=0;$i<128;$i++)
{
    echo 
"$i = " pow(2$i) . "\n";
}


for (
$i=0;$i<128;$i++)
{
    echo 
"$i = " . (<< $i) . "\n";
}


  
$my_subjects[] = array('name'    => 'subject',
                       
'options' => array(''.pow(2,0).''  => 'Arts & Photography',        ''.pow(2,1).''  => 'Audiocassettes',            ''.pow(2,2).''  => 'Audio CDs'
                                          
''.pow(2,3).''  => 'Audio Downloads',           ''.pow(2,4).''  => 'Bargain Books',             ''.pow(2,5).''  => 'Biographies & Memoirs'
                                          
''.pow(2,6).''  => 'Business & Investing ',     ''.pow(2,7).''  => 'Children\'s Books',         ''.pow(2,8).''  => 'Christian Books'
                                          
''.pow(2,9).''  => 'Comics & Graphic Novels',   ''.pow(2,10).'' => 'Computers & Internet',      ''.pow(2,11).'' => 'Cooking, Food & Wine'
                                          
''.pow(2,12).'' => 'e-Books',                   ''.pow(2,13).'' => 'Entertainment',             ''.pow(2,14).'' => 'Español'
                                          
''.pow(2,15).'' => 'Gay & Lesbian',             ''.pow(2,16).'' => 'Health, Mind & Body',       ''.pow(2,17).'' => 'History'
                                          
''.pow(2,18).'' => 'History',                   ''.pow(2,19).'' => 'Horror',                    ''.pow(2,20).'' => 'Literature & Fiction'
                                          
''.pow(2,21).'' => 'Mystery & Thrillers',       ''.pow(2,22).'' => 'Nonfiction',                ''.pow(2,23).'' => 'Outdoors & Nature '
                                          
''.pow(2,24).'' => 'Parenting & Families',      ''.pow(2,25).'' => 'Professional & Technical',  ''.pow(2,26).'' => 'Reference'
                                          
''.pow(2,27).'' => 'Religion & Spirituality',   ''.pow(2,28).'' => 'Romance',                   ''.pow(2,29).'' => 'Science'
                                          
''.pow(2,30).'' => 'Science Fiction & Fantasy'''.pow(2,31).'' => 'Sports',                    ''.pow(2,32).'' => 'Teen'
                                          
''.pow(2,33).'' => 'Travel',                    ''.pow(2,34).'' => 'Women\'s Fiction'
                                         
));
                                         
                                         
                                         
var_dump($my_subjects);

?>

EDIT: found this: PHP: bcpow - Manual

bcpow() would get around having to do that '' dance.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by molotov : 08-24-2007 at 12:14 PM.
Reply With Quote
  #14 (permalink)  
Old 09-19-2007, 02:06 PM
molotov molotov is offline
Novice
Join Date: Jul 2007
Posts: 37
iTrader: (0)
molotov is on a distinguished road
Bump.

Still curious to the solution for this issue.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #15 (permalink)  
Old 09-19-2007, 02:09 PM
TeraTask's Avatar
TeraTask TeraTask is offline
PT Admin
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 3
Join Date: Jun 2007
Location: Reno, NV
Posts: 441
iTrader: (0)
TeraTask is a splendid one to beholdTeraTask is a splendid one to beholdTeraTask is a splendid one to beholdTeraTask is a splendid one to beholdTeraTask is a splendid one to beholdTeraTask is a splendid one to behold
I just may get back to this shortly. I found PHP: GMP Functions - Manual and want to write this up in a generic class, but as indicated elsewhere in these forums, I have an enormous amount of work on my hands right now.

__________________
Jeremy Miller
Content Farmer - Optimized Automated Blog Posting

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 05:23 AM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50