Esempio n. 1
0
        /// <summary>
        /// Merge two lists as and
        /// </summary>
        /// <param name="src"></param>
        /// <param name="dest"></param>
        /// <returns></returns>
        public static AscIntList MergeAnd(AscIntList src, AscIntList dest)
        {
            if (src == null)
            {
                return(new AscIntList());
            }

            if (dest == null)
            {
                return(new AscIntList());
            }

            src.Compress();
            dest.Compress();

            if (src.Count == 0)
            {
                return(src);
            }

            if (dest.Count == 0)
            {
                return(dest);
            }

            AscIntList result = new AscIntList(Math.Min(src.Count, dest.Count));

            int srcIndex  = 0;
            int destIndex = 0;
            int srcLen    = src.Count;
            int destLen   = dest.Count;

            while (srcIndex < srcLen && destIndex < destLen)
            {
                int sValue = src[srcIndex];
                int dValue = dest[destIndex];
                if (sValue < dValue)
                {
                    srcIndex++;
                }
                else if (sValue > dValue)
                {
                    destIndex++;
                }
                else
                {
                    result.Add(sValue);
                    srcIndex++;
                    destIndex++;
                }
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Merge two lists as or
        /// </summary>
        /// <param name="src"></param>
        /// <param name="dest"></param>
        /// <returns></returns>
        public static AscIntList MergeOr(AscIntList src, AscIntList dest)
        {
            if (src == null)
            {
                return(dest);
            }

            if (dest == null)
            {
                return(src);
            }

            src.Compress();
            dest.Compress();

            if (src.Count == 0)
            {
                return(dest);
            }

            if (dest.Count == 0)
            {
                return(src);
            }

            AscIntList result = new AscIntList(src.Count + dest.Count);

            int srcIndex  = 0;
            int destIndex = 0;
            int srcLen    = src.Count;
            int destLen   = dest.Count;

            while (srcIndex < srcLen && destIndex < destLen)
            {
                int sValue = src[srcIndex];
                int dValue = dest[destIndex];
                if (sValue < dValue)
                {
                    result.Add(sValue);
                    srcIndex++;
                }
                else if (sValue > dValue)
                {
                    result.Add(dValue);
                    destIndex++;
                }
                else
                {
                    result.Add(sValue);
                    srcIndex++;
                    destIndex++;
                }
            }

            if (srcIndex < srcLen)
            {
                for (int i = srcIndex; i < srcLen; i++)
                {
                    result.Add(src[i]);
                }
            }

            if (destIndex < destLen)
            {
                for (int i = destIndex; i < destLen; i++)
                {
                    result.Add(dest[i]);
                }
            }

            return(result);
        }