/// <summary>
        /// Searches the last segment.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        public int SearchLastSegment(SearchMarkState <T> state)
        {
            if (m_segments.Count <= 0)
            {
                return(-1);
            }

            var lastSegment = m_segments[m_segments.Count - 1];

            if (lastSegment == null)
            {
                return(-1);
            }

            var result = lastSegment.Array.SearchMark(lastSegment.Offset, lastSegment.Count, state.Mark);

            if (!result.HasValue)
            {
                return(-1);
            }

            if (result.Value > 0)
            {
                state.Matched = 0;
                return(result.Value - lastSegment.Offset + lastSegment.From);
            }

            state.Matched = 0 - result.Value;
            return(-1);
        }
Esempio n. 2
0
        /// <summary>
        /// Searches the mark from source.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">The source.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="length">The length.</param>
        /// <param name="searchState">State of the search.</param>
        /// <returns></returns>
        public static int SearchMark <T>(this IList <T> source, int offset, int length, SearchMarkState <T> searchState)
            where T : IEquatable <T>
        {
            int?result = source.SearchMark(offset, length, searchState.Mark, searchState.Matched);

            if (!result.HasValue)
            {
                searchState.Matched = 0;
                return(-1);
            }

            if (result.Value < 0)
            {
                searchState.Matched = 0 - result.Value;
                return(-1);
            }

            searchState.Matched = 0;
            return(result.Value);
        }