Binary Tree insead of strcmp
#1

I have had this idea for a while, but as free time gets shorter and shorter, i just want to tell it, and hear some.. idk theories or conclusions that apply for this thing, So i'll try to draw some tree in PS, maybe it'll fail outpointing that this idea is a failure. If it goes, then BinTreeCmd will most likely be a plugin, due to pawno 32 bit varibale sizes. Main idea - jumping throught trees instead of making a "full" cycle of all functions, i think this would give a decent improvement even if having not so fast bug repairs. I actually haven't designed my own bin tree, but I have friend who's working with 'em, and besides, i don't need the normal usual functions, i think it wouldn't be splash tree or something even complex.

Oh and first ideas are:
1. Variable that stores the "deepness" of check (like 0 is 0 in array, 1 is 1 in array and so on).
2. When it reaches deepness of only one result possible (like from /abc /aabc and /aaabc it would result that 3 first charaters are "a") it would make a check if function matches. Possibly by my function, which would stop at mismatch (main component would be? while(cmd[pos]=input[pos])?

My thoughts are that at enough good design only speed problems would be the same as for an binary tree - if first function would be /aaa it surely would be found faster by directly being called.

If we'll or I'll manage to make this tree, a splash tree could be desgined - as players usually use few functions much more than others, like /repair and /gc or what was tele to airport .

Idea of making this is - 1. Learning bin trees in pawn/pawn plugin 2. Possibly making very fast commands. 3. This may grow into check of params too, when it's like id?
Reply
#2

As pawno preview : << I'll edit the topic in few minutes to add full command list.

Now full code, comands and first letters are typed down in comment.
And i think it'll be in 2 ways - 1st precoded into a file or anything and then downloaded by plugin. 2st made in script with some AddCommandNode("text") function.
pawn Код:
#include <a_samp>
forward cmdcmp(const string1[],const string2[], index);
/*
a c e i k m
/earn
/apply
/animat
/count
/counting
/info
/information
/kaiser
/mansion
/mapplace
*/

public OnFilterScriptInit()
{
    print("BinTree");
    OnPlayerCommandText(0, "/animat");
    return 1;
}

stock cmdcmp(const string1[],const string2[], index)
{
    while(strlen(string1)>index&&strlen(string2)>index)
    {
        if(string1[index]!=string2[index]) return false;
        index++;
    }
    return true;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(cmdtext[1]==0x61) // Skips error, 0x61 = "a" Starts from 2nd char as 1st is always "/"
    {                    // Btw some of you always compare if "/" is once again equal to "/"
        if(cmdtext[2]==0x70) // "p" Oh and index is deepness in my means of this code
        {
            if(cmdcmp(cmdtext,"/apply",3)) print("Ok");
            else print("Failure");
            return 1;
        }
        else if(cmdtext[2]==0x6E) // "n"
        {
            if(cmdcmp(cmdtext,"/animat",3)) print("OK");
            return 1;
        }
        return 0;
    }
    else if(cmdtext[1]==0x63) // "c"
    {
        if(cmdtext[2]==0x6F) // "o"
        {
            if(cmdcmp(cmdtext,"/count",3)) // Doubleways
            {
                if(cmdcmp(cmdtext,"/counting",6))
                {
                    print("ing OK");
                }
                else print("count OK");
                return 1;
            }
            return 0;
        }
        return 0;
    }
    else if(cmdtext[1]==0x65) // "e"
    {
        if(cmdcmp(cmdtext,"/earn",2)) // One way - happens when last choose returns 1 command or maybe more. (Not everything is clear for me)
        {
            print("OK");
            return 1;
        }
        return 0;
    }
    else if(cmdtext[1]==0x69) // "i"
    {
        if(cmdtext[2]==0x65) // "f" - I'm not sure if i need to always directly go with cmdcmp here
        {
            if(cmdcmp(cmdtext,"/info",3)) //Another Doubleways, this time equal doubleways. Some developement is required here too.
            {
                print("OK");
                return 1;
            }
        }
        return 0;
    }
    else if(cmdtext[1]==0x6B) // "k"
    {
        if(cmdcmp(cmdtext,"/kaiser",2))// One way again
        {
            print("OK");
            return 1;
        }
        return 0;
    }
    else if(cmdtext[1]==0x6D) // "m"
    {
        if(cmdtext[2]==0x61) // "a"
        {
            if(cmdtext[3]==0x6E) // "n" 3rd level deepness check and i show the split which i hope will exist only in pawn
            {
                if(cmdcmp(cmdtext,"/mansion",4))
                {
                    print("OK");
                    return 1;
                }
            }
            else if(cmdcmp(cmdtext,"/mapplace",4)) // Here's the "problem" - i could do the same as in /mansion, but which is faster?
            //While it's one char, it should be here as it doesn't make anything new, but now i'm unsure. And this may appear in plugin too.
            {
                print("OK");
                return 1;
            }
            return 0;
        }
        return 0;
    }
    return 0;
}
Reply
#3

Ok It'll be a Trie, and if i'll be good at it, then i'll make some hybrid, still no ideas to add?
The pawno code abowe shows a primitive trie in pawno code, but i'm still thinking about 1st charater BST.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)