コード例 #1
0
        public ReadSpec GetReadSpec(RCSymbol symbol, int limit, bool force, bool fill)
        {
            ReadSpec result = new ReadSpec(this, limit, force, fill);

            if (limit == 0)
            {
                limit = int.MaxValue;
            }
            for (int i = 0; i < symbol.Count; ++i)
            {
                CountRecord current = Get(symbol[i]);
                if (current != null)
                {
                    // Start searching from the first known record.
                    result.Add(symbol[i], current.start, limit);
                }
                else
                {
                    // In this case we know there is no data so any search should begin
                    // from the end of time.
                    result.Add(symbol[i], _dispatched.Count, limit);
                }
            }
            return(result);
        }
コード例 #2
0
        public void Write(RCSymbolScalar scalar, int line)
        {
            CountRecord record;
            Dictionary <RCSymbolScalar, CountRecord> map = _records;

            // It's a delete
            if (line < 0)
            {
                if (map.TryGetValue(scalar, out record))
                {
                    record.deleted = true;
                }
                // map.Remove (scalar);
                scalar = scalar.Previous;
                while (scalar != null)
                {
                    if (map.TryGetValue(scalar, out record))
                    {
                        --record.count;
                        --record.total;
                        record.end = Math.Abs(line);
                    }
                    scalar = scalar.Previous;
                }
            }
            else
            {
                while (scalar != null)
                {
                    if (!map.TryGetValue(scalar, out record))
                    {
                        record       = new CountRecord(scalar, map == _records);
                        map[scalar]  = record;
                        record.start = line;
                    }
                    // I have to take stuff into account here when clearing...
                    // But How? Can I just blow away the counters?
                    ++record.count;
                    ++record.total;
                    record.end = line;
                    scalar     = scalar.Previous;
                    map        = _abstracts;
                }
                _dispatched.Add(false);
            }
        }
コード例 #3
0
        public void Dispatch(RCSymbolScalar scalar, long line)
        {
            Dictionary <RCSymbolScalar, CountRecord> map = _records;

            while (scalar != null)
            {
                // I assume you wouldn't try to dispatch if the symbol was not represented...
                CountRecord record = map[scalar];
                if (line == record.start)
                {
                    ++record.start;
                }
                --record.count;
                scalar = scalar.Previous;
                map    = _abstracts;
            }
            _dispatched[(int)line] = true;
        }
コード例 #4
0
 public Satisfy CanSatisfy(ReadSpec spec)
 {
     if (spec.IgnoreDispatchedRows)
     {
         if (spec.SymbolUnlimited)
         {
             foreach (SpecRecord specRecord in spec)
             {
                 // CountRecord countRecord = Get (specRecord.symbol);
                 CountRecord countRecord = Get(specRecord);
                 // The symbol is missing entirely.
                 if (countRecord == null)
                 {
                     continue;
                 }
                 // If there are zero rows for the symbol then we are never satsified.
                 if (countRecord.count > 0)
                 {
                     return(Satisfy.Yes);
                 }
             }
             return(Satisfy.No);
         }
         else
         {
             foreach (SpecRecord specRecord in spec)
             {
                 // CountRecord countRecord = Get (specRecord.symbol);
                 CountRecord countRecord = Get(specRecord);
                 // The symbol is missing entirely.
                 if (countRecord == null)
                 {
                     return(Satisfy.No);
                 }
                 // If there are zero rows for the symbol then we are never satsified.
                 if (countRecord.count == 0)
                 {
                     return(Satisfy.No);
                 }
                 // We will accept any number of them.
                 if (specRecord.limit == int.MaxValue)
                 {
                     continue;
                 }
                 // There are not enough records to satisfy the spec for this symbol.
                 if (countRecord.count < specRecord.limit)
                 {
                     return(Satisfy.No);
                 }
             }
         }
     }
     else
     {
         if (spec.SymbolUnlimited)
         {
             foreach (SpecRecord specRecord in spec)
             {
                 // CountRecord countRecord = Get (specRecord.symbol);
                 CountRecord countRecord = Get(specRecord);
                 // The symbol is missing entirely.
                 if (countRecord == null)
                 {
                     continue;
                 }
                 // Notice that while dispatching we look at count. Here at total.
                 if (countRecord.total > 0)
                 {
                     if (specRecord.start == 0)
                     {
                         return(Satisfy.Yes);
                     }
                     else
                     {
                         return(Satisfy.Maybe);
                     }
                 }
             }
             return(Satisfy.No);
         }
         else
         {
             if (spec.RecordCount > 0)
             {
                 foreach (SpecRecord specRecord in spec)
                 {
                     CountRecord countRecord = Get(specRecord);
                     // The symbol is missing entirely.
                     if (countRecord == null)
                     {
                         return(Satisfy.No);
                     }
                     // Check there are enough records to satisfy the spec for this symbol.
                     if (specRecord.start == 0)
                     {
                         // We will accept any number of them.
                         if (specRecord.limit == int.MaxValue)
                         {
                             continue;
                         }
                         if (countRecord.total < specRecord.limit)
                         {
                             return(Satisfy.No);
                         }
                     }
                     else
                     {
                         // This is for the case where you use read or last from an arbitrary start
                         // point.
                         // Since we don't track where the symbols are in this counter, we won't
                         // know whether
                         // The query would be satisfied.  We just have to do it and see.
                         return(Satisfy.Maybe);
                     }
                 }
             }
             else
             {
                 return(Satisfy.No);
             }
         }
     }
     return(Satisfy.Yes);
 }