Arkshine
My tests:
Used:
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;
new Trie:trie;
new mapIdx;
new Profile:start;
new Float:stop;
new bool:bMapIdx;
new mapname[64]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
set_task(1.0, "test");
}
public test()
{
trie = TrieCreate();
// addons/amxmodx/configs/maps.ini
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;
server_print("^n-----------------------------------------------")
// ---------------------------- Adding map in array --------------------------
maps_count = 0
start = StartProfile();
hFile = fopen(maps_file,"rt")
while (fgets(hFile,buffer,64))
{
trim(buffer);
strtolower(buffer);
maps[++maps_count] = buffer;
}
fclose(hFile);
stop = StopProfile(start)
server_print("Adding Time in array is %f secs", stop);
// ---------------------------------------------------------------------------
// ---------------------------- Adding map in Trie ---------------------------
maps_count = 0
start = StartProfile();
hFile = fopen(maps_file,"rt")
while (fgets(hFile,buffer, 64))
{
trim(buffer)
strtolower(buffer)
TrieSetCell(trie, buffer, ++maps_count);
}
fclose(hFile);
stop = StopProfile(start)
server_print("Adding Time in Trie is %f secs", stop);
// ---------------------------------------------------------------------------
server_print("Total Maps = %d", maps_count);
// ------------------------- Search First Map in maps.ini ---------------------------
mapname = "ae_sTrafeRs_heaven"; // <- First map in maps.ini
strtolower(mapname)
server_print("-----------------------------------------------")
server_print("Searching first map in maps.ini (%s) ...", mapname)
SearchInArray(mapname, "Searching using Array ...")
SearchInTrie(mapname, "Searching using Trie ...")
// ----------------------------------------------------------------------------------
// ------------------------- Search Middle Map in maps.ini ---------------------------
mapname = "etl_speedcliff"; // <- Middle map in maps.ini
strtolower(mapname)
server_print("-----------------------------------------------")
server_print("Searching middle map in maps.ini (%s) ...", mapname)
SearchInArray(mapname, "Searching using Array ...")
SearchInTrie(mapname, "Searching using Trie ...")
// ----------------------------------------------------------------------------------
// ------------------------- Search Last Map in maps.ini ---------------------------
mapname = "zr_icecave"; // <- Last map in maps.ini
strtolower(mapname)
server_print("-----------------------------------------------")
server_print("Searching last map in maps.ini (%s) ...", mapname)
SearchInArray(mapname, "Searching using Array ...")
SearchInTrie(mapname, "Searching using Trie ...")
// ----------------------------------------------------------------------------------
// ------------------------- Search nonexistent map in maps.ini ---------------------------
mapname = "Hello"; // <- nonexistent map in maps.ini
strtolower(mapname)
server_print("-----------------------------------------------")
server_print("Searching nonexistent map in maps.ini (%s) ...", mapname)
SearchInArray(mapname, "Searching using Array ...")
SearchInTrie(mapname, "Searching using Trie ...")
// ----------------------------------------------------------------------------------
}
public plugin_end()
{
TrieDestroy(trie);
}
stock SearchInArray(mapname[], comment[])
{
mapIdx = -1
start = StartProfile();
for (new i=1; i<=maps_count; i++)
{
if (equal(maps[i], mapname))
{
mapIdx = i;
break;
}
}
stop = StopProfile(start)
server_print("^n%s^nmapIdx = %d. Find time in array is %f secs", comment, mapIdx, stop);
}
stock SearchInTrie(mapname[], const comment[])
{
mapIdx = -1
start = StartProfile();
bMapIdx = TrieGetCell(trie, mapname, mapIdx);
stop = StopProfile(start)
server_print("^n%s^nmapIdx = %d. Find time in Trie is %f secs", comment, mapIdx, stop);
}
This test without prefixes. With its time will be (max search time * number of prefixes)
Often, players often write in chat.
Quote:
- You won't loop through all the maps all the time
|
No, when player type any word in chat then plugin through all the maps and all prefixes.
Quote:
- equal() is not an intensive native
|
I changed from equali to equal in test plugin.