private static Key UpperIntersection()

in EsentCollections/KeyRange.cs [337:389]


        private static Key<T> UpperIntersection(Key<T> a, Key<T> b)
        {
            Key<T> min;
            if (null == a && null != b)
            {
                min = b;
            }
            else if (null != a && null == b)
            {
                min = a;
            }
            else if (null != a && null != b)
            {
                int compare = CompareKeys(a, b);
                if (0 == compare)
                {
                    // Prefer the non-prefix/exclusive range
                    if (a.IsPrefix || b.IsPrefix)
                    {
                        min = a.IsPrefix ? b : a;
                    }
                    else
                    {
                        min = !a.IsInclusive ? a : b;
                    }
                }
                else
                {
                    if (a.IsPrefix && b.IsPrefix)
                    {
                        min = ComparePrefixes(a, b) < 0 ? a : b;
                    }
                    else if (a.IsPrefix)
                    {
                        min = CompareNonPrefixAndPrefix(b, a) < 0 ? b : a;
                    }
                    else if (b.IsPrefix)
                    {
                        min = CompareNonPrefixAndPrefix(a, b) < 0 ? a : b;
                    }
                    else
                    {
                        min = compare < 0 ? a : b;
                    }
                }
            }
            else
            {
                min = null;
            }

            return min;
        }