|
Register or have you forgotten your password?
|
|
|
| Other Operating Systems This forum is to allow our members to discuss other (non-Amiga-related) operating systems. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#16 | ||||||||
|
Master Sock Abuser
|
There are loads of great programmer on A.org... Odd actually that there isn't a dedicated forum for programming issues?
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
||||||||
|
|
|
|
|
#17 | ||||||||
|
Kindred of Babble-on
![]()
|
Actually, comparing against an array uses less RAM all in all (just the values and the loop, you save the space of all but one cmp and blt ops minus loop ops). On a somewhat caching CPU it should also perform better since the loop needs only be fetched once and then just the array values get read - the slowest is always the memory. Without cache your approach will be faster, saving the loop overhead.
Also depends on the indexing range the CPU is capable of, of course... You could also combine both methods with a larger loop (did that once on a 6502 to save the few cycles I needed). |
||||||||
|
|
|
|
|
#18 | ||||||||
|
Kindred of Babble-on
![]()
Join Date: Feb 2002
Posts: 2,786
|
I have an idea. Depending on how you want to optimize it (apparently for speed rather than size) you could organize ranks comparisons in a binary tree like sequence (assuming the ranks are fixed). This would grant you the fastest search results possible but probably a tid bit bigger code.
Don't ask me for a code sample right now though
__________________
\"We made Amiga, they {bleep}ed it up\" |
||||||||
|
|
|
|
|
#19 | |||||||||
|
Master Sock Abuser
|
Quote:
Trying to do real time stuff with 8bit Microcontrollers is fun! ![]() -edit- just want to add that the uc I'm using has plenty of program memory 32k, but only 2k of ram... So I need to be a bit careful with my arrays and variables
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 Last edited by bloodline; 04-16-2012 at 04:03 PM.. |
|||||||||
|
|
|
|
|
#20 | |||||||||
|
Master Sock Abuser
|
Quote:
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
|||||||||
|
|
|
|
|
#21 | ||||||||
|
Hobbyist
![]()
Join Date: Feb 2011
Posts: 56
|
Don't know about a binary tree, but a binary search will reduce the number of searches to log2 n, i.e. if you have an array of 256 numbers it will do 8 searches. Basic implementation would be:
Code:
// For an array of 100 numbers, call with binsearch(n, 0, 99);
int binsearch(int n, int a, int b)
{
if(a == b)
return a;
int mid = a + (b-a)/2;
if(n < array[mid])
return binsearch(n, a, mid);
else
return binsearch(n, mid+1, b);
}
Last edited by Leffmann; 04-16-2012 at 05:30 PM.. |
||||||||
|
|
|
|
|
#22 | |||||||||
|
Defender of the Faith
![]()
|
Quote:
This is quite simple, just go to kings Knight pawn, and move two to the left, not forgetting to move queen pawn two spaces to the right, and then you get checkmate. If you figured out that I don't have a clue to what your talking about, it means that you are 10 times smarter than the average person here at Amiga.org :-) smerf
__________________
I have no idea what your talking about, so here is a doggy with a small pancake on his head. MorphOS is a MAC done a little better |
|||||||||
|
|
|
|
|
#23 | |||||||||
|
Master Sock Abuser
|
Quote:
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
|||||||||
|
|
|
|
|
#24 | ||||||||
|
Master Sock Abuser
|
Hmmm, looking around the interwebs suggest that using Staf's ternary operator based code might compile to more efficient code... I'll have to implement both and look at the Asm
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
||||||||
|
|
|
|
|
#25 | ||||||||
|
Kindred of Babble-on
![]()
Join Date: Feb 2002
Posts: 2,786
|
Is the size between boundaries constant ? (i.e. is the total nr. of ranks a multiple of the size of one rank).
__________________
\"We made Amiga, they {bleep}ed it up\" |
||||||||
|
|
|
|
|
#26 | |||||||||
|
Master Sock Abuser
|
Quote:
-edit- The values I used in my example were real, and if you were to plot them on a graph you should see the beginnings of a curve, here is more of the sequence: 5859 6525 7342 8371 9766 11719 14648 19531 29297 You get the idea
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 Last edited by bloodline; 04-17-2012 at 09:13 AM.. |
|||||||||
|
|
|
|
|
#27 | ||||||||
|
Slacker
Join Date: May 2003
Location: San Francisco, California, US
Posts: 1,514
|
If the compiler is at all recent, I'd expect the trigraph and the function (inlined) to produce the same code. Use the function. :-) (Or put the trigraph in a function.)
I know this isn't Amiga coding, but as an aside, I really miss utilitybase.com. I lost interest in my Amigas when it shut down....
__________________
Sam440ep-flex 733 MHz/1 GB RAM/Radeon 9250/AmigaOS4.1 Update 2 borked A1200/Blizzard1260+SCSI-IV/Z4+MediatorZIV/Deneb/Voodoo3/CatweaselMk3 more borked A1200/MBX1200z/Indivision A500/clockport/RRNet A600/A603 Power Mac G4 QuickSilver/MorphOS 2.6 |
||||||||
|
|
|
|
|
#28 | |||||||||
|
Master Sock Abuser
|
Quote:
![]() Also many people on this site have expressed an interest in learning to program, they would be wise to read threads like these
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
|||||||||
|
|
|
|
|
#29 | ||||||||
|
Hobbyist
![]()
Join Date: Feb 2011
Posts: 56
|
|
||||||||
|
|
|
|
|
#30 | |||||||||
|
Master Sock Abuser
|
Quote:
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!
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
|||||||||
|
|
|
![]() |
| Bookmarks |
| Tags |
| programming , question |
| Thread Tools | |
| Display Modes | |
|
|