Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips > Additional Libraries
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Additional Libraries Users contributed libraries.
This sub-forum is only available to licensed users.

Collection library

Reply
 
LinkBack Thread Tools Display Modes
  #31 (permalink)  
Old 01-31-2012, 07:41 PM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 810
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by agraham View Post
Haven't got time to look at "next" at the moment but
Code:
If index < 0 then
    index = 
1 - index ' complement
End If
Thanks again; that was my conclusion too! But I was not negating or complementing the result. Merely testing for " > -1" which should have trapped all mismatches but didn't.

Please ignore my winge about IndexOf(); that problem was down to my not noticing that the order of arguments is quite different from BinarySearch()
Reply With Quote
  #32 (permalink)  
Old 02-01-2012, 08:28 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Sorry, the perils of haste , dinner was ready to serve! The above is wrong, it should be

Code:
If index < 0 then
    index = 
0 - 1 - index ' complement
End If
so
0xffff (-1) => 0
0xfffe (-2) => 1
0cfffd (-3) => 2
etc.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.

Last edited by agraham : 02-01-2012 at 08:31 AM.
Reply With Quote
  #33 (permalink)  
Old 02-01-2012, 10:09 AM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 810
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by agraham View Post
Sorry, the perils of haste , dinner was ready to serve! The above is wrong, it should be

Code:
If index < 0 then
    index = 
0 - 1 - index ' complement
End If
so
0xffff (-1) => 0
0xfffe (-2) => 1
0cfffd (-3) => 2
etc.
Thanks again Andrew. It would be nice to have this explained in the Help, but maybe it is not worth doing that now it is enshrined in this relevant thread.

None of the above explains why I am getting zero returned from BinarySearch() whereas IndexOf() gives the results I expect and works fine. The demo program works OK if tweaked to look for missing values. BTW I think that the constants are singular as in the Help, not cNumbers. I suppose if you have the detection suppressed this means you will get a null string or zero passed to the operation instead of the intended constant, which could give strange results.

My look-up arrays are generated by sparsely storing a counter, so are sorted numerically from the outset; I do not perform a sort operation. If you wanted(?) to investigate I could write out a sample array. (It is derived from zooming an OS-GB vector road-map.)

Mike.
Attached Images
File Type: jpg zoomed-map.jpg (24.9 KB, 8 views)
Reply With Quote
  #34 (permalink)  
Old 02-01-2012, 12:16 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Time dims the memory. All is now clear! Unfortunately there is a bug in ArraysEx.BinarySearch and ArrayListEx.BinarySearch. The .NET documentation is correct but in attempting to make this statement in the help true
Quote:
If value is not found a negative number is returned. If the absolute value of this number is greater than or equal to the size of the array, there are no elements larger than value in the array. Otherwise, it is the index of the first element that is larger than value.
and notionally make things simpler by compensating for the bitwise inversion I missed that zero would be rturned both for a match at index 0 and for a no match when all the elements are larger than the search value. So as you suggested earlier a zero return is ambiguous and needs a further check doing to be correctly interpreted.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Door library (Beta) - Special library Erel Official Updates 60 01-13-2011 11:23 AM
Merging Outlook library and Phone library Erel Official Updates 11 09-15-2010 09:22 AM
Contact.update verschiebt Collection-List Paulsche German Forum 0 09-30-2008 11:08 PM
Data collection from devices to Desktop using SQLite mozaharul Questions (Windows Mobile) 3 04-03-2008 10:00 AM
3D to 2D functions collection legugusse Share Your Creations 2 07-12-2007 11:11 AM


All times are GMT. The time now is 10:22 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0