/// <summary>Called when building the line index completes (success or failure)</summary> private void MergeResults(State d, List <RangeI> n_line_index, bool reload, ProgressFunc progress) { // This method runs in the main thread, so if the build issue is the same at // the start of this method it can't be changed until after this function returns. if (!progress(0, n_line_index.Count)) { return; } // Both old and new ranges are expected to be contiguous var old_rng = Tools.GetRange(m_line_index); var new_rng = Tools.GetRange(n_line_index); int row_delta = 0; // Replace 'm_line_index' with 'line_index' if (reload) { // Try to determine the row delta // Use any range overlap to work out the row delta. // If the ranges overlap, we can search for the start address of the intersection in both // ranges to get the row delta. If the don't overlap, the best we can do is say the direction. var intersect = old_rng.Intersect(new_rng); if (!intersect.Empty) { var old_idx = FindIndex(m_line_index, intersect.Beg); var new_idx = FindIndex(n_line_index, intersect.Beg); row_delta = new_idx - old_idx; } else { row_delta = intersect.Beg == old_rng.End ? -n_line_index.Count : n_line_index.Count; } // Replace the line index m_line_index.Assign(n_line_index); } // The new range is to the left of the old range else if (new_rng.Beg < old_rng.Beg && new_rng.End <= old_rng.End) { // Make sure there's no overlap by removing data from 'm_line_index' var trim = 0; for (; trim != m_line_index.Count && m_line_index[trim].Beg < new_rng.End; ++trim) { } m_line_index.RemoveRange(0, trim); row_delta -= trim; // Insert the new lines m_line_index.InsertRange(0, n_line_index); row_delta += n_line_index.Count; // Trim the tail if (m_line_index.Count > d.m_line_cache_count) { m_line_index.RemoveRange(d.m_line_cache_count, m_line_index.Count - d.m_line_cache_count); } } // The new range is to the right of the old range else if (new_rng.Beg >= old_rng.Beg && new_rng.End > old_rng.End) { // Make sure there's no overlap by removing data from 'm_line_index' var trim = 0; for (; trim != m_line_index.Count && m_line_index.Back(trim).End > new_rng.Beg; ++trim) { } m_line_index.RemoveRange(m_line_index.Count - trim, trim); // Insert the new lines m_line_index.InsertRange(m_line_index.Count, n_line_index); // Trim the head if (m_line_index.Count > d.m_line_cache_count) { row_delta -= m_line_index.Count - d.m_line_cache_count; m_line_index.RemoveRange(0, m_line_index.Count - d.m_line_cache_count); } } // Save the new index state m_state = d; // Notify of update complete BuildComplete?.Invoke(this, new BuildCompleteEventArgs(new_rng, row_delta)); }
protected virtual void OnBuildComplete(bool success) { BuildComplete?.Invoke(this, success); }
protected virtual void OnBuildComplete(EventArgs args) { BuildComplete?.Invoke(this, args); }