830 - MaqIndex::LookupWord(): Difference between revisions

From Genome Analysis Wiki
Jump to navigationJump to search
Created page with "<source lang="cpp"> bool MaqIndex::LookupWord(String & sequence, int offset, unsigned int & firstOccurrence, unsigned int & lastOccurrence) { firstOccurrence = 0; lastOccurr..."
 
No edit summary
 
Line 2: Line 2:
bool MaqIndex::LookupWord(String & sequence, int offset, unsigned int & firstOccurrence, unsigned int & lastOccurrence)
bool MaqIndex::LookupWord(String & sequence, int offset, unsigned int & firstOccurrence, unsigned int & lastOccurrence)
{
{
firstOccurrence = 0;
  firstOccurrence = 0;
lastOccurrence = sortedPositions.Length() - 1;
  lastOccurrence = sortedPositions.Length() - 1;


if (lastOccurrence < 0)
  if (lastOccurrence < 0)
return false;
return false;


   unsigned int firstMax = lastOccurrence;
   unsigned int firstMax = lastOccurrence;
Line 15: Line 15:


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



Latest revision as of 16:09, 28 October 2013

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;
}