amiga.org
     
iconAll times are GMT -6. The time now is 03:16 PM. | Welcome to Forum, please register to access all of our features.

» Amiga.org » Operating System Specific Discussions » Other Operating Systems » Programming question! :)

Other Operating Systems This forum is to allow our members to discuss other (non-Amiga-related) operating systems.

Reply
 
Thread Tools Display Modes
Old 04-17-2012, 12:07 PM   #31
Zac67
Kindred of Babble-on
Points: 12,421, Level: 72 Points: 12,421, Level: 72 Points: 12,421, Level: 72
Activity: 15% Activity: 15% Activity: 15%
 
Zac67's Avatar
 
Join Date: Nov 2004
Location: Erlangen, Germany
Posts: 2,851
Blog Entries: 4
Default Re: Programming question! :)

A binary tree search with recursion will result in very compact code but the recursion bit may take up a bit of stack space... You can do it the iterative way as well with more code and much less elegance. Plus, it'll (probably) be a lot faster.
Zac67 is offline   Reply With Quote
Old 04-17-2012, 12:08 PM   #32
Fats
Technoid
Points: 9,230, Level: 64 Points: 9,230, Level: 64 Points: 9,230, Level: 64
Activity: 5% Activity: 5% Activity: 5%
 
Fats's Avatar
 
Join Date: Mar 2002
Location: Belgium
Posts: 498
Default Re: Programming question! :)

Quote:
Originally Posted by bloodline View Post
Appologies! I only quickly looked over it If I had a larger array I would certainly investigate this method... I'm intrigued to see how a tiny microcontroller would cope with this kind of search!
OK, then you can go really funky. Using something like this:

Code:
struct lookup
{
   int num;
   unsigned char rank;
}

struct lookup vals[] =
{
    {4185, 4},
    {4507, 3},
    {4883, 2},
    {5327, 1},
    {MAX, 0}
}
If you make the array size a power of two you should be able to implement the binary search with bit manipulation using |= and <<. Or you can start somewhere in the middle of the array with an index that is power of two and see that you don't go over the highest index.

greets,
Staf.
__________________
Trust me... I know what I'm doing
Fats is offline   Reply With Quote
Old 04-18-2012, 05:40 PM   #33
Jose
Kindred of Babble-on
Points: 21,917, Level: 92 Points: 21,917, Level: 92 Points: 21,917, Level: 92
Activity: 10% Activity: 10% Activity: 10%
 
Join Date: Feb 2002
Posts: 2,786
Default Re: Programming question! :)

Another idea that I don't know if it would work. If the values of the curve can be guessed by using a mathematical function you could revert the function and get the x value. Then calculate the rank by dividing by rank x size (of course that assumes rank x size is constant between ranks, as opposed to rank y size which isn't (like you say it's a curve)).
__________________
\"We made Amiga, they {bleep}ed it up\"
Jose is offline   Reply With Quote
Old 04-18-2012, 10:43 PM   #34
bloodline
Master Sock Abuser
Points: 37,161, Level: 100 Points: 37,161, Level: 100 Points: 37,161, Level: 100
Activity: 8% Activity: 8% Activity: 8%
 
bloodline's Avatar
 
Join Date: Mar 2002
Location: London, UK
Posts: 11,657
Blog Entries: 3
Default Re: Programming question! :)

Quote:
Originally Posted by Jose View Post
Another idea that I don't know if it would work. If the values of the curve can be guessed by using a mathematical function you could revert the function and get the x value. Then calculate the rank by dividing by rank x size (of course that assumes rank x size is constant between ranks, as opposed to rank y size which isn't (like you say it's a curve)).
On an 8bit microcontroller, you really want to avoid multiplication and division (unless you can use a power of 2... ie left or right shifts). I really did try to do this mathematically first, but realised that I simply don't have the CPU time
__________________
My iPhone Game: Puny Humans -
http://itunes.apple.com/gb/app/puny-...362230281?mt=8
bloodline is offline   Reply With Quote
Old 04-19-2012, 08:15 AM   #35
Thorham
Cult Member
Points: 4,050, Level: 40 Points: 4,050, Level: 40 Points: 4,050, Level: 40
Activity: 26% Activity: 26% Activity: 26%
 
Thorham's Avatar
 
Join Date: Oct 2009
Posts: 553
Default Re: Programming question! :)

Quote:
Originally Posted by bloodline View Post
On an 8bit microcontroller, you really want to avoid multiplication and division (unless you can use a power of 2... ie left or right shifts). I really did try to do this mathematically first, but realised that I simply don't have the CPU time
Out of interest, how often is this code executed per second (seems quite often seeing how that controller does 1 mips per Mhz (according to the specs I looked up at least))? Also, for the challenge, would it be a problem to post the whole threshold array here? Maybe there's a nice trick possible
Thorham is offline   Reply With Quote
Old 04-19-2012, 12:30 PM   #36
Zac67
Kindred of Babble-on
Points: 12,421, Level: 72 Points: 12,421, Level: 72 Points: 12,421, Level: 72
Activity: 15% Activity: 15% Activity: 15%
 
Zac67's Avatar
 
Join Date: Nov 2004
Location: Erlangen, Germany
Posts: 2,851
Blog Entries: 4
Default Re: Programming question! :)

Reminds me of when I tried to calculate the Mandelbrot set without any(!) multiplications - it was hideously fast on a non-FPUd 68000 (for the time) but the precision was really crap - not surprising, I used a 16 bit table of squares together with (a+b)^2-a^2-b^2=2ab. 128KB was no problem but a somewhat usable 32 bit table would take 16 GB - still waiting for that to come around...

Last edited by Zac67; 04-19-2012 at 12:33 PM..
Zac67 is offline   Reply With Quote
Reply

Bookmarks

Tags
programming , question

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump