public TNode Remove <TNode>(IListNode <TData> node) where TNode : IListNode <TData>, new() { node.Previous.Next = node.Next; node.Next.Previous = node.Previous; return((TNode)node); }
public LinkedListImpl() { _first = new HeadNode(); _last = new TailNode(); _first.Next = _last; _last.Previous = _first; }
public IListNode <TData> SearchBackward <TNode>(IListNode <TData> node) where TNode : IListNode <TData>, new() { var current = node; while (true) { if (current is HeadNode) { break; } if (ReferenceEquals(null, current)) { break; } if (node?.Value?.Equals(current.Value) ?? ReferenceEquals(null, current.Value)) { break; } current = current.Previous; } return((TNode)current); }
public IListNode Build() { IListNode node = Substitute.For <IListNode>(); node.ChildNode.Returns(ChildNode); node.CreateList().Returns(new List <T>()); node.GetListCount(Arg.Any <IList <T> >()).Returns(args => { IList <T> list = (IList <T>)args[0]; return(list.Count); }); node.GetListEntry(Arg.Any <IList <T> >(), Arg.Any <int>()).Returns(args => { IList <T> list = (IList <T>)args[0]; int index = (int)args[1]; return(list[index]); }); SetupAddEntry(node); return(node); }
public void Test_Writing_A_List_With_Duplicate_Entry_Count() { IList <string> list = BuildStringList(); IListNode listNode = BuildStringListNode(duplicateEntryCount: true); uint offset = 0xFFEEDDCC; binaryWriter.Position.Returns(0); binaryWriter.WriteInt32(ArgX.OrderedDo <int>( _ => binaryWriter.Position.Returns(0), _ => binaryWriter.Position.Returns(offset) )); binaryWriter.WriteUInt32(Arg.Do <uint>(_ => binaryWriter.Position.Returns(0))); uint result = listNode.Write(binaryWriter, list); result.Should().Be(offset); Received.InOrder(() => { binaryWriter.WriteInt32(list.Count); binaryWriter.WriteInt32(list.Count); binaryWriter.WriteUInt32(0); // offset placeholder }); }
private void VerifyWriteTreeWithNestedLists( IDataNode node, TreeWithNestedLists.Class value, uint originalPosition1, uint originalPosition2, uint offsetPosition1, uint offsetPosition2 ) { node.Write(binaryWriter, value); IListNode listNode1 = node.Edges[0].ChildNode as IListNode; listNode1.Write(binaryWriter, value.List1); IListNode listNode2 = node.Edges[1].ChildNode as IListNode; listNode2.Write(binaryWriter, value.List2); VerifyBinaryWriterWritesOffset(originalPosition1, offsetPosition1); foreach (var entry in value.List1) { VerifyWriteTreeWithHeight1(listNode1.ChildNode, entry); } VerifyBinaryWriterWritesOffset(originalPosition2, offsetPosition2); foreach (var entry in value.List2) { VerifyWriteTreeWithHeight2(listNode2.ChildNode, entry); } }
/// <summary> /// Removes the supplied node from the list /// /// Note: This implementation is unsafe as there are no checks to ensure /// that the supplied node is actually a part of this list. In order to /// do that we would need to keep a reference to the parent list within /// the node as well. I haven't done that yet. :) /// /// Complexity: O(n) worst as we have to traverse the list to get the /// neighbours /// </summary> /// <param name="node"></param> public void Remove(IListNode <T> node) { ValidateNotEmpty(); var oldNode = node as ListNode <T>; if (oldNode == _back) { RemoveBack(); } else if (oldNode == _front) { RemoveFront(); } else { var current = _front; while (current != null) { if (current.Next == oldNode) { current.Next = oldNode.Next; --Count; return; } current = current.Next; } } }
/// <summary> /// Adds a node to the list before the node supplied /// /// Note: This implementation is unsafe as there are no checks to ensure /// that the supplied node is actually a part of this list. In order to /// do that we would need to keep a reference to the parent list within /// the node as well. I haven't done that yet. :) /// /// Complexity: O(n) as we have to traverse the list to get the previous node /// </summary> /// <param name="node">The node to add the new node before</param> /// <param name="data">The data to add to the node</param> public void AddBefore(IListNode <T> node, T data) { var oldNode = node as ListNode <T>; var newNode = new ListNode <T>(data); if (oldNode == null) { AddNodeToBack(newNode); } else if (oldNode == _front) { AddNodeToFront(newNode); } else { var current = _front; while (current != null) { if (current.Next == oldNode) { newNode.Next = current.Next; current.Next = newNode; ++Count; return; } current = current.Next; } } }
public ImmutableLinkedList <T> Insert(int index, T item) { if (index < 0) { throw ExceptionHelper.GetIndexNegativeException(index, "item"); } if (index > Length) { throw ExceptionHelper.GetIndexTooBigException(index, Length, "item"); } var nodes = new IListNode <T> [index]; var current = _first; for (var i = 0; i < index; i++) { nodes[i] = current; current = current.Tail; } current = current.Prepend(item); for (var i = index - 1; i >= 0; i--) { current = nodes[i].ChangeTail(current); } return(new ImmutableLinkedList <T>(current, Length + 1)); }
public static NodeViewCellDetail Create(IListNode nodeView) { var view = (NodeViewCellDetail)Nib.Instantiate(null, null)[0]; view._nodeView = nodeView; return(view); }
public void Test_Adding_A_Null_Entry_To_A_List() { IListNode listNode = BuildStringListNode(); Action action = () => listNode.AddListEntry(new List <string>(), null); action.Should() .ThrowArgumentNullException("value"); }
public void Test_Adding_An_Entry_To_A_Null_List() { IListNode listNode = BuildStringListNode(); Action action = () => listNode.AddListEntry(null, string.Empty); action.Should() .ThrowArgumentNullException("list"); }
public void Delete(IListNode node) { if (!(node is ListNode)) { throw new System.ArgumentException("Cannot delete a node from another type of list", nameof(node)); } list.Remove((ListNode)node); }
public void Test_Adding_An_Entry_To_A_List() { IList <string> list = new List <string>(); IListNode listNode = BuildStringListNode(); string value = "value"; listNode.AddListEntry(list, value); list.Should().HaveCount(1); list[0].Should().BeSameAs(value); }
public void Test_Adding_An_Element_To_A_List_Of_Incorrect_Type() { IList <int> list = new List <int>(); IListNode listNode = BuildStringListNode(); Action action = () => listNode.AddListEntry(list, string.Empty); action.Should() .ThrowExactly <ArgumentException>() .WithMessage($"List argument is of type {list.GetType().Name} which should " + $"implement {typeof(IList<string>).Name} but doesn't."); }
/// <summary> /// When implemented by a class, copies the elements of the /// <c>Collections.ICollection</c> to an Array, starting at a /// particular Array index. /// </summary> /// <param name="array"> /// The one-dimensional <c>Array</c> that is the destination of the /// elements copied from <c>Collections.ICollection</c>. The /// <c>Array</c> must have zero-based indexing. /// </param> /// <param name="index"> /// The zero-based index in array at which copying begins. /// </param> public virtual void CopyTo(System.Array array, System.Int32 index) { IListNode node = head.Next; while (node != head) { array.SetValue(node.Value, index); index++; node = node.Next; } }
public void Test_Creating_A_List_Instance() { IListNode listNode = BuildStringListNode(); object result = listNode.CreateList(); result.Should() .BeOfType <List <string> >() .Which .Should() .HaveCount(0); }
public void Test_Adding_An_Element_Of_Invalid_Type_To_A_List() { IList <string> list = BuildStringList(); IListNode listNode = BuildStringListNode(); int value = 1; Action action = () => listNode.AddListEntry(list, value); action.Should() .ThrowExactly <ArgumentException>() .WithMessage($"Value should be of type {typeof(string).Name}, " + $"but is of type {value.GetType().Name} instead."); }
public void Test_Getting_The_Entries_From_A_Non_Empty_List() { IList <string> list = BuildStringList(); IListNode listNode = BuildStringListNode(); for (int n = 0; n < list.Count; n++) { listNode.GetListEntry(list, n) .Should() .BeSameAs(list[n]); } }
public void Test_Reading_Duplicate_Entry_Count() { IListNode listNode = BuildStringListNode(duplicateEntryCount: true); int offset = 20; binaryReader.ReadInt32().Returns(offset, offset); int result = listNode.ReadEntryCount(binaryReader); result.Should().Be(offset); binaryReader.Received(2).ReadInt32(); }
public IListNode <TData> InsertBefore <TNode>(IListNode <TData> node, TData value) where TNode : IListNode <TData>, new() { var @new = new TNode { Next = node, Previous = node.Previous, Value = value, }; node.Previous.Next = @new; node.Previous = @new; return(@new); }
public bool Move() { if (currentNode != null) { if (currentNode.Next != null) { currentNode = currentNode.Next; return(true); } return(false); } currentNode = firstNode; return(currentNode != null); }
private void SetupAddEntry(IListNode node) { // Setup in this convoluted way so the "list" variable // is different everytime "AddListEntry" is called // otherwise "list" will be the same for different calls void setup() { IList <T> list = default(IList <T>); node.AddListEntry( Arg.Do <IList <T> >(val => list = val), Arg.Do <T>(entry => list.Add(entry)) ); } setup(); }
private void ProcessListNode(IBinaryWriter binaryWriter, IListNode node, object list) { uint offsetPosition = node.Write(binaryWriter, list); int count = node.GetListCount(list); if (count == 0) { Enqueue(node.ChildNode, null, offsetPosition); return; } Enqueue(node.ChildNode, node.GetListEntry(list, 0), offsetPosition); for (int n = 1; n < count; ++n) { Enqueue(node.ChildNode, node.GetListEntry(list, n)); } }
private object ProcessListNode(IBinaryReader binaryReader, IListNode listNode) { int count = listNode.ReadEntryCount(binaryReader); uint offset = listNode.ReadOffset(binaryReader); object list = listNode.CreateList(); if (count != 0) { binaryReader.DoAtPosition(offset, () => { for (int n = 0; n < count; ++n) { object entry = ProcessDataNode(binaryReader, listNode.ChildNode); listNode.AddListEntry(list, entry); } }); } return(list); }
/// <summary> /// Adds a node to the list after the node supplied /// /// Note: This implementation is unsafe as there are no checks to ensure /// that the supplied node is actually a part of this list. In order to /// do that we would need to keep a reference to the parent list within /// the node as well. I haven't done that yet. :) /// /// Complexity: O(1) as we have everything we need to update the list /// </summary> /// <param name="node">The node to add the new node after</param> /// <param name="data">The data to add to the node</param> public void AddAfter(IListNode <T> node, T data) { var oldNode = node as ListNode <T>; var newNode = new ListNode <T>(data); if (oldNode == null) { AddNodeToFront(newNode); } else if (oldNode.Next == null) { AddNodeToBack(newNode); } else { newNode.Next = oldNode.Next; oldNode.Next = newNode; ++Count; } }
public void ExtensionsHasTable(int xi, int n) { int newKey = GetHash(n, xi); if (Values.Length > newKey) { key = newKey; } else { IListNode[] newValues = new IListNode[newKey + 1]; key = newKey; for (int i = 0; i < Values.Length; i++) { newValues[i] = Values[i]; } Values = newValues; } }
public static NodeViewCell Create(IListNode nodeView) { var view = (NodeViewCell)Nib.Instantiate(null, null)[0]; view._defaultView = NodeViewCellDefault.Create(); view._defaultView.Frame = view.Frame; view._detail = NodeViewCellDetail.Create(nodeView); view._detail.Frame = view.Frame; view.Add(view._detail); view.Add(view._defaultView); view._lpg = new NodeGestureRecognizer((Action <UIPanGestureRecognizer>)((e) => { CGPoint change = e.TranslationInView(view); if (e.State == UIGestureRecognizerState.Changed) { e.CancelsTouchesInView |= Math.Abs(change.X) > 0; if (nodeView.PresentingDetail) { nodeView.ResetCells(view); } view._defaultView.Frame = new CGRect(new CGPoint(change.X <= 0 ? change.X : 0, view._defaultView.Frame.Y), view._defaultView.Frame.Size); } else if (e.State == UIGestureRecognizerState.Ended) { var width = -view._defaultView.Frame.Width; nodeView.PresentingDetail = change.X < width / 2; var newX = nodeView.PresentingDetail ? width : 0; UIView.Animate(.65d, 0, UIViewAnimationOptions.CurveEaseOut, () => { view._defaultView.Frame = new CGRect(new CGPoint(newX, view._defaultView.Frame.Y), view._defaultView.Frame.Size); }, null); e.CancelsTouchesInView = false; } })); view._lpg.CancelsTouchesInView = false; view.AddGestureRecognizer(view._lpg); return(view); }
/// <summary> /// Removes the supplied node from the list /// /// Note: This implementation is unsafe as there are no checks to ensure /// that the supplied node is actually a part of this list. In order to /// do that we would need to keep a reference to the parent list within /// the node as well. I haven't done that yet. :) /// /// Complexity: O(1) worst as we have all the information within the node /// </summary> /// <param name="node"></param> public void Remove(IListNode <T> node) { ValidateNotEmpty(); var oldNode = node as ListNode <T>; if (oldNode.Next == null) { RemoveBack(); } else if (oldNode.Prev == null) { RemoveFront(); } else { oldNode.Prev.Next = oldNode.Next; oldNode.Next.Prev = oldNode.Prev; --Count; } }
public static NodeViewCell Create(IListNode nodeView) { var view = (NodeViewCell)Nib.Instantiate(null, null)[0]; view._defaultView = NodeViewCellDefault.Create(); view._defaultView.Frame = view.Frame; view._detail = NodeViewCellDetail.Create(nodeView); view._detail.Frame = view.Frame; view.Add(view._detail); view.Add(view._defaultView); view._lpg = new NodeGestureRecognizer((Action<UIPanGestureRecognizer>)((e) => { CGPoint change = e.TranslationInView(view); if (e.State == UIGestureRecognizerState.Changed) { e.CancelsTouchesInView |= Math.Abs(change.X) > 0; if (nodeView.PresentingDetail) { nodeView.ResetCells(view); } view._defaultView.Frame = new CGRect(new CGPoint(change.X <= 0 ? change.X : 0, view._defaultView.Frame.Y), view._defaultView.Frame.Size); } else if (e.State == UIGestureRecognizerState.Ended) { var width = -view._defaultView.Frame.Width; nodeView.PresentingDetail = change.X < width / 2; var newX = nodeView.PresentingDetail ? width : 0; UIView.Animate(.65d, 0, UIViewAnimationOptions.CurveEaseOut, () => { view._defaultView.Frame = new CGRect(new CGPoint(newX, view._defaultView.Frame.Y), view._defaultView.Frame.Size); }, null); e.CancelsTouchesInView = false; } })); view._lpg.CancelsTouchesInView = false; view.AddGestureRecognizer(view._lpg); return view; }
private void DrawRightFrame(Vector2 frameSize) { var rightFrameNode = ListView.GetSelectedNode(ListViewID); if (_currentRightFrameNode != rightFrameNode) { _currentRightFrameNode = rightFrameNode; Task.Run(() => { string newText = rightFrameNode.GetNodeSpecialText(); TextInputBuffer newBuffer = new TextInputBuffer(newText); InvokeOnMainThread(() => { if (_currentRightFrameNode == rightFrameNode) { _rightFrameTextBuffer.Dispose(); _rightFrameTextBuffer = newBuffer; _rightFrameRawText = newText; } else { newBuffer.Dispose(); } }); }); } if (_selectableText) { ImGui.PushStyleColor(ColorTarget.FrameBg, new Vector4(1, 1, 1, 1)); ImGui.PushStyleColor(ColorTarget.Text, new Vector4(0, 0, 0, 1)); ImGui.InputTextMultiline( "", _rightFrameTextBuffer.Buffer, _rightFrameTextBuffer.Length, frameSize * new Vector2(2.5f, 1f) - Vector2.UnitY * 35f, InputTextFlags.ReadOnly, null, IntPtr.Zero); ImGui.PopStyleColor(2); } else { unsafe { byte* start = (byte*)_rightFrameTextBuffer.Buffer.ToPointer(); byte* end = start + _rightFrameTextBuffer.Length; if (_wrapRightFrame) { ImGuiNative.igPushTextWrapPos(ImGuiNative.igGetColumnWidth(ImGuiNative.igGetColumnIndex())); } ImGuiNative.igTextUnformatted(start, end); if (_wrapRightFrame) { ImGuiNative.igPopTextWrapPos(); } } } }
public static void SetSelectedNode(IListNode node) { Debug.Assert(s_currentViewID != null); s_selectedNodes[s_currentViewID] = node; }
public static LocationChooserView Create(string path, bool newFileUploadChooser, IListNode nodeView) { int selectedBox = Waardes.Instance.GeselecteerdeBox; var view = (LocationChooserView)Nib.Instantiate(null, null)[0]; view._BestandsnaamLabel.Text = path.Substring(path.LastIndexOf('/') + 1); view._parentNodeView = nodeView; view.NewFileUpload = newFileUploadChooser; view.OpslaanButton.TouchUpInside += async(object sender, EventArgs e) => { try{ if(view.NewFileUpload == true){ //Nieuw bestand uploaden view.RemoveFromSuperview(); DialogHelper.ShowBlockingProgressDialog("Uploaden", "Bezig met het uploaden van een bestand"); string filename = Path.Combine(view._dataSource.NodeStack.Peek().Path, path.Substring(path.LastIndexOf('/') + 1)); bool uploadSucceeded = await DataLayer.Instance.UploadFile(filename, path); if(uploadSucceeded){ var ef = DataLayer.Instance.GetFolder(view._dataSource.NodeStack.Peek().Path, true).Result; UIAlertView alertSuccess = new UIAlertView("Succesvol", "Het bestand is succesvol geupload", null, "OK"); alertSuccess.Show(); }else{ DialogHelper.ShowErrorDialog("Fout", "Er is een fout opgetreden bij het uploaden van het bestand" + "\nProbeer het a.u.b. opnieuw"); } DialogHelper.HideBlockingProgressDialog(); File.Delete(path); Waardes.Instance.GeselecteerdeBox = selectedBox; }else{ //Verplaatsen van bestand DialogHelper.ShowBlockingProgressDialog("Verplaatsen", "Bezig met het verplaatsen van het bestand"); string destinationPath = System.IO.Path.Combine(view._dataSource.NodeStack.Peek().Path, path.Substring(path.LastIndexOf('/') + 1)); if(path.Equals(destinationPath)){ DialogHelper.HideBlockingProgressDialog(); DialogHelper.ShowErrorDialog("Fout", "Gekozen map mag niet hetzelfde zijn als de oorspronkelijke locatie van het bestand"); } else{ bool uploadedSucceeded = false; bool deleteSucceeded = false; //decrypt file to filesystem and get path of decrypted file string filePath = await DataLayer.Instance.GetFilePath (path); //upload file to selected destination folder uploadedSucceeded = await DataLayer.Instance.UploadFile (destinationPath, filePath); //remove file from old destination if(uploadedSucceeded){ deleteSucceeded = await DataLayer.Instance.DeleteFileOrFolder (path); //Update folder where file is moved to DataLayer.Instance.GetFolder(view._dataSource.NodeStack.Peek().Path, true); } //close this dialog en show succeeded message if(deleteSucceeded){ DialogHelper.HideBlockingProgressDialog(); view.RemoveFromSuperview(); view._parentNodeView.Refresh(true, true); UIAlertView alertSuccess = new UIAlertView("Succesvol", "Het bestand is succesvol verplaatst", null, "OK"); alertSuccess.Show(); }else{ DialogHelper.HideBlockingProgressDialog(); view.RemoveFromSuperview(); view._parentNodeView.Refresh(true, true); DialogHelper.ShowErrorDialog("Fout", "Er is een fout opgetreden bij het verplaatsen van het bestand" + "\n Ververs a.u.b. de map en probeer het opnieuw."); } } } } catch (Exception ex){ Insights.Report(ex); DialogHelper.HideBlockingProgressDialog(); string message; if(view.NewFileUpload){ message = "uploaden van het bestand. \nProbeer het a.u.b. opnieuw."; }else{ message = "verplaatsen van het bestand. \nVervers a.u.b. de map en probeer het opnieuw."; } DialogHelper.ShowErrorDialog("Fout", "Er is een fout opgetreden bij het "+ message); } }; view.TerugButton.TouchUpInside += (object sender, EventArgs e) => { view._dataSource.Back(); view.TableView.ReloadData(); }; view.SluitenButton.TouchUpInside += (object sender, EventArgs e) => { if(view.NewFileUpload){ Waardes.Instance.GeselecteerdeBox = selectedBox; File.Delete(path); } view.RemoveFromSuperview(); }; view._dataSource = new LocationChooseDataSource(view, view.NewFileUpload); view.TableView.Source = view._dataSource; view.ShowSaveButton(false); return view; }
private ImmutableLinkedList(IListNode <T> first, int count) { _first = first; Length = count; }
public void MoveFile(string pathOfFileToMove, IListNode nodeView) { var view = LocationChooserView.Create(pathOfFileToMove, false, nodeView); View.Add(view); }
public static NodeViewCellDetail Create(IListNode nodeView) { var view = (NodeViewCellDetail)Nib.Instantiate(null, null)[0]; view._nodeView = nodeView; return view; }