Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Array issue

Author
Message
george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 13th Sep 2016 23:33
Please run the following code:


Then add around 10 elements and try to make some searches a few times. It will not work all the times.
I am not sure if there is a bug in my code or in the find method
ShaunRW
DBPro Developer
16
Years of Service
User Offline
Joined: 7th Jan 2008
Location: Brisbane, Australia
Posted: 14th Sep 2016 00:29
Try using myArray.insertsorted(m) on line 40. The array needs to be sorted for the find to work properly.
george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 14th Sep 2016 00:41 Edited at: 14th Sep 2016 00:44
Oh.. thanks for the info
I read the documentation. You are right...
Although, I cannot understand why there is such a limitation
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 14th Sep 2016 08:14 Edited at: 14th Sep 2016 08:18
Quote: "I cannot understand why there is such a limitation"


You're confusing 'limitation' with 'efficiency'.
The find routine will probably use a binary search algorithm so it only has to look at a very small number of elements to find the one it needs. It's incredibly fast and efficient but does require the array to be sorted first.
If you don't want to sort the array then it's easy enough to write your own find function but it will be a lot slower.

AGK V2 user - Tier 1 (mostly)
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Sep 2016 14:38
I had the same thought Scraggle, binary search.

Is there a command to sort an array after creation? Or only through the insertedSorted command? Because I would assume every insertSorted uses the same binary search. If you have a lot of data to insert dynamically maybe it'd be quicker to just add it all into the array first the run a quick sort or radix or whatever it used to sort.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 14th Sep 2016 16:55
You can use myarray.sort to sort an array Docs on arrays can be found under "Principles" in the documentation: https://www.appgamekit.com/documentation/guides/12_array_changes.htm
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Sep 2016 22:41
I don't have AppGameKit 2, so that's why I had to ask :p

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 15th Sep 2016 09:19
Quote: "I don't have AppGameKit 2"


I'd have thought TGC would have upgraded everyone by now. Is there a discounted upgrade path available? I'd quite like to upgrade all my old V1 licences to V2 as my kids want to start coding
V2 T1 (Mostly)
Phone Tap!
Uzmadesign

Login to post a reply

Server time is: 2024-09-29 19:28:16
Your offset time is: 2024-09-29 19:28:16