Esempio n. 1
0
        public bool EndsWith(ComposedSet <T, TDB> a)
        {
            int length   = indices.Count;
            var aindices = a.indices;
            int alength  = aindices.Count;

            if (alength > length)
            {
                return(false);
            }
            if (alength == 0)
            {
                return(false);
            }

            for (int i = 1, count = alength + 1; i < count; ++i)
            {
                if (aindices[alength - i] != indices[length - i])
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 2
0
        public static ComposedSet <T, TDB> operator +(ComposedSet <T, TDB> a, T b)
        {
            var newIndices   = new List <int>(a.indices);
            var bComposedSet = new ComposedSet <T, TDB>(b);

            newIndices.AddRange(bComposedSet.indices);
            return(new ComposedSet <T, TDB>(newIndices));
        }
Esempio n. 3
0
        public int FindLastIndex(ComposedSet <T, TDB> a)
        {
            int length   = indices.Count;
            var aindices = a.indices;
            int alength  = aindices.Count;

            if (length == 0)
            {
                return(-1);
            }
            if (alength > length)
            {
                return(-1);
            }
            if (alength == 0)
            {
                return(-1);
            }

            for (int i = length - 1; i >= 0; i--)                       // look from end to start
            {
                if (indices[i] == aindices[0] && i + alength <= length) // First index match, now test the rest
                {
                    for (int j = 0; j < alength; j++)
                    {
                        if (aindices[j] != indices[i + j])
                        {
                            break; // Mis-match continue searching for a matching first index
                        }
                        if (j == alength - 1)
                        {
                            return(i); // Rest was a match, return index of matching start index
                        }
                    }
                }
            }
            return(-1);
        }
Esempio n. 4
0
        public bool StartsWith(ComposedSet <T, TDB> a)
        {
            int length  = indices.Count;
            int alength = a.indices.Count;

            if (alength > length)
            {
                return(false);
            }
            if (alength == 0)
            {
                return(false);
            }

            for (int i = 0; i < alength; ++i)
            {
                if (a.indices[i] != indices[i])
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 5
0
 public ComposedSet(ComposedSet <T, TDB> cset)
 {
     indices  = new List <int>(cset.indices);
     hashCode = CalculateHashCode(indices);
 }
Esempio n. 6
0
 public bool Contains(ComposedSet <T, TDB> a)
 {
     return(FindFirstIndex(a) != -1);
 }
Esempio n. 7
0
 public ComposedSet <T, TDB> TrimEnd(ComposedSet <T, TDB> cset)
 {
     return(EndsWith(cset) ? GetSubset(0, indices.Count - cset.indices.Count) : this);
 }
Esempio n. 8
0
 public static bool IsNullOrEmpty(ComposedSet <T, TDB> cset)
 {
     return(cset == null || cset.indices.Count == 0);
 }