/// <summary> /// Sets up a linked list to iterate though valid entries of the hashtable. /// Must call only after this.CreateAllInputKeys() is called! /// </summary> private void SetupIterationList() { // Search for the first valid entry int i; for (i = 0; i < this.hashBucketSize; i++) { if (this.hashBucket[i] != null) { break; // Found it } } Debug.Assert(i < this.hashBucketSize, "InputKeyMap does not have any entries!"); // Create the head of the iteration list this.iterationListHead = new InputKeyListNode(this.hashBucket[i]); this.iterationListHead.next = null; // Now loop through the rest of the hashtable for (i = i + 1; i < this.hashBucketSize; i++) { if (this.hashBucket[i] != null) { this.AddIterationNode(this.hashBucket[i]); } } }
/// <summary> /// Add a new node to the front of the linked list /// </summary> /// <param name="newNode"></param> private void AddIterationNode(InputKey newInputKey) { Debug.Assert(newInputKey != null, "Trying to add a null key into the iteration list!"); InputKeyListNode newNode = new InputKeyListNode(newInputKey); newNode.next = this.iterationListHead; this.iterationListHead = newNode; }
// // Constructor // public InputKeyMap() { // This number is determined by looking for the maximum // Possible value in Azul.AZUL_KEYS, which appears to be 348 int azulKeyMaxValue = this.GetLargestValueInAzulKeysEnum(); this.hashBucketSize = azulKeyMaxValue + 1; this.isMapLocked = false; this.hashBucket = null; this.iterationListHead = null; }
/// <summary> /// Updates all InputKeys in the hashtable /// </summary> public void Update() { // Loop through the iteration list of valid key entries // This is much faster then looping through the whole hashtable InputKeyListNode itr = this.iterationListHead; while (itr != null) { // Update the state of individual keys itr.Update(); // Next key itr = itr.next as InputKeyListNode; } }