830 - MaqIndex::LookupWord()

From Genome Analysis Wiki
Jump to navigationJump to search
bool MaqIndex::LookupWord(String & sequence, int offset, unsigned int & firstOccurrence, unsigned int & lastOccurrence)
{
   firstOccurrence = 0;
   lastOccurrence = sortedPositions.Length() - 1;

   if (lastOccurrence < 0)
	return false;

   unsigned int firstMax = lastOccurrence;
   int boundaryCheck = CompareToIndex(sequence, offset, 0);

   if (boundaryCheck < 0)
	   return false;

   if (boundaryCheck > 0)
       while (firstMax >= firstOccurrence)
	  {
	  int probe = (firstMax + firstOccurrence) / 2; 
          int test = CompareToIndex(sequence, offset, probe);

          if (test <= 0)
             firstMax = probe - 1;
          else
             firstOccurrence  = probe + 1;
          }

   unsigned int lastMin = firstOccurrence;

   while (lastMin <= lastOccurrence)
   {
      int probe = (lastMin + lastOccurrence) / 2; 
      int test = CompareToIndex(sequence, offset, probe);

      if (test >= 0)
         lastMin = probe + 1;
      else
         lastOccurrence  = probe - 1;
   }

   return lastOccurrence >= firstOccurrence;
}