- Joined
- Sep 10, 2022
- Messages
- 101
Hello everyone, I am continuing with hashtables and I have some sort of typical question.
1. For example, imagine I have a hashtable in which I store a timer for the unit - unit_timer - as the value to be stored, then the Key is a unique Unit Handle of the Owner of the unit.
Hashtable cells:
[UnitHandle][Owner of Unit] = unit_timer
[103204][1] = 15
....
[103265][9] = 137
In another trigger, I am planning to loop over the hash table and change each count_timer until It won't be zero. So the question is how I can perform it effectively, cause the count_timer value can be an arbitrary number (from 0 to infinity). The same situation is with the unique unit Handle in this hashtable and it feels like For loop from integer A to B is not the best option...
So maybe the answer is to create 2 loops in different triggers, one from the start of the hashtable, and one from the end of the hashtable. I mean two loops at the same time are working until both reach the middle..?
2. I have one more question. I know that data in the hashtable also leaks, for example, we store position 1 and then replace it with position 2. And heard that we can prevent a leak by assigning the data in the hashtable cell to a variable, then we remove* the variable with DestroyLocation(), position 1 really disappears, and the data in the hashtable will also be cleaned by the time we assign in the cell new position. I am not sure... but is that true?
1. For example, imagine I have a hashtable in which I store a timer for the unit - unit_timer - as the value to be stored, then the Key is a unique Unit Handle of the Owner of the unit.
-
Hashtable - Save conf_timer as (Key (Picked unit)) of (Player number of (Owner of conf_target)) in conf_hash_table
Hashtable cells:
[UnitHandle][Owner of Unit] = unit_timer
[103204][1] = 15
....
[103265][9] = 137
In another trigger, I am planning to loop over the hash table and change each count_timer until It won't be zero. So the question is how I can perform it effectively, cause the count_timer value can be an arbitrary number (from 0 to infinity). The same situation is with the unique unit Handle in this hashtable and it feels like For loop from integer A to B is not the best option...
So maybe the answer is to create 2 loops in different triggers, one from the start of the hashtable, and one from the end of the hashtable. I mean two loops at the same time are working until both reach the middle..?
2. I have one more question. I know that data in the hashtable also leaks, for example, we store position 1 and then replace it with position 2. And heard that we can prevent a leak by assigning the data in the hashtable cell to a variable, then we remove* the variable with DestroyLocation(), position 1 really disappears, and the data in the hashtable will also be cleaned by the time we assign in the cell new position. I am not sure... but is that true?