GetCmd() public method

Return the command in the Cell associated with the given char.
public GetCmd ( char way ) : int
way char the associated with the holding the desired command
return int
Exemplo n.º 1
0
        /// <summary>
        /// Return the element that is stored as last on a path associated with the
        /// given key.
        /// </summary>
        /// <param name="key">the key associated with the desired element</param>
        /// <returns>the last on path element</returns>
        public virtual string GetLastOnPath(string key)
        {
            Row     now = GetRow(root);
            int     w;
            string  last = null;
            StrEnum e    = new StrEnum(key, forward);

            for (int i = 0; i < key.Length - 1; i++)
            {
                char ch = e.Next();
                w = now.GetCmd(ch);
                if (w >= 0)
                {
                    last = cmds[w];
                }
                w = now.GetRef(ch);
                if (w >= 0)
                {
                    now = GetRow(w);
                }
                else
                {
                    return(last);
                }
            }
            w = now.GetCmd(e.Next());
            return((w >= 0) ? cmds[w] : last);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the all attribute of the <see cref="Trie"/> object
        /// </summary>
        /// <param name="key">Description of the Parameter</param>
        /// <returns>The all value</returns>
        public virtual string[] GetAll(string key)
        {
            int[]   res  = new int[key.Length];
            int     resc = 0;
            Row     now  = GetRow(root);
            int     w;
            StrEnum e  = new StrEnum(key, forward);
            bool    br = false;

            for (int i = 0; i < key.Length - 1; i++)
            {
                char ch = e.Next();
                w = now.GetCmd(ch);
                if (w >= 0)
                {
                    int n = w;
                    for (int j = 0; j < resc; j++)
                    {
                        if (n == res[j])
                        {
                            n = -1;
                            break;
                        }
                    }
                    if (n >= 0)
                    {
                        res[resc++] = n;
                    }
                }
                w = now.GetRef(ch);
                if (w >= 0)
                {
                    now = GetRow(w);
                }
                else
                {
                    br = true;
                    break;
                }
            }
            if (br == false)
            {
                w = now.GetCmd(e.Next());
                if (w >= 0)
                {
                    int n = w;
                    for (int j = 0; j < resc; j++)
                    {
                        if (n == res[j])
                        {
                            n = -1;
                            break;
                        }
                    }
                    if (n >= 0)
                    {
                        res[resc++] = n;
                    }
                }
            }

            if (resc < 1)
            {
                return(null);
            }
            string[] R = new string[resc];
            for (int j = 0; j < resc; j++)
            {
                R[j] = cmds[res[j]];
            }
            return(R);
        }