SDBinarySearch

Posts   
 
    
OlafB
User
Posts: 7
Joined: 07-Jul-2022
# Posted on: 08-Aug-2022 10:11:57   

When migrating our code to .NET6 we altered our code to get it to compile:

            var query =
                from eis in _metaData.EmployeeInShift.WhereIn(x => x.Id, employeesToCallUp.Select(y => y.EmployeeInShiftId))
                where eis.EmpInShiftContractTypeId == (long)EmpInShiftContractType.Gig
                orderby eis.Id
                select eis.Id;

            var lookup = query.ToArray();
            var nonCallUpList = new List<EmployeeCallUpData>();
            var callUpList = new List<EmployeeCallUpData>();

            foreach (var item in employeesToCallUp)
            {
                    if (lookup.BinarySearch(item.EmployeeInShiftId, Comparer<long>.Default) != -1)
                    nonCallUpList.Add(item);
                else
                    callUpList.Add(item);
            }

we changed this line:

                    if (lookup.BinarySearch(item.EmployeeInShiftId, Comparer<long>.Default) != -1)

to

                if (SDBinarySearch.BinarySearch(lookup, item.EmployeeInShiftId, Comparer<long>.Default) != -1)

Are these lines functionally equivalent i.e. can they be interchanged without altering the functionality?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 08-Aug-2022 11:03:39   

I don't know what SDBinarySearch is?

netstandard contains Array.BinarySearch(), so it'll become Array.BinarySearch(lookup, item.EmployeeInShiftId, Comparer<long>.Default)

Frans Bouma | Lead developer LLBLGen Pro
OlafB
User
Posts: 7
Joined: 07-Jul-2022
# Posted on: 08-Aug-2022 13:50:19   

This should be equivalent, though.

                using SDExtensions = SD.Tools.BCLExtensions.CollectionsRelated.IListExtensionMethods;


                if (SDExtensions.BinarySearch(lookup, item.EmployeeInShiftId, Comparer<long>.Default) != -1)
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 08-Aug-2022 21:12:23   

Ah that's our binary search, I couldn't find it at first as I looked in the Algorithmia library but it's in the BCL Extensions library. It should be equivalent, however as the one in our library isn't optimized, it might be a tiny bit slower than the one in the BCL. Either one should work tho.

Frans Bouma | Lead developer LLBLGen Pro