public AgbMemoryMap() { RangedRegions = new Dictionary <byte, RangedMemoryRegion>(); AuxiliaryMap = new Dictionary <uint, IMemoryRegion>(); MmioRegions = new List <IMmioRegion>(); DirtyRegions = new UniqueQueue <IMmioRegion>(); }
public static Dfa ToDfa(this Nfa nfa) { var once = new UniqueQueue <NfaClosure>(); var start = new NfaClosure(nfa.Start, nfa.End); once.Enqueue(start); while (once.Count > 0) { var closure = once.Dequeue(); var transitions = closure.UnambiguateTransitions(); foreach (var transition in transitions) { var terminal = transition.Key; var targets = transition.Value; var targetClosure = new NfaClosure(targets, nfa.End); once.Enqueue(targetClosure, out targetClosure); var target = targetClosure.State; closure.State.Add(Atom.From(terminal), target); } } //return new Dfa(start.State); return(new Dfa(start.State)); }
/// <summary> /// Setup of readonly fields and non-optional steps. /// </summary> private World(WorldInformation information, string worldDirectory, string chunkDirectory, IWorldGenerator generator) { positionsToActivate = new HashSet<(int x, int z)>(); positionsActivating = new HashSet<(int, int)>(); chunksToGenerate = new UniqueQueue<Chunk>(); chunkGenerateTasks = new List<Task>(MaxGenerationTasks); chunksGenerating = new Dictionary<int, Chunk>(MaxGenerationTasks); positionsToLoad = new UniqueQueue<(int x, int z)>(); chunkLoadingTasks = new List<Task<Chunk?>>(MaxLoadingTasks); positionsLoading = new Dictionary<int, (int x, int z)>(MaxLoadingTasks); activeChunks = new Dictionary<ValueTuple<int, int>, Chunk>(); positionsToReleaseOnActivation = new HashSet<(int x, int z)>(); chunksToSave = new UniqueQueue<Chunk>(); chunkSavingTasks = new List<Task>(MaxSavingTasks); chunksSaving = new Dictionary<int, Chunk>(MaxSavingTasks); positionsSaving = new HashSet<(int x, int z)>(MaxSavingTasks); positionsActivatingThroughSaving = new HashSet<(int x, int z)>(); Information = information; WorldDirectory = worldDirectory; ChunkDirectory = chunkDirectory; this.generator = generator; UpdateCounter = new UpdateCounter(); Setup(); }
public void Update(GameTime gameTime) { foreach (AbstractCreature creature in creatures) { creature.Update(gameTime); } // Remove dead creatures // iterate backwards to remove them from the array as we loop for (int i = creatures.Count - 1; i >= 0; i--) { if (!creatures[i].alive) { creatures.RemoveAt(i); } } if (blockUpdateQueue.Count == 0) { blockUpdateQueue = new UniqueQueue <byte[]>(nextBlockUpdateQueue); nextBlockUpdateQueue.Clear(); } for (int i = 0; i < 64000 && blockUpdateQueue.Count > 0; i++) { byte[] blockPosition = blockUpdateQueue.Dequeue(); blocks[blockPosition[0], blockPosition[1], blockPosition[2]].Update(gameTime); } }
public void UniqueQueueEnqueue() { UniqueQueue <int> queue = new UniqueQueue <int>(); Assert.That(queue.Enqueue(10), Is.True); Assert.That(queue.Enqueue(10), Is.False); }
public void UniqueQueueDequeue() { UniqueQueue <int> queue = new UniqueQueue <int>(); queue.Enqueue(10); Assert.That(queue.Dequeue(), Is.EqualTo(10)); Assert.Throws <InvalidOperationException>(() => queue.Dequeue()); }
public void Enqueue_QueueString_Queued() { UniqueQueue <string> queue = new UniqueQueue <string>(); queue.Enqueue("abc"); Assert.Equal(1, queue.Count); }
public Tile(int tileX, int tileY) { this.tileX = tileX; this.tileY = tileY; blockUpdateQueue = new UniqueQueue <byte[]>(); nextBlockUpdateQueue = new UniqueQueue <byte[]>(); }
public void Enqueue_QueueMultipleOfSameString_SecondQueueFailed() { UniqueQueue <string> queue = new UniqueQueue <string>(); queue.Enqueue("abc"); queue.Enqueue("abc"); Assert.Equal(1, queue.Count); }
public void Enqueue_Null_InvalidOperationException() { UniqueQueue <string> queue = new UniqueQueue <string>(); Assert.Throws <InvalidOperationException>(() => { queue.Enqueue(null); }); }
public void Dequeue_QueuedString_Dequeued() { UniqueQueue <string> queue = new UniqueQueue <string>(); queue.Enqueue("abc"); Assert.Equal("abc", queue.Dequeue()); Assert.Equal(0, queue.Count); }
public void Dequeue_WhileEmpty_InvalidOperationException() { UniqueQueue <string> queue = new UniqueQueue <string>(); Assert.Throws <InvalidOperationException>(() => { queue.Dequeue(); }); }
private void Awake() { tileChangeManager = GetComponentInParent <TileChangeManager>(); metaDataLayer = GetComponent <MetaDataLayer>(); matrix = GetComponent <Matrix>(); hotspots = new Dictionary <Vector3Int, MetaDataNode>(); winds = new UniqueQueue <MetaDataNode>(); }
public void TryDequeue_WithNoneQueued_ReturnedFalse() { UniqueQueue <string> queue = new UniqueQueue <string>(); string str; bool result = queue.TryDequeue(out str); Assert.Null(str); Assert.False(result); }
public static void TestSimple() { UniqueQueue <int> queue = new UniqueQueue <int>(); Assert.IsTrue(queue.Enqueue(0)); Assert.IsFalse(queue.Enqueue(0)); Assert.IsTrue(queue.Contains(0)); Assert.AreEqual(queue.Peek(), 0); Assert.AreEqual(queue.Dequeue(), 0); }
public void Enqueue_QueueAnotherOfSameStringAfterDequeue_BothQueuesSuccess() { UniqueQueue <string> queue = new UniqueQueue <string>(); queue.Enqueue("abc"); queue.Dequeue(); queue.Enqueue("abc"); Assert.Equal(1, queue.Count); }
public void Enqueue_QueueMultipleNonSimilarStrings_AllQueuesSuccess() { UniqueQueue <string> queue = new UniqueQueue <string>(); queue.Enqueue("abc"); queue.Enqueue("def"); queue.Enqueue("ghi"); Assert.Equal(3, queue.Count); }
/// <summary> /// /// </summary> /// <param name="capacity">Preallocated elements in the pool. OnRecycle is called when the instance is preallocated</param> public Pool(int capacity = 0) { m_items = new UniqueQueue <T>(capacity); // preallocate instances for (int i = 0; i < capacity; i++) { var item = m_allocator.CreateNew(); item.OnRecycle(); m_items.Enqueue(item); } }
// Only used for testing internal void Clear() { Log.To.NoDomain.D(TAG, "clear() called, setting _jobQueue to null"); Unschedule(); var itemCount = _inbox.Count; Misc.SafeDispose(ref _inbox); _inbox = new UniqueQueue <T>(); Log.To.NoDomain.D(TAG, "Discarded {0} items", itemCount); }
private void CreateRoom(Vector3Int origin) { if (metaDataLayer.Get(origin).RoomNumber != -1) { return; } var roomPositions = new HashSet <Vector3Int>(); var freePositions = new UniqueQueue <Vector3Int>(); freePositions.Enqueue(origin); var isSpace = false; // breadth-first search of the connected tiles that are not occupied while (!freePositions.IsEmpty) { if (freePositions.TryDequeue(out Vector3Int position)) { roomPositions.Add(position); Vector3Int[] neighbors = MetaUtils.GetNeighbors(position, null); for (var i = 0; i < neighbors.Length; i++) { Vector3Int neighbor = neighbors[i]; if (metaTileMap.IsSpaceAt(neighbor, true)) { Vector3Int worldPosition = MatrixManager.LocalToWorldInt(neighbor, MatrixManager.Get(matrix.Id)); // If matrix manager says, the neighboring positions is space, the whole room is connected to space. // Otherwise there is another matrix, blocking off the connection to space. if (MatrixManager.IsSpaceAt(worldPosition, true, matrix.MatrixInfo)) { isSpace = true; } } else if (metaTileMap.IsAtmosPassableAt(position, neighbor, true)) { // if neighbor position is not yet a room in the meta data layer and not in the room positions list, // add it to the positions that need be checked if (!roomPositions.Contains(neighbor) && !metaDataLayer.IsRoomAt(neighbor)) { freePositions.Enqueue(neighbor); } } } } } AssignType(roomPositions, isSpace ? NodeType.Space : NodeType.Room); SetupNeighbors(roomPositions); }
private void Awake() { tileChangeManager = GetComponentInParent <TileChangeManager>(); metaDataLayer = GetComponent <MetaDataLayer>(); matrix = GetComponent <Matrix>(); hotspots = new ConcurrentDictionary <Vector3Int, MetaDataNode>(); winds = new UniqueQueue <MetaDataNode>(); hotspotsToRemove = new List <Vector3Int>(); hotspotsToAdd = new List <Hotspot>(); tilemapDamages = GetComponentsInChildren <TilemapDamage>(); }
public void TryDequeue_WithOneQueued_DequeueSuccessful() { UniqueQueue <string> queue = new UniqueQueue <string>(); queue.Enqueue("abc"); string str; bool result = queue.TryDequeue(out str); Assert.Equal("abc", str); Assert.True(result); Assert.Equal(0, queue.Count); }
private void Awake() { tileChangeManager = GetComponentInParent <TileChangeManager>(); metaDataLayer = GetComponent <MetaDataLayer>(); matrix = GetComponent <Matrix>(); hotspots = new Dictionary <Vector3Int, MetaDataNode>(); winds = new UniqueQueue <MetaDataNode>(); addFog = new UniqueQueue <MetaDataNode>(); removeFog = new UniqueQueue <MetaDataNode>(); tilemapDamages = GetComponentsInChildren <TilemapDamage>(); }
public IEnumerable <State> Closure() { var once = new UniqueQueue <State>(); once.Enqueue(this); while (once.Count > 0) { var state = once.Dequeue(); foreach (var transition in state.EpsilonTransitions) { once.Enqueue(transition.Target); } } return(once.Seen); }
private void CreateRoom(Vector3Int origin) { var roomPositions = new HashSet <Vector3Int>(); var freePositions = new UniqueQueue <Vector3Int>(); freePositions.Enqueue(origin); var isSpace = false; while (!freePositions.IsEmpty) { Vector3Int position; if (freePositions.TryDequeue(out position)) { roomPositions.Add(position); Vector3Int[] neighbors = MetaUtils.GetNeighbors(position); for (var i = 0; i < neighbors.Length; i++) { Vector3Int neighbor = neighbors[i]; if (metaTileMap.IsSpaceAt(neighbor)) { Vector3 worldPosition = transform.TransformPoint(neighbor + Vector3Int.one); worldPosition.z = 0; if (MatrixManager.IsSpaceAt(worldPosition.RoundToInt())) { isSpace = true; } } else if (metaTileMap.IsAtmosPassableAt(neighbor)) { if (!roomPositions.Contains(neighbor) && !metaDataLayer.IsRoomAt(neighbor)) { freePositions.Enqueue(neighbor); } } } } } AssignType(roomPositions, isSpace ? NodeType.Space : NodeType.Room); SetupNeighbors(roomPositions); }
static void Main(string[] args) { string seed = "http://web.archive.org/web/20100101163446/http://www.fool.com/"; int downloadCounter = 0; UniqueQueue <string> urlQueue = new UniqueQueue <string>(); WebClient client = new WebClient(); if (!Directory.Exists(DOWNLOADS_FOLDER)) { Directory.CreateDirectory(DOWNLOADS_FOLDER); } urlQueue.Enqueue(seed); while (urlQueue.Count > 0 && downloadCounter < DOWNLOAD_LIMIT) { string url = urlQueue.Dequeue(); Console.WriteLine("Downloading from {0}", url); try { string html = client.DownloadString(url); string filename = (url.Split('/').Last().Length > 0 ? url.Split('/').Last() : DateTime.Now.Ticks.ToString() + ".html"); using (StreamWriter outfile = new StreamWriter(Path.Combine(DOWNLOADS_FOLDER, filename))) { outfile.Write(html); } IEnumerable <string> links = GetLinks(html); foreach (var link in links) { urlQueue.Enqueue(link); } seen[url] = true; downloadCounter++; } catch (Exception e) { Console.WriteLine(e.Message); } } Console.WriteLine("{0} URLs downloaded, {1} URLs remaining in queue", downloadCounter, urlQueue.Count); Console.ReadLine(); }
public static List <string> PrepareAndFindPath(int n, int i_start, int j_start, int i_end, int j_end, out bool isAnswer) { var startNode = $"{i_start}-{j_start}"; var visited = new HashSet <string>(); var notVisited = new UniqueQueue <string>(); notVisited.Enqueue(startNode); var shortestPaths = new Dictionary <string, Path>() { { startNode, new Path() { cost = 0, PreviousNode = startNode, Move = "" } } }; isAnswer = FindPath(n, i_end, j_end, shortestPaths, visited, notVisited); if (!isAnswer) { return(new List <string>()); } var endNode = $"{i_end}-{j_end}"; var cost = 0; var path = new List <string>(); var currentNode = endNode; while (currentNode != startNode) { cost += shortestPaths[currentNode].cost; path.Add(shortestPaths[currentNode].Move); currentNode = shortestPaths[currentNode].PreviousNode; } path.Reverse(); return(path); }
public static FA ToDfa(FA nfa) { if (nfa.Final == null) { EnsureDfa(nfa); return(nfa); } var once = new UniqueQueue <Closure>(); var start = new Closure(nfa.Start, nfa.Final); once.Enqueue(start); while (once.Count > 0) { var closure = once.Dequeue(); var transitions = closure.UnambiguateTransitions(); foreach (var transition in transitions) { var terminal = transition.Key; var targets = transition.Value; var targetClosure = new Closure(targets, nfa.Final); once.Enqueue(targetClosure, out targetClosure); var target = targetClosure.DfaState; closure.DfaState.Add(Integers.From(terminal), target); } } var dfa = From(start.DfaState); EnsureDfa(dfa); return(dfa); }
public void ClearUpdateList() { nodes.Clear(); updateList = new UniqueQueue <MetaDataNode>(); }
public SimplePool(int capacity = 0) { m_items = new UniqueQueue <T>(capacity); }