Better to use
Trie than arrays when working with map names. Using Trie, plugin will quickly work with the functions such as
iscustommap many times faster than with using arrays. This depended on the number of maps. If number of maps is about 850 then functions with using Trie will be executed up to 30 times faster than with using array. If number of maps is about 1-3 then work-time of functions with using Trie and array will be is equal. It follows that in any case should be used Trie.
But adding mapnames in Trie takes is about 3.7 times longer than in array.
Here example which shows work time with Trie and array (for working needed
amxmodx profiler):
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <celltrie>
#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"
#define MAX_MAPS 3000
new maps[MAX_MAPS][64];
new maps_count = 0;
new Trie:trie;
new Profile:start;
new Float:stop;
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
set_task(1.0, "test");
}
public test()
{
trie = TrieCreate();
new configs_dir[64], maps_file[64];
get_configsdir(configs_dir,64);
formatex(maps_file,64,"%s/maps.ini",configs_dir);
new buffer[64], hFile;
// ---------------------------- Adding map in array --------------------------
start = StartProfile();
hFile = fopen(maps_file,"rt")
while (fgets(hFile,buffer,64))
{
trim(buffer);
maps[++maps_count] = buffer;
}
fclose(hFile);
stop = StopProfile(start)
server_print("time of adding in array is %f secs",stop);
// ---------------------------------------------------------------------------
// ---------------------------- Adding map in Trie ---------------------------
start = StartProfile();
hFile = fopen(maps_file,"rt")
while (fgets(hFile,buffer,64))
{
trim(buffer)
strtolower(buffer)
TrieSetCell(trie,buffer,1);
++maps_count;
}
fclose(hFile);
stop = StopProfile(start)
server_print("time of adding in Trie is %f secs",stop);
// ---------------------------------------------------------------------------
new mapname[64] = "aK_rh_warehouse_ns"; // <- type here mapname in maps.ini
// --------------------------- Searching map in Array ------------------------
start = StartProfile();
for (new i=1; i<=maps_count;i++)
{
if (equali(maps[i],mapname)) break;
}
stop = StopProfile(start)
server_print("time of finding map in array is %f secs",stop);
// ---------------------------------------------------------------------------
// ----------------------------- Searching map in Trie -----------------------
start = StartProfile();
strtolower(mapname)
new bool:fmap = TrieKeyExists(trie,mapname);
stop = StopProfile(start)
server_print("time of finding map in Trie is %f secs",stop);
if (fmap) server_print("%s","MAP IS FOUND")
else server_print("%s","MAP NOT FOUND")
// ---------------------------------------------------------------------------
}
public plugin_end()
{
TrieDestroy(trie);
}
Also, is not a good idea to use read_file and read_dir (are very slow). Better to use fopen, fgets, fclose for reading file and open_dir, next_file, close_fir for finding files in directory.
P.S. Sorry for my english. I dont know where to find a good manual on syntax of English.