Logo Search packages:      
Sourcecode: pan version File versions

unsigned long Numbers::mark_range ( const Range rr  )  [private]

Returns:
the number of articles newly-marked as read

Definition at line 62 of file numbers.cc.

References pan::Numbers::Range::contains(), pan::Numbers::Range::high, and pan::Numbers::Range::low.

Referenced by mark_one(), mark_range(), mark_str(), and pan::DataImpl::set_xover_low().

{
   int i;
   unsigned long retval = 0;
   bool range_found = false;
   int low_index (std::lower_bound (_marked.begin(), _marked.end(), rr.low)
                  - _marked.begin());
   int high_index (std::lower_bound (_marked.begin(), _marked.end(), rr.high)
                   - _marked.begin());

   retval = rr.high + 1 - rr.low;

   for (i=low_index; i<=high_index && i<(int)_marked.size(); ++i)
   {
      Range& r = _marked[i];

      if (rr.contains (r)) /* read range is engulfed; remove */
      {
         retval -= r.high+1 - r.low; /* remove r from retval */
         _marked.erase (_marked.begin() + i);
         --high_index;
         --i;
      }
      else if (r.contains (rr)) /* no-op */
      {
         retval = 0;
         range_found = true;
      }
      else if (r.contains (rr.high)) /* change low */
      {
         Range * prev = !i ? NULL : &_marked[i-1];
         range_found = true;
         retval -= rr.high+1 - r.low; /* remove intersection from retval */
         r.low = prev ? std::max(rr.low, prev->high+1) : rr.low;
      }
      else if (r.contains (rr.low)) /* change high */
      {
         Range * next = i==(int)_marked.size()-1 ? NULL : &_marked[i+1];
         range_found = true;
         retval -= r.high+1 - rr.low; /* remove intersection from retval */
         r.high = next ? std::min(rr.high, next->low-1) : rr.high;
      }
   }

   if (!range_found)
   {
      _marked.insert (_marked.begin()+low_index, rr);
      --low_index;
      ++high_index;
   }

   for (i=low_index; i<=high_index && i<(int)_marked.size(); )
   {
      if (maybe_merge_ranges (_marked, i))
         --high_index;
      else
         ++i;
   }

   return retval;
}


Generated by  Doxygen 1.6.0   Back to index