public void AddRef(uint strokeId) { if (RefCountMap.ContainsKey(strokeId)) { RefCountMap[strokeId]++; } }
public IReadOnlyList <uint> AddStrokes(IReadOnlyList <InkStroke> inkStrokes) { var strokeIds = new List <uint>(); var strokeIdArray = new uint[inkStrokes.Count]; if (inkStrokes.Count == 0) { return(strokeIds.AsReadOnly()); } // Duplicate list. var strokesToAdd = inkStrokes.ToList(); // Keep a second copy that we can search through. var inkStrokesSearchList = inkStrokes.ToList(); // First search through existing strokes. foreach (var pair in StrokeMap) { var index = strokesToAdd.FindIndex(stroke => stroke == pair.Value); if (index >= 0) { strokesToAdd.RemoveAt(index); var index2 = inkStrokesSearchList.FindIndex(stroke => stroke == pair.Value); if (index2 >= 0) { strokeIdArray[index2] = pair.Key; } } } // Add remaining strokes. foreach (var stroke in strokesToAdd) { uint newId = TotalStrokeCount; ++TotalStrokeCount; StrokeMap.Add(newId, stroke); RefCountMap.Add(newId, 0); var index = inkStrokesSearchList.FindIndex(listStroke => listStroke == stroke); if (index >= 0) { strokeIdArray[index] = newId; } } // Ensure stroke order is identical. for (uint i = 0; i < inkStrokes.Count; i++) { strokeIds.Add(strokeIdArray[i]); } return(strokeIds.AsReadOnly()); }
public void Dispose() { if (RefCountMap.ContainsKey(Segments)) { RefCountMap[Segments]--; if (RefCountMap[Segments] == 0) { RefCountMap.Remove(Segments); VertexMap = null; IndexMap = null; } } }
public uint AddStroke(InkStroke inkStroke) { if (StrokeMap.ContainsValue(inkStroke)) { return(StrokeMap.FirstOrDefault(x => x.Value == inkStroke).Key); } // Add new stroke. var newId = TotalStrokeCount; ++TotalStrokeCount; StrokeMap.Add(newId, inkStroke); RefCountMap.Add(newId, 0); return(newId); }
public void Dispose() { // Don't delete VBOs unless all DebugRenderBox objects have been deleted if (CreateCaps) { if (RefCountMap.ContainsKey(Hash)) { RefCountMap[Hash]--; if (RefCountMap[Hash] == 0) { RefCountMap.Remove(Hash); VertexMap = null; IndexMap = null; } } } }
public void RemoveRef(uint strokeId) { if (RefCountMap.ContainsKey(strokeId)) { var currentRef = RefCountMap[strokeId]; if (currentRef <= 1) { RefCountMap.Remove(strokeId); StrokeMap.Remove(strokeId); } else { RefCountMap[strokeId]--; } } }
public static IDisposable connect_sorted_distinct_mux <T, TResult>(IList <T> source_list, INotifyCollectionChanged source_notifier, IList <TResult> target, Func <T, IEnumerable <TResult> > selector, IComparer <TResult> comparer, IEqualityComparer <TResult> eq_comparer) { var ref_count = new RefCountMap <TResult>(eq_comparer); if (target.Count > 0) { target.Clear(); } foreach (var v in source_list) { var r = selector(v); target.InsertSortedDistinct(r, comparer); } return(source_notifier.Subscribe(on_collection_changed)); void on_collection_changed(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: target.InsertSorted(e.NewItems.Cast <T>().SelectMany(selector).Where(ref_count.increment_adds_key), comparer); break; case NotifyCollectionChangedAction.Remove: target.RemoveSorted(e.OldItems.Cast <T>().SelectMany(selector).Where(ref_count.decrement_removes_key), comparer); break; case NotifyCollectionChangedAction.Replace: target.RemoveSorted(e.OldItems.Cast <T>().SelectMany(selector).Where(ref_count.decrement_removes_key), comparer); target.InsertSorted(e.NewItems.Cast <T>().SelectMany(selector).Where(ref_count.increment_adds_key), comparer); break; case NotifyCollectionChangedAction.Reset: target.Clear(); ref_count.Clear(); target.InsertSorted(source_list.SelectMany(selector).Where(ref_count.increment_adds_key), comparer); break; } } }
public void Clear() { StrokeMap.Clear(); RefCountMap.Clear(); TotalStrokeCount = 0; }