For anyone using a version of 4D prior to V14 R4, you may actually find the Dave Terry code that I tweaked and posted of use. It's 25 years old and still works. The issue is, how do you distinguish between a result that says "this is where the element you're looking for *is*" and one that says "this is where the element *belongs*, if you add it." For cases where you keep an array of unique values and don't care about duplicates:
* Find the element's position. * If the position is greater than the size of your array, you need to add an element. * If the position is less than or equal to the size of your array, does the target value match the existing value at that position? * If they match, you're done because the value is already in place. * If they don't match, you need to insert the new element in that position and set it with your target value. Unique value arrays and binary insert/lookup are a pretty natural combination, so this isn't a rare situation to find yourself in. Is it work the effort? Depends. For a tiny array, a sequential (find in array) scan is just fine. You can test it out in your environment to see if it's worth the trouble. Then again, with the 4D command (or the more limited version adapted from Dave Terry) in place, it's very little work to maintain an array in sorted order & use binary search and insert. On Sun, Jan 15, 2017 at 11:07 AM, Keisuke Miyako <[email protected]> wrote: > that is absolutely right. > > the syntax and behaviour of "Find in sorted array" was modified during the > beta phase of 14R4, > "Following a feedback received from the customer who was the source of the > feature request" > > Implementation changes in feature "Find in array by dichotomy" (2014) > http://forums.4d.fr/Post/FR/15548126/1/15548127#15548127 > > > 2017/01/15 8:13、Arnaud de Montard <[email protected]> のメール: > > > > You have to know that, at the very beginning, that car had no wheel :-) > > (translated from french) > > "Binary search in array is great. But something's missing IMHO. > > Where do I insert the value in the array if it is not found? > > Seems obvious this information goes along with a binary search. > > We would not have to sort every time we add a value, > > especially if several arrays are synchronized." > > > > 宮古 啓介 > セールス・エンジニア > > 株式会社フォーディー・ジャパン > 〒150-0043 > 東京都渋谷区道玄坂1-10-2 渋谷THビル6F > Tel: 03-6427-8441 > Fax: 03-6427-8449 > > [email protected] > www.4D.com/JP > > ********************************************************************** > 4D Internet Users Group (4D iNUG) > FAQ: http://lists.4d.com/faqnug.html > Archive: http://lists.4d.com/archives.html > Options: http://lists.4d.com/mailman/options/4d_tech > Unsub: mailto:[email protected] > ********************************************************************** > ********************************************************************** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:[email protected] **********************************************************************

