Exemplo n.º 1
0
        public string getKey(int add)
        {
            string res           = "";
            int    div           = 1;
            int    wildcardCount = wildcardList.Count - 1;
            int    i             = pattern.Length - 1;

            while (i >= 0)
            {
                if (pattern[i] != ']')
                {
                    res += pattern[i--];
                }
                else
                {
                    Wildcard wc = (Wildcard)wildcardList[wildcardCount--];
                    if (add < div)
                    {
                        res += wc.getChar();
                    }
                    else
                    {
                        res += wc.getChar((add / div) % wc.size());
                        div *= wc.size();
                    }
                    while (pattern[i--] != '[')
                    {
                        ;
                    }
                }
            }
            char[] r = res.ToCharArray();
            Array.Reverse(r);
            return(new string(r));
        }
Exemplo n.º 2
0
        /// <summary>
        /// See this[]
        /// </summary>
        /// <param name="index">The index</param>
        /// <returns>The sub key pattern</returns>
        private KeyPattern GetAtIndex(BigInteger index)
        {
            //calculate the wildcard positions on which we want to split:
            int[] splittingPositions = new int[pattern.wildcardList.Count];
            for (int k = pattern.wildcardList.Count - 1; k >= 0; k--)
            {
                splittingPositions[k] = (int)(index % splittingQuotient[k]);
                index /= splittingQuotient[k];
            }
            Debug.Assert(index == 0);

            //split up the sub pattern parts:
            KeyPattern subpart = new KeyPattern(pattern.GetPattern());

            subpart.wildcardList = new ArrayList();
            for (int k = 0; k < pattern.wildcardList.Count; k++)
            {
                Wildcard subwc     = ((Wildcard)pattern.wildcardList[k]);
                char[]   values    = new char[256];
                int      sublength = subwc.size() / splittingQuotient[k];
                for (int i = 0; i < sublength; i++)
                {
                    values[i] = subwc.getChar(i + splittingPositions[k] * sublength);
                }
                Wildcard newwc = new Wildcard(values, sublength);
                subpart.wildcardList.Add(newwc);
            }

            return(subpart);
        }
Exemplo n.º 3
0
        public bool Contains(KeyPattern pattern)
        {
            if (pattern.wildcardList.Count != this.pattern.wildcardList.Count)
            {
                return(false);
            }
            if (pattern.GetPattern() != this.pattern.GetPattern())
            {
                return(false);
            }

            bool equal = true;

            for (int k = 0; k < pattern.wildcardList.Count; k++)
            {
                Wildcard wc     = ((Wildcard)pattern.wildcardList[k]);
                Wildcard thiswc = ((Wildcard)this.pattern.wildcardList[k]);
                if (wc.size() != (thiswc.size() / splittingQuotient[k]))
                {
                    return(false);
                }

                bool bolContains2 = true;
                int  begin        = equal ? splittingCounter[k] : 0;
                for (int j = begin; j < splittingQuotient[k]; j++)
                {
                    bool bolContains = true;
                    for (int i = 0; i < wc.size(); i++)
                    {
                        if (wc.getChar(i - wc.count()) != thiswc.getChar(i + j * wc.size()))
                        {
                            bolContains = false;
                            break;
                        }
                    }
                    if (bolContains)
                    {
                        equal        = (j == splittingCounter[k]);
                        bolContains2 = true;
                        break;
                    }
                }
                if (!bolContains2)
                {
                    return(false);
                }
            }
            return(!equal);
        }
Exemplo n.º 4
0
        public KeyPattern Pop()
        {
            if (stack.Count != 0)
            {
                counter++;
                return((KeyPattern)stack.Pop());
            }

            if (end)
            {
                return(null);
            }

            KeyPattern part = new KeyPattern(pattern.GetPattern());

            part.wildcardList = new ArrayList();
            for (int k = 0; k < pattern.wildcardList.Count; k++)
            {
                Wildcard wc     = ((Wildcard)pattern.wildcardList[k]);
                char[]   values = new char[256];
                int      length = wc.size() / splittingQuotient[k];
                for (int i = 0; i < length; i++)
                {
                    values[i] = wc.getChar(i + splittingCounter[k] * length);
                }
                Wildcard newwc = new Wildcard(values, length);
                part.wildcardList.Add(newwc);
            }

            if (!SuccCounter())
            {
                end = true;
            }

            counter++;
            return(part);
        }
Exemplo n.º 5
0
        public string getKey()
        {
            string res           = "";
            int    wildcardCount = 0;
            int    i             = 0;

            while (i < pattern.Length)
            {
                if (pattern[i] != '[')
                {
                    res += pattern[i++];
                }
                else
                {
                    Wildcard wc = (Wildcard)wildcardList[wildcardCount++];
                    res += wc.getChar();
                    while (pattern[i++] != ']')
                    {
                        ;
                    }
                }
            }
            return(res);
        }