Exemple #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);
        }
Exemple #2
0
        /// <summary>
        /// Return the element that is stored in a cell associated with the given key.
        /// </summary>
        /// <param name="key">the key</param>
        /// <returns>the associated element</returns>
        public virtual string GetFully(string key)
        {
            Row     now = GetRow(root);
            int     w;
            Cell    c;
            int     cmd = -1;
            StrEnum e   = new StrEnum(key, forward);
            char    ch;

            //char aux; // LUCENENET: IDE0059: Remove unnecessary value assignment

            for (int i = 0; i < key.Length;)
            {
                ch = e.Next();
                i++;

                c = now.At(ch);
                if (c == null)
                {
                    return(null);
                }

                cmd = c.cmd;

                for (int skip = c.skip; skip > 0; skip--)
                {
                    if (i < key.Length)
                    {
                        /*aux =*/ e.Next(); // LUCENENET: IDE0059: Remove unnecessary value assignment
                    }
                    else
                    {
                        return(null);
                    }
                    i++;
                }

                w = now.GetRef(ch);
                if (w >= 0)
                {
                    now = GetRow(w);
                }
                else if (i < key.Length)
                {
                    return(null);
                }
            }
            return((cmd == -1) ? null : cmds[cmd]);
        }
Exemple #3
0
        /// <summary>
        /// Return the element that is stored in a cell associated with the given key.
        /// </summary>
        /// <param name="key">the key</param>
        /// <returns>the associated element</returns>
        public virtual string GetFully(string key)
        {
            Row     now = GetRow(root);
            int     w;
            Cell    c;
            int     cmd = -1;
            StrEnum e   = new StrEnum(key, forward);
            char    ch;
            char    aux;

            for (int i = 0; i < key.Length;)
            {
                ch = e.Next();
                i++;

                c = now.At(ch);
                if (c == null)
                {
                    return(null);
                }

                cmd = c.cmd;

                for (int skip = c.skip; skip > 0; skip--)
                {
                    if (i < key.Length)
                    {
                        aux = e.Next();
                    }
                    else
                    {
                        return(null);
                    }
                    i++;
                }

                w = now.GetRef(ch);
                if (w >= 0)
                {
                    now = GetRow(w);
                }
                else if (i < key.Length)
                {
                    return(null);
                }
            }
            return((cmd == -1) ? null : cmds[cmd]);
        }
Exemple #4
0
        /// <summary>
        /// Add the given key associated with the given patch command. If either
        /// parameter is null this method will return without executing.
        /// </summary>
        /// <param name="key">the key</param>
        /// <param name="cmd">the patch command</param>
        public virtual void Add(string key, string cmd)
        {
            if (key == null || cmd == null)
            {
                return;
            }
            if (cmd.Length == 0)
            {
                return;
            }
            int id_cmd = cmds.IndexOf(cmd);

            if (id_cmd == -1)
            {
                id_cmd = cmds.Count;
                cmds.Add(cmd);
            }

            int node = root;
            Row r    = GetRow(node);

            StrEnum e = new StrEnum(key, forward);

            for (int i = 0; i < e.Length - 1; i++)
            {
                char ch = e.Next();
                node = r.GetRef(ch);
                if (node >= 0)
                {
                    r = GetRow(node);
                }
                else
                {
                    node = rows.Count;
                    Row n;
                    rows.Add(n = new Row());
                    r.SetRef(ch, node);
                    r = n;
                }
            }
            r.SetCmd(e.Next(), id_cmd);
        }
Exemple #5
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);
        }
Exemple #6
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;
        }
Exemple #7
0
        /// <summary>
        /// Return the element that is stored in a cell associated with the given key.
        /// </summary>
        /// <param name="key">the key</param>
        /// <returns>the associated element</returns>
        public virtual string GetFully(string key)
        {
            Row now = GetRow(root);
            int w;
            Cell c;
            int cmd = -1;
            StrEnum e = new StrEnum(key, forward);
            char ch;
            char aux;

            for (int i = 0; i < key.Length;)
            {
                ch = e.Next();
                i++;

                c = now.At(ch);
                if (c == null)
                {
                    return null;
                }

                cmd = c.cmd;

                for (int skip = c.skip; skip > 0; skip--)
                {
                    if (i < key.Length)
                    {
                        aux = e.Next();
                    }
                    else
                    {
                        return null;
                    }
                    i++;
                }

                w = now.GetRef(ch);
                if (w >= 0)
                {
                    now = GetRow(w);
                }
                else if (i < key.Length)
                {
                    return null;
                }
            }
            return (cmd == -1) ? null : cmds[cmd];
        }
Exemple #8
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;
        }
Exemple #9
0
        /// <summary>
        /// Add the given key associated with the given patch command. If either
        /// parameter is null this method will return without executing.
        /// </summary>
        /// <param name="key">the key</param>
        /// <param name="cmd">the patch command</param>
        public virtual void Add(string key, string cmd)
        {
            if (key == null || cmd == null)
            {
                return;
            }
            if (cmd.Length == 0)
            {
                return;
            }
            int id_cmd = cmds.IndexOf(cmd);
            if (id_cmd == -1)
            {
                id_cmd = cmds.Count;
                cmds.Add(cmd);
            }

            int node = root;
            Row r = GetRow(node);

            StrEnum e = new StrEnum(key, forward);

            for (int i = 0; i < e.Length - 1; i++)
            {
                char ch = e.Next();
                node = r.GetRef(ch);
                if (node >= 0)
                {
                    r = GetRow(node);
                }
                else
                {
                    node = rows.Count;
                    Row n;
                    rows.Add(n = new Row());
                    r.SetRef(ch, node);
                    r = n;
                }
            }
            r.SetCmd(e.Next(), id_cmd);
        }