Ejemplo n.º 1
0
        public IReadOnlyList <MergedLogLineIndex> Get(LogSourceSection section)
        {
            var indices = new MergedLogLineIndex[section.Count];

            lock (_syncRoot)
            {
                if (section.Index.Value < _indices.Count)
                {
                    var count = Math.Min((section.Index + section.Count).Value, _indices.Count);
                    _indices.CopyTo(section.Index.Value, indices, 0, count);
                    for (var i = 0; i < section.Count - count; ++i)
                    {
                        indices[section.LastIndex + i] = MergedLogLineIndex.Invalid;
                    }
                }
                else
                {
                    for (var i = 0; i < section.Count; ++i)
                    {
                        indices[i] = MergedLogLineIndex.Invalid;
                    }
                }
            }

            return(indices);
        }
Ejemplo n.º 2
0
        private static bool IsSameLogEntry(MergedLogLineIndex lhs, MergedLogLineIndex rhs)
        {
            // Two log lines refer to the same entry if they are from the SAME source
            // AND if they have the same ORIGINAL log entry index.
            if (lhs.SourceId != rhs.SourceId)
            {
                return(false);
            }

            return(lhs.OriginalLogEntryIndex == rhs.OriginalLogEntryIndex);
        }
Ejemplo n.º 3
0
        private LogEntryIndex CalculateLogEntryIndexFor(int insertionIndex, MergedLogLineIndex index)
        {
            if (insertionIndex > 0)
            {
                var previousIndex = _indices[insertionIndex - 1];
                if (IsSameLogEntry(previousIndex, index))
                {
                    return(previousIndex.MergedLogEntryIndex);
                }

                return(previousIndex.MergedLogEntryIndex + 1);
            }

            return(0);
        }
Ejemplo n.º 4
0
        public int FindInsertionIndexNoLock(MergedLogLineIndex index)
        {
            if (_indices.Count == 0)
            {
                return(0);
            }

            // Changes are we need to insert that index AFTER the last, so let's
            // optimize for that...
            if (index.Timestamp >= _indices[_indices.Count - 1].Timestamp)
            {
                return(_indices.Count);
            }

            var binary = FindInsertionIndexBinary(index.Timestamp);

            /*var actual = FindInsertionIndexLinear(index.Timestamp);
             * if (actual != binary)
             *      throw new NotImplementedException($"Mismatch detected: linear search wants to insert at {actual} and binary wants to insert at {binary} (the latter is incorrect)");
             * return actual*/
            return(binary);
        }