Accord.IO.SparseReader.guessSampleSize C# (CSharp) Method

guessSampleSize() private method

private guessSampleSize ( ) : int
return int
        private int guessSampleSize()
        {
            // Scan the whole file and identify
            // the largest index we can find. 

            long position = reader.GetPosition();

            reader.BaseStream.Seek(0, SeekOrigin.Begin);

            int max = 0;

            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();
                int lastColon = line.LastIndexOf(':');
                int lastSpace = line.LastIndexOf(' ', lastColon);

                string str = line.Substring(lastSpace, lastColon - lastSpace);
                int index = int.Parse(str, CultureInfo.InvariantCulture) - 1;

                if (index >= max)
                    max = index + 1;
            }

            // rewind the stream to where we found it
            reader.BaseStream.Seek(position, SeekOrigin.Begin);

            return max;
        }