public virtual bool Upload(string localFile, string remoteFile, DUpload up, DTransferring trans, DDiscarded discarded, uint flags) { if (localFile == null || localFile.Length == 0) { return(false); } if (remoteFile == null || remoteFile.Length == 0) { return(false); } CContext context = new CContext(true, flags); context.Upload = up; context.Transferring = trans; context.Discarded = discarded; context.FilePath = remoteFile; context.LocalFile = localFile; lock (m_csFile) { m_vContext.AddToBack(context); if (m_vContext.Count == 1) { ClientCoreLoader.PostProcessing(AttachedClientSocket.Handle, 0, 0); AttachedClientSocket.DoEcho(); //make sure WaitAll works correctly } } return(true); }
public virtual bool Upload(string localFile, string remoteFile, DUpload up, DTransferring trans, DDiscarded discarded, uint flags, DOnExceptionFromServer se) { if (localFile == null || localFile.Length == 0) { throw new ArgumentException("localFile cannot be empty"); } if (remoteFile == null || remoteFile.Length == 0) { throw new ArgumentException("remoteFile cannot be empty"); } CContext context = new CContext(true, flags); context.Upload = up; context.Transferring = trans; context.Discarded = discarded; context.FilePath = remoteFile; context.LocalFile = localFile; context.Se = se; lock (m_csFile) { m_vContext.AddToBack(context); uint filesOpened = GetFilesOpened(); if (m_MaxDownloading > filesOpened) { ClientCoreLoader.PostProcessing(Socket.Handle, 0, 0); if (filesOpened == 0) { Socket.DoEcho(); //make sure WaitAll works correctly } } } return(true); }
public void RemoveAt() { Deque <string> d = new Deque <string>(); d.Insert(0, "a"); d.Insert(1, "b"); d.Insert(0, "c"); d.Insert(2, "d"); d.Insert(1, "e"); d.Insert(4, "f"); d.Insert(3, "g"); d.Insert(2, "h"); d.Insert(0, "i"); d.Insert(2, "j"); d.Insert(4, "k"); d.RemoveAt(4); d.RemoveAt(3); d.RemoveAt(2); d.RemoveAt(5); d.RemoveAt(2); InterfaceTests.TestReadWriteListGeneric(d, new string[] { "i", "c", "a", "g", "f", "b" }); d.Clear(); d.AddToBack("f"); d.AddToBack("g"); d.AddToFront("e"); d.AddToFront("d"); d.AddToFront("c"); d.AddToFront("b"); d.AddToFront("a"); d.RemoveAt(3); d.RemoveAt(4); d.RemoveAt(4); InterfaceTests.TestReadWriteListGeneric(d, new string[] { "a", "b", "c", "e" }); }
static void Main(string[] args) { Deque <byte> deque = new Deque <byte>(); string command; int n = int.Parse(Console.ReadLine()); for (int i = 0; i <= n - 1; i++) { command = Console.ReadLine(); string[] commandParameters = command.Split(); switch (commandParameters[0]) { case "add": { byte iD = byte.Parse(commandParameters[1]); deque.AddToBack(iD); Console.WriteLine("Added {0}", iD); break; } case "slide": { int k = int.Parse(commandParameters[1]); byte tmp; for (int j = 0; j <= k - 1; j++) { tmp = deque.RemoveFromFront(); deque.AddToBack(tmp); } Console.WriteLine("Slided {0}", k); break; } case "print": { int size = deque.Count; byte tmp; StringBuilder pehso = new StringBuilder(); for (int j = size - 1; j >= 1; j--) { tmp = deque.RemoveFromBack(); deque.AddToFront(tmp); pehso.Append(string.Format("{0} ", tmp)); } if (size >= 1) { tmp = deque.RemoveFromBack(); deque.AddToFront(tmp); pehso.Append(string.Format("{0}", tmp)); } Console.WriteLine(pehso.ToString()); break; } } } }
public void CloneFrom(TimeStateContainer other) { EarliestTimeStamp = other.EarliestTimeStamp; LatestTimeStamp = other.LatestTimeStamp; StateQue.Clear(); foreach (var state in other.StateQue) { StateQue.AddToBack((byte[])state.Clone()); } }
/// <summary> /// Add a buffer to the end of the queue and associate a promise with it that should be completed when /// all the buffer's bytes have been consumed from the queue and written. /// </summary> /// <param name="buf">to add to the tail of the queue</param> /// <param name="promise">to complete when all the bytes have been consumed and written, can be void.</param> public void Add(IByteBuffer buf, IPromise promise) { // buffers are added before promises so that we naturally 'consume' the entire buffer during removal // before we complete it's promise. _bufAndListenerPairs.AddToBack(buf); if (promise is object && !promise.IsVoid) { _bufAndListenerPairs.AddToBack(promise); } IncrementReadableBytes(buf.ReadableBytes); }
static void Main() { var strs = Console.ReadLine().Split(' '); var n = int.Parse(strs[0]); var k = int.Parse(strs[1]); if (n < k) { Console.WriteLine(0); return; } strs = Console.ReadLine().Split(' '); var f = long.Parse(strs[0]); var a = int.Parse(strs[1]); var b = int.Parse(strs[2]); var m = int.Parse(strs[3]); var deque = new Deque <Tuple <long, int> >(); deque.AddToBack(new Tuple <long, int>(f, 0)); for (int i = 1; i < k; ++i) { f = (f * a + b) % m; while (deque.Count > 0 && deque[deque.Count - 1].Item1 >= f) { deque.RemoveFromBack(); } deque.AddToBack(new Tuple <long, int>(f, i)); } for (int i = k; i < n; ++i) { f = (f * a + b) % m; while (deque[0].Item2 < i - k) { deque.RemoveFromFront(); } var cell = f + deque[0].Item1; while (deque.Count > 0 && deque[deque.Count - 1].Item1 >= cell) { deque.RemoveFromBack(); } deque.AddToBack(new Tuple <long, int>(cell, i)); } while (deque[0].Item2 < n - k) { deque.RemoveFromFront(); } Console.WriteLine(deque[0].Item1); }
public new void Enqueue(AtfAction action) { if (Count > 0 && last.serializedContent.Equals(action.serializedContent)) { var previousCount = rleCounts.RemoveFromBack(); rleCounts.AddToBack(previousCount + 1); } else { rleCounts.AddToBack(0); last = action; base.Enqueue(action); } }
public void IListInterface() { Deque <string> d = new Deque <string>(); d.AddToFront("foo"); d.AddToBack("world"); d.AddToFront("hello"); d.AddToBack("elvis"); d.AddToFront("elvis"); d.AddToBack(null); d.AddToFront("cool"); InterfaceTests.TestReadWriteList((IList)d, new string[] { "cool", "elvis", "hello", "foo", "world", "elvis", null }); }
static void Main(string[] args) { var deque = new Deque <int>(); int lines = int.Parse(Console.ReadLine()); for (int i = 0; i < lines; i++) { var parts = Console.ReadLine().Split(' '); string command = parts[0]; switch (command) { case "add": int id = int.Parse(parts[1]); deque.AddToBack(id); Console.WriteLine("Added " + id); break; case "slide": int sliders = int.Parse(parts[1]); int k = sliders; while (sliders > 0 && deque.Count > 0) { var front = deque.GetAtFront(); deque.RemoveFromFront(); deque.AddToBack(front); sliders--; } Console.WriteLine("Slided " + k); break; case "print": var listToPrint = new List <int>(deque); StringBuilder sb = new StringBuilder(); for (int j = listToPrint.Count - 1; j >= 0; j--) { sb.Append(listToPrint[j] + " "); } Console.WriteLine(sb.ToString().TrimEnd()); break; default: break; } } }
public void Constructor_CapacityOf0_PermitsAdd() { var deque = new Deque <int>(0); deque.AddToBack(13); Assert.AreEqual(new[] { 13 }, deque); }
public static double[] GetMin(this double[] input, int window) { //this is the initial method extesion for ascending mimima //taken from http://stackoverflow.com/a/14823809/2381899 var queue = new Deque <MinimaValue>(); var result = new double[input.Length]; for (int i = 0; i < input.Length; i++) { var val = input[i]; // Note: in Nito.Deque, queue[0] is the front while (queue.Count > 0 && i >= queue[0].RemoveIndex) { queue.RemoveFromFront(); } while (queue.Count > 0 && queue[queue.Count - 1].Value >= val) { queue.RemoveFromBack(); } queue.AddToBack(new MinimaValue { RemoveIndex = i + window, Value = val }); result[i] = queue[0].Value; } return(result); }
static void SceneOpenedCallback( Scene _scene, UnityEditor.SceneManagement.OpenSceneMode _mode) { if (isUndo) { index--; isUndo = false; } else if (isRedo) { index++; isRedo = false; ROM.write <Deque <string> >(ROM_SCENE, sceneDeck); } else { index++; int diff = sceneDeck.Count - index; if (diff > 0) { sceneDeck.RemoveRange(index, sceneDeck.Count - index); } sceneDeck.AddToBack(_scene.path); if (sceneDeck.Count > SCENE_COUNT) { sceneDeck.RemoveFromFront(); index--; } } }
public void ShouldCompleteOperation(IBackgroundOperation backgroundOperation) { _scheduledOperations.AddToBack(backgroundOperation); ExecuteCount = 0; while (ExecuteCount < MaxExecuteCount) { ++ExecuteCount; if (_scheduledOperations[0].Execute(MockSubOperationScheduler.Object).IsComplete) { var disposableOperation = _scheduledOperations.RemoveFromFront() as IDisposable; if (disposableOperation != null) { disposableOperation.Dispose(); } if (_scheduledOperations.Count == 0) { return; } } } throw new ShouldAssertException($"Operation of type {backgroundOperation.GetType().Name} should have completed within {MaxExecuteCount} executions, but didn't"); }
public void AddEntry(string text, int font, Hue hue, bool isUnicode) { bool maxScroll = _scrollBar.Value == _scrollBar.MaxValue; while (_entries.Count > 99) { _entries.RemoveFromFront().Destroy(); } _entries.AddToBack(new RenderedText { MaxWidth = Width - 18, IsUnicode = isUnicode, Align = TEXT_ALIGN_TYPE.TS_LEFT, FontStyle = FontStyle.Indention | FontStyle.BlackBorder, Hue = hue, Font = (byte)font, Text = text }); _scrollBar.MaxValue += _entries[_entries.Count - 1].Height; if (maxScroll) { _scrollBar.Value = _scrollBar.MaxValue; } }
public void Constructor_CapacityOf0_PermitsAdd() { var deque = new Deque <int>(0); deque.AddToBack(13); deque.ShouldBe(new[] { 13 }); }
/// <inheritdoc/> public IEnumerable <string> GetCommitHistory(IEnumerable <string> oids) { Deque <string> oidQueue = new Deque <string>(oids); HashSet <string> visited = new HashSet <string>(StringComparer.OrdinalIgnoreCase); while (oidQueue.Count > 0) { string oid = oidQueue.RemoveFromFront(); if (string.IsNullOrWhiteSpace(oid) || visited.Contains(oid)) { continue; } visited.Add(oid); yield return(oid); var commit = this.GetCommit(oid); oidQueue.AddToFront(commit.Parents.FirstOrDefault()); if (commit.Parents.Count > 1) { commit.Parents.TakeLast(commit.Parents.Count - 1) .ToList() .ForEach(id => oidQueue.AddToBack(id)); } } }
void EnqueueFrameWithoutMerge(IHttp2RemoteFlowControlled frame) { _pendingWriteQueue.AddToBack(frame); // This must be called after adding to the queue in order so that hasFrame() is // updated before updating the stream state. IncrementPendingBytes(frame.Size, true); }
public void setDeque(string msg) { if ("".Equals(msg) != true) { deque.AddToBack(msg); } }
/* * def reachablekeys(grid, start, havekeys): * bfs = collections.deque([start]) * distance = {start: 0} * keys = {} * while bfs: * h = bfs.popleft() * for pt in [ * (h[0] + 1, h[1]), * (h[0] - 1, h[1]), * (h[0], h[1] + 1), * (h[0], h[1] - 1), * ]: * if not (0 <= pt[0] < len(grid) and 0 <= pt[1] < len(grid[0])): * continue * ch = grid[pt[0]][pt[1]] * if ch == '#': * continue * if pt in distance: * continue * distance[pt] = distance[h] + 1 * if 'A' <= ch <= 'Z' and ch.lower() not in havekeys: * continue * if 'a' <= ch <= 'z' and ch not in havekeys: * keys[ch] = distance[pt], pt * else: * bfs.append(pt) * return keys */ public static Dictionary <char, (int, Point)> ReachableKeys(string[] grid, Point start, string haveKeys) { var bfs = new Deque <Point>(new[] { start }); var distance = new Dictionary <Point, int> { { start, 0 } }; var keys = new Dictionary <char, (int, Point)>(); while (bfs.Count > 0) { var h = bfs.RemoveFromFront(); List <Point> points = new List <Point> { new Point { X = h.X + 1, Y = h.Y }, new Point { X = h.X - 1, Y = h.Y }, new Point { X = h.X, Y = h.Y - 1 }, new Point { X = h.X, Y = h.Y + 1 } }; foreach (var point in points) { if (!(0 <= point.X && point.X < Height && 0 <= point.Y && point.Y < Width)) { continue; } var ch = grid[point.X][point.Y]; if (ch == '#') { continue; } if (distance.ContainsKey(point)) { continue; } distance.Add(point, distance[h] + 1); if ('A' <= ch && ch <= 'Z' && haveKeys.All(c => c != ch + 32)) { continue; } if ('a' <= ch && ch <= 'z' && haveKeys.All(c => c != ch)) { keys.Add(ch, (distance[point], point)); } else { bfs.AddToBack(point); } } } return(keys); }
public int seats() { var a = ".x.x.x.xx."; var d = new Deque <P>(); var j = 0; var n = a.Length; while (j < n) { while (j < n && a[j] == '.') { j++; } if (j == n) { break; } var i = j; while (j < n && a[j] == 'x') { j++; } d.AddToBack(new P { start = i, end = j - 1 }); } long cnt = 0; // merge all groups together while (d.Count > 1) { var left = d.GetAtFront(); var right = d.GetAtBack(); // decide what region need to merge var leftLen = left.end - left.start + 1; var rightLen = right.end - right.start + 1; if (leftLen < rightLen) // merge left region { left = d.RemoveFromFront(); cnt = cnt + leftLen * (d.GetAtFront().start - left.end - 1); cnt = cnt % 10000003; d.GetAtFront().start -= leftLen; } else // merge right region { right = d.RemoveFromBack(); cnt = cnt + rightLen * (right.start - d.GetAtBack().end - 1); cnt = cnt % 10000003; d.GetAtBack().end += rightLen; } } return((int)cnt); }
public static int PeekLast(this Deque <int> collection) { var value = collection.RemoveFromBack(); collection.AddToBack(value); return(value); }
public void Ldeque(int startIndex, int toIndex) { watch.start(); path.Add(toIndex); double INF = double.PositiveInfinity; Deque <int> deque = new Deque <int>(); foreach (var pair in graph) { shortestDistances.Add(INF); predecessorVertex.Add(-1); } shortestDistances[startIndex] = 0; deque.AddToBack(startIndex); while (deque.Count != 0) { int u = deque.RemoveFromFront(); foreach (var pair in graph[u]) { int v = pair.toIndex; if (shortestDistances[v] > shortestDistances[u] + pair.cost) { if (!deque.Contains(v)) { if (shortestDistances[v] == double.PositiveInfinity) { deque.AddToBack(v); } else { deque.AddToFront(v); } } shortestDistances[v] = shortestDistances[u] + pair.cost; predecessorVertex[v] = u; } } } getPath(startIndex, toIndex); totalJarak = shortestDistances[toIndex]; elapsedTimeMs = watch.stop(); }
static void DequeExample() { Console.WriteLine("Wintellect.PowerCollections.Deque<T> example:"); Console.WriteLine("Elements will retain their insertion order. Elements can be added at both ends of the deque."); Deque <string> list = new Deque <string>(); list.AddToBack("programming"); list.AddToBack("C#"); list.AddToFront("Visual Studio"); list.AddToBack("dotnet"); list.AddToFront("C#"); // Duplicates are allowed (at different index) list.AddToBack("C#"); // Duplicates are allowed (at different index) Console.WriteLine("Elements: {0}", list); Console.WriteLine("Removed element from front: {0}", list.RemoveFromFront()); Console.WriteLine("Removed element from back: {0}", list.RemoveFromBack()); Console.WriteLine("Elements: {0}", list); }
public void Test() { var a = new int[] { '.', '.', 'x', 'x', '.', '.', '.', 'x', 'x', '.', '.', 'x', 'x', '.', '.', 'x', 'x', 'x', '.', '.', '.' }; // add all groups to deque var d = new Deque <P>(); var j = 0; var n = a.Length; while (j < n) { while (j < n && a[j] == '.') { j++; } if (j == n) { break; } var i = j; while (j < n && a[j] == 'x') { j++; } d.AddToBack(new P { start = i, end = j - 1 }); } var cnt = 0; // merge all groups together if (d.Count > 1) { var left = d.GetAtFront(); var right = d.GetAtBack(); // decide what region need to merge var leftLen = left.end - left.start + 1; var rightLen = right.end - right.start + 1; if (leftLen < rightLen) // merge left region { left = d.RemoveFromFront(); cnt = cnt + leftLen * (d.GetAtFront().start - left.end - 1); d.GetAtFront().start -= leftLen; } else // merge right region { right = d.RemoveFromBack(); cnt = cnt + rightLen * (right.start - d.GetAtBack().end - 1); d.GetAtBack().end += rightLen; } } Assert.AreEqual(6, cnt); }
public void Indexer() { Deque <string> d = new Deque <string>(); d.AddToFront("c"); d.AddToFront("b"); d.AddToFront("a"); d.AddToBack("d"); d.AddToBack("e"); d.AddToBack("f"); Assert.AreEqual("b", d[1]); Assert.AreEqual("e", d[4]); d[1] = "q"; d[4] = "r"; Assert.AreEqual("q", d[1]); Assert.AreEqual("r", d[4]); InterfaceTests.TestReadWriteListGeneric(d, new string[] { "a", "q", "c", "d", "r", "f" }); d.Clear(); d.AddToBack("a"); d.AddToBack("b"); d.AddToBack("c"); d.AddToBack("d"); Assert.AreEqual("b", d[1]); Assert.AreEqual("d", d[3]); d[1] = "q"; d[3] = "r"; Assert.AreEqual("q", d[1]); Assert.AreEqual("r", d[3]); InterfaceTests.TestReadWriteListGeneric(d, new string[] { "a", "q", "c", "r" }); }
public void SerializeStrings() { Deque <string> d = new Deque <string>(); d.AddToFront("foo"); d.AddToBack("world"); d.AddToFront("hello"); d.AddToBack("elvis"); d.AddToFront("elvis"); d.AddToBack(null); d.AddToFront("cool"); d.AddManyToFront(new string[] { "1", "2", "3", "4", "5", "6" }); d.AddManyToBack(new string[] { "7", "8", "9", "10", "11", "12" }); Deque <string> result = (Deque <string>)InterfaceTests.SerializeRoundTrip(d); InterfaceTests.TestReadWriteListGeneric((IList <string>)result, new string[] { "1", "2", "3", "4", "5", "6", "cool", "elvis", "hello", "foo", "world", "elvis", null, "7", "8", "9", "10", "11", "12" }); }
public void ToArray_CopiesToNewArray() { var deque = new Deque <int>(new[] { 0, 1 }); deque.AddToBack(13); var result = deque.ToArray(); Assert.AreEqual(new[] { 0, 1, 13 }, result); }
public void Add_IsAddToBack() { var deque1 = new Deque <int>(new[] { 1, 2 }); var deque2 = new Deque <int>(new[] { 1, 2 }); ((ICollection <int>)deque1).Add(3); deque2.AddToBack(3); Assert.AreEqual(deque1, deque2); }
public void Insert_AtCount_IsSameAsAddToBack() { var deque1 = new Deque <int>(new[] { 1, 2 }); var deque2 = new Deque <int>(new[] { 1, 2 }); deque1.Insert(deque1.Count, 0); deque2.AddToBack(0); Assert.AreEqual(deque1, deque2); }
static void Main() { Console.Write("Bag of Integers: "); var bagOfInts = new Bag<int>(); bagOfInts.Add(3); bagOfInts.Add(5); bagOfInts.Add(5); bagOfInts.Add(5); bagOfInts.Add(10); bagOfInts.Add(20); bagOfInts.Add(20); bagOfInts.Remove(5); bagOfInts.RemoveAllCopies(20); bagOfInts.UnionWith(new Bag<int>() { 3, 3, 4, 4, 5, 5 }); Console.WriteLine(bagOfInts); Console.Write("OrderedBag of Integers: "); var orderedBagOfInts = new OrderedBag<int>(); orderedBagOfInts.Add(3); orderedBagOfInts.Add(5); orderedBagOfInts.Add(5); orderedBagOfInts.Add(5); orderedBagOfInts.Add(10); orderedBagOfInts.Add(20); orderedBagOfInts.Add(20); orderedBagOfInts.Remove(5); orderedBagOfInts.RemoveAllCopies(20); orderedBagOfInts.UnionWith(new OrderedBag<int>() { 3, 3, 4, 4, 5, 5 }); Console.WriteLine(orderedBagOfInts); Console.WriteLine("Sub-range [5...10]: " + orderedBagOfInts.Range(5, true, 10, true)); Console.Write("Set of Integers: "); var setOfInts = new Set<int>(); setOfInts.Add(3); setOfInts.Add(5); setOfInts.Add(5); setOfInts.Add(5); setOfInts.Add(10); setOfInts.Add(20); setOfInts.Add(20); setOfInts.Remove(5); setOfInts.UnionWith(new Set<int>() { 3, 4, 5 }); Console.WriteLine(setOfInts); Console.Write("OrderedSet of Integers: "); var orderedSetOfInts = new OrderedSet<int>(); orderedSetOfInts.Add(3); orderedSetOfInts.Add(5); orderedSetOfInts.Add(5); orderedSetOfInts.Add(5); orderedSetOfInts.Add(10); orderedSetOfInts.Add(20); orderedSetOfInts.Add(20); orderedSetOfInts.Remove(5); orderedSetOfInts.UnionWith(new OrderedSet<int>() { 3, 4, 5 }); Console.WriteLine(orderedSetOfInts); Console.WriteLine("Sub-range [5...20): " + orderedSetOfInts.Range(5, true, 20, false)); Console.Write("MultiDictionary<string,int>: "); var studentGrades = new MultiDictionary<string, int>(true); studentGrades.Add("Peter", 3); studentGrades.Add("Peter", 4); studentGrades.Add("Peter", 4); studentGrades.Add("Stanka", 6); studentGrades.Add("Stanka", 5); studentGrades.Add("Stanka", 6); studentGrades.Add("Tanya", 6); studentGrades.Add("Tanya", 4); Console.WriteLine(studentGrades); Console.WriteLine("OrderedMultiDictionary<string,int>:"); var distancesFromSofia = new OrderedMultiDictionary<int, string>(true); distancesFromSofia.Add(149, "Plovdiv"); distancesFromSofia.Add(505, "Varna"); distancesFromSofia.Add(394, "Bourgas"); distancesFromSofia.Add(310, "Rousse"); distancesFromSofia.Add(163, "Pleven"); distancesFromSofia.Add(163, "Troyan"); foreach (var distanceTowns in distancesFromSofia) { Console.WriteLine("\t" + distanceTowns); } Console.Write("Deque<string>: "); var people = new Deque<string>(); people.AddToBack("Kiro"); people.AddToBack("Maria"); people.AddToFront("Steve"); people.AddManyToBack(new string[] { "Ivan", "Veronika" }); Console.WriteLine(people); Console.Write("BigList<int>: "); var ints = new BigList<int>(); // var ints = new List<int>(); for (int i = 0; i < 1000000; i++) { ints.Add(i); } for (int i = 0; i < 50000; i++) { ints.Insert(i, i); } Console.WriteLine(ints.Count); }
/// <summary> /// Deque<T> /// Double-ended queue (deque) /// </summary> private static void TestDeque() { Deque<Student> deque = new Deque<Student>(); var student1 = new Student("First DUPLICATE", 21); var student2 = new Student("Second", 21); var student3 = new Student("Third", 22); var student4 = new Student("Forth", 23); var student5 = new Student("Fifth", 24); deque.AddToBack(student1); deque.AddToFront(student2); deque.AddToBack(student3); deque.AddToFront(student4); deque.AddToBack(student5); deque.AddToFront(student1); while (deque.Count != 0) { var student = deque.RemoveFromFront(); Console.WriteLine(student); } }