/// <summary>Insert the given element to the created/deleted list.</summary> /// <param name="i"> /// the insertion point defined /// in /// <see cref="Sharpen.Collections.BinarySearch{T}(System.Collections.Generic.IList{E}, object) /// "/> /// </param> private void Insert(Diff.ListType type, E element, int i) { IList <E> list = type == Diff.ListType.Created ? created : deleted; if (i >= 0) { throw new Exception("Element already exists: element=" + element + ", " + type + "=" + list); } if (list == null) { list = new AList <E>(DefaultArrayInitialCapacity); if (type == Diff.ListType.Created) { created = list; } else { if (type == Diff.ListType.Deleted) { deleted = list; } } } list.Add(-i - 1, element); }
/// <returns> /// null if the element is not found; /// otherwise, return the element in the created/deleted list. /// </returns> public virtual E Search(Diff.ListType type, K name) { IList <E> list = GetList(type); int c = Search(list, name); return(c < 0 ? null : list[c]); }
private bool RemoveChild(Diff.ListType type, INode child) { IList <INode> list = GetList(type); int i = SearchIndex(type, child.GetLocalNameBytes()); if (i >= 0 && list[i] == child) { list.Remove(i); return(true); } return(false); }
/// <summary>Remove the given child in the created/deleted list, if there is any.</summary> public virtual bool RemoveChild(Diff.ListType type, INode child) { IList <DirectoryWithSnapshotFeature.DirectoryDiff> diffList = AsList(); for (int i = diffList.Count - 1; i >= 0; i--) { DirectoryWithSnapshotFeature.ChildrenDiff diff = diffList[i].diff; if (diff.RemoveChild(type, child)) { return(true); } } return(false); }
/// <summary>Replace the given child from the created/deleted list.</summary> /// <returns>true if the child is replaced; false if the child is not found.</returns> private bool Replace(Diff.ListType type, INode oldChild, INode newChild) { IList <INode> list = GetList(type); int i = Search(list, oldChild.GetLocalNameBytes()); if (i < 0 || list[i].GetId() != oldChild.GetId()) { return(false); } INode removed = list.Set(i, newChild); Preconditions.CheckState(removed == oldChild); return(true); }
public virtual int SearchIndex(Diff.ListType type, K name) { return(Search(GetList(type), name)); }
/// <returns>the created list, which is never null.</returns> public virtual IList <E> GetList(Diff.ListType type) { IList <E> list = type == Diff.ListType.Created ? created : deleted; return(list == null?Sharpen.Collections.EmptyList <E>() : list); }