protected override void Parse(ref BitStreamReader bsr) { StringTablesManager manager = DemoRef.StringTablesManager; if (!manager.TableReadable.GetValueOrDefault(_tableName)) { DemoRef.LogError($"{_tableName} table is marked as non-readable, can't update :/"); _exceptionWhileParsing = true; bsr.SkipToEnd(); return; } if (manager.CreationLookup.Single(table => table.TableName == _tableName).Flags == StringTableFlags.Fake) { DemoRef.LogError($"{_tableName} table was created manually - not parsed in SvcServerInfo"); _exceptionWhileParsing = true; bsr.SkipToEnd(); return; } try { // se2007/engine/networkstringtable.cpp line 595 MutableStringTable tableToUpdate = manager.Tables[_tableName]; int?decompressedIndex = null; if (tableToUpdate.Flags.HasValue && (tableToUpdate.Flags & StringTableFlags.DataCompressed) != 0 && _canCompress) { // decompress the data - engine/baseclientstate.cpp (hl2_src) line 1364 int uncompressedSize = bsr.ReadSInt(); int compressedSize = bsr.ReadSInt(); byte[] data = Compression.Decompress(ref bsr, compressedSize - 8); // -8 to ignore header decompressedIndex = DemoRef.DecompressedLookup.Count; DemoRef.DecompressedLookup.Add(data); // so that we can access the reader for the entries later if (data.Length != uncompressedSize) { throw new Exception("could not decompress data in string table update"); } bsr = new BitStreamReader(data); } int entryIndex = -1; var history = new C5.CircularQueue <string>(32); for (int i = 0; i < _numUpdatedEntries; i++) { entryIndex++; if (!bsr.ReadBool()) { entryIndex = (int)bsr.ReadUInt(BitUtils.HighestBitIndex(tableToUpdate.MaxEntries)); } string?entryName = null; if (bsr.ReadBool()) { if (bsr.ReadBool()) // the first part of the string may be the same as for other entries { int index = (int)bsr.ReadUInt(5); int subStrLen = (int)bsr.ReadUInt(SubStringBits); entryName = history[index][..subStrLen];
public void SW200602() { C5.CircularQueue <int> list = new C5.CircularQueue <int>(8); for (int count = 0; count <= 7; count++) { list.Enqueue(count); } int end = list.Count; for (int index = 0; index < end; index++) { Assert.AreEqual(index, list[0]); list.Dequeue(); } }
public static void Add <T>([DisallowNull] this C5.CircularQueue <T> queue, T item) => queue.Enqueue(item);
public void SW200602() { C5.CircularQueue<int> list = new C5.CircularQueue<int>(8); for(int count = 0; count <= 7; count++) { list.Enqueue(count); } int end = list.Count; for(int index = 0; index < end; index++) { Assert.AreEqual(index, list[0]); list.Dequeue(); } }
private bool TopologicalSearch(HKMSTDNode v, HKMSTDNode w) { var F = new C5.CircularQueue<int>(); var B = new C5.CircularQueue<int>(); F.Push(w.Index); B.Push(v.Index); var i = w.Position; var j = v.Position; v.Visited = true; w.Visited = true; while (true) { i++; while (i < j && !F.Any(u => adjMatrix[u, vertex[position[i]].Index])) i++; if (i == j) break; F.Push(vertex[position[i]].Index); vertex[position[i]].Visited = true; j--; while(i < j && !B.Any(z => adjMatrix[vertex[position[j]].Index, z])) j--; if (i == j) break; B.Push(vertex[position[j]].Index); vertex[position[j]].Visited = true; } //Once the search finishes, test for a cycle by checking whether there is an arc(u, z) //with u in F and z in B bool noCycle = !(from u in F from z in B where adjMatrix[u, z] select u).Any(); // Any stops when first occurance is found if (!noCycle) { foreach (var x in F) { vertex[x].Visited = false; } foreach (var x in B) { vertex[x].Visited = false; } return false; } else //cycle { var fix = new List<HKMSTDNode>();// putting things back the way they were // Reorder while (!F.IsEmpty) { if (vertex[position[i]].Visited == false && F.Any(u => adjMatrix[u, vertex[position[i]].Index])) { F.Push(vertex[position[i]].Index); vertex[position[i]].Visited = true; } if (vertex[position[i]].Visited) { var x = F.Dequeue(); position[i] = vertex[x].Index; vertex[x].Position = i; fix.Add(vertex[x]); } i++; } while (!B.IsEmpty) { j--; if (vertex[position[j]].Visited == false && B.Any(z => adjMatrix[vertex[position[j]].Index, z])) { B.Push(vertex[position[j]].Index); vertex[position[j]].Visited = true; } if (vertex[position[j]].Visited) { var y = B.Dequeue(); position[j] = vertex[y].Index; vertex[y].Position = j; fix.Add(vertex[y]); } } foreach (var vert in fix) { vert.Visited = false; } } return noCycle; }
private bool TopologicalSearch(HKMSTDNode v, HKMSTDNode w) { var F = new C5.CircularQueue <int>(); var B = new C5.CircularQueue <int>(); F.Push(w.Index); B.Push(v.Index); var i = w.Position; var j = v.Position; v.Visited = true; w.Visited = true; while (true) { i++; while (i < j && !F.Any(u => adjMatrix[u, vertex[position[i]].Index])) { i++; } if (i == j) { break; } F.Push(vertex[position[i]].Index); vertex[position[i]].Visited = true; j--; while (i < j && !B.Any(z => adjMatrix[vertex[position[j]].Index, z])) { j--; } if (i == j) { break; } B.Push(vertex[position[j]].Index); vertex[position[j]].Visited = true; } //Once the search finishes, test for a cycle by checking whether there is an arc(u, z) //with u in F and z in B bool noCycle = !(from u in F from z in B where adjMatrix[u, z] select u).Any(); // Any stops when first occurance is found if (!noCycle) { foreach (var x in F) { vertex[x].Visited = false; } foreach (var x in B) { vertex[x].Visited = false; } return(false); } else //cycle { var fix = new List <HKMSTDNode>();// putting things back the way they were // Reorder while (!F.IsEmpty) { if (vertex[position[i]].Visited == false && F.Any(u => adjMatrix[u, vertex[position[i]].Index])) { F.Push(vertex[position[i]].Index); vertex[position[i]].Visited = true; } if (vertex[position[i]].Visited) { var x = F.Dequeue(); position[i] = vertex[x].Index; vertex[x].Position = i; fix.Add(vertex[x]); } i++; } while (!B.IsEmpty) { j--; if (vertex[position[j]].Visited == false && B.Any(z => adjMatrix[vertex[position[j]].Index, z])) { B.Push(vertex[position[j]].Index); vertex[position[j]].Visited = true; } if (vertex[position[j]].Visited) { var y = B.Dequeue(); position[j] = vertex[y].Index; vertex[y].Position = j; fix.Add(vertex[y]); } } foreach (var vert in fix) { vert.Visited = false; } } return(noCycle); }
/// <summary> /// Starts a new weighted average with a given maximum sample size /// </summary> /// <param name="sampleSize"></param> public MovingIntegerAverage(int sampleSize) { _values = new C5.CircularQueue <long>(sampleSize); _sampleSize = sampleSize; }
/// <summary> /// Starts a new weighted average with a given maximum sample size /// </summary> /// <param name="sampleSize"></param> public MovingIntegerAverage(int sampleSize) { _values = new C5.CircularQueue<long>(sampleSize); _sampleSize = sampleSize; }
public void C5_CircularQueue() => _ = new C5.CircularQueue <Int32>(32);