Expanded create/temp_array functions to allow creating a new "lookup" type of associative array (from Mr.Stalin)

This commit is contained in:
NovaRain
2019-01-08 06:52:00 +08:00
parent 4f48926105
commit e320acce0b
7 changed files with 81 additions and 52 deletions
+11
View File
@@ -20,6 +20,9 @@
/*
Generic array functions
*/
// returns True if the specified key exists in the associative array
procedure map_contains_key(variable arrayMap, variable key);
// push new item at the end of array, returns array
procedure array_push(variable array, variable item);
@@ -151,6 +154,14 @@ procedure load_collection(variable name);
#define ARRAY_SET_BLOCK_SIZE (10)
procedure map_contains_key(variable arrayMap, variable key) begin
variable i;
for (i := 0; i < len_array(arrayMap); i++) begin
if (array_key(arrayMap, i) == key) then return true;
end
return false;
end
/**
* Returns first index of zero value
*/
+4
View File
@@ -102,6 +102,10 @@
#define create_array_map (create_array(-1, 0))
// create temporary map
#define temp_array_map (temp_array(-1, 0))
// create persistent lookup map (see arrays.txt for details)
#define create_lookup_map (create_array(-1, 2))
// create temporary lookup map
#define temp_lookup_map (temp_array(-1, 2))
// true if array is map, false otherwise
#define array_is_map(x) (array_key(x, -1) == 1)
// returns temp list with names of all arrays saved with save_array() in alphabetical order