コード例 #1
0
 public virtual int GetEndOffset(byte[] b, int start, int end, int[] lengthIndices
                                 , KeyFieldHelper.KeyDescription k)
 {
     //if -k2,2.8 is the keyspec, the endChar is lengthIndices[1] + 8
     //note that the [0]'th element is the number of fields in the key
     if (k.endFieldIdx == 0)
     {
         //there is no end field specified for this keyspec. So the remaining
         //part of the key is considered in its entirety.
         return(end - 1);
     }
     if (lengthIndices[0] >= k.endFieldIdx)
     {
         int position = 0;
         int i;
         for (i = 1; i < k.endFieldIdx; i++)
         {
             position += lengthIndices[i] + keyFieldSeparator.Length;
         }
         if (k.endChar == 0)
         {
             position += lengthIndices[i];
         }
         if (position + k.endChar <= (end - start))
         {
             return(start + position + k.endChar - 1);
         }
         return(end - 1);
     }
     return(end - 1);
 }
コード例 #2
0
 private void PrintKey(KeyFieldHelper.KeyDescription key)
 {
     System.Console.Out.WriteLine("key.beginFieldIdx: " + key.beginFieldIdx);
     System.Console.Out.WriteLine("key.beginChar: " + key.beginChar);
     System.Console.Out.WriteLine("key.endFieldIdx: " + key.endFieldIdx);
     System.Console.Out.WriteLine("key.endChar: " + key.endChar);
     System.Console.Out.WriteLine("key.numeric: " + key.numeric);
     System.Console.Out.WriteLine("key.reverse: " + key.reverse);
     System.Console.Out.WriteLine("parseKey over");
 }
コード例 #3
0
 /// <summary>
 /// Required for backcompatibility with num.key.fields.for.partition in
 /// <see cref="KeyFieldBasedPartitioner{K2, V2}"/>
 ///
 /// </summary>
 public virtual void SetKeyFieldSpec(int start, int end)
 {
     if (end >= start)
     {
         KeyFieldHelper.KeyDescription k = new KeyFieldHelper.KeyDescription();
         k.beginFieldIdx = start;
         k.endFieldIdx   = end;
         keySpecSeen     = true;
         allKeySpecs.AddItem(k);
     }
 }
コード例 #4
0
        public virtual void ParseOption(string option)
        {
            if (option == null || option.Equals(string.Empty))
            {
                //we will have only default comparison
                return;
            }
            StringTokenizer args = new StringTokenizer(option);

            KeyFieldHelper.KeyDescription global = new KeyFieldHelper.KeyDescription();
            while (args.HasMoreTokens())
            {
                string arg = args.NextToken();
                if (arg.Equals("-n"))
                {
                    global.numeric = true;
                }
                if (arg.Equals("-r"))
                {
                    global.reverse = true;
                }
                if (arg.Equals("-nr"))
                {
                    global.numeric = true;
                    global.reverse = true;
                }
                if (arg.StartsWith("-k"))
                {
                    KeyFieldHelper.KeyDescription k = ParseKey(arg, args);
                    if (k != null)
                    {
                        allKeySpecs.AddItem(k);
                        keySpecSeen = true;
                    }
                }
            }
            foreach (KeyFieldHelper.KeyDescription key in allKeySpecs)
            {
                if (!(key.reverse | key.numeric))
                {
                    key.reverse = global.reverse;
                    key.numeric = global.numeric;
                }
            }
            if (allKeySpecs.Count == 0)
            {
                allKeySpecs.AddItem(global);
            }
        }
コード例 #5
0
 public virtual int GetStartOffset(byte[] b, int start, int end, int[] lengthIndices
                                   , KeyFieldHelper.KeyDescription k)
 {
     //if -k2.5,2 is the keyspec, the startChar is lengthIndices[1] + 5
     //note that the [0]'th element is the number of fields in the key
     if (lengthIndices[0] >= k.beginFieldIdx)
     {
         int position = 0;
         for (int i = 1; i < k.beginFieldIdx; i++)
         {
             position += lengthIndices[i] + keyFieldSeparator.Length;
         }
         if (position + k.beginChar <= (end - start))
         {
             return(start + position + k.beginChar - 1);
         }
     }
     return(-1);
 }
コード例 #6
0
        private int CompareByteSequence(byte[] first, int start1, int end1, byte[] second
                                        , int start2, int end2, KeyFieldHelper.KeyDescription key)
        {
            if (start1 == -1)
            {
                if (key.reverse)
                {
                    return(1);
                }
                return(-1);
            }
            if (start2 == -1)
            {
                if (key.reverse)
                {
                    return(-1);
                }
                return(1);
            }
            int compareResult = 0;

            if (!key.numeric)
            {
                compareResult = CompareBytes(first, start1, end1 - start1 + 1, second, start2, end2
                                             - start2 + 1);
            }
            if (key.numeric)
            {
                compareResult = NumericalCompare(first, start1, end1, second, start2, end2);
            }
            if (key.reverse)
            {
                return(-compareResult);
            }
            return(compareResult);
        }
コード例 #7
0
        private KeyFieldHelper.KeyDescription ParseKey(string arg, StringTokenizer args)
        {
            //we allow for -k<arg> and -k <arg>
            string keyArgs = null;

            if (arg.Length == 2)
            {
                if (args.HasMoreTokens())
                {
                    keyArgs = args.NextToken();
                }
            }
            else
            {
                keyArgs = Sharpen.Runtime.Substring(arg, 2);
            }
            if (keyArgs == null || keyArgs.Length == 0)
            {
                return(null);
            }
            StringTokenizer st = new StringTokenizer(keyArgs, "nr.,", true);

            KeyFieldHelper.KeyDescription key = new KeyFieldHelper.KeyDescription();
            string token;

            //the key is of the form 1[.3][nr][,1.5][nr]
            if (st.HasMoreTokens())
            {
                token = st.NextToken();
                //the first token must be a number
                key.beginFieldIdx = System.Convert.ToInt32(token);
            }
            if (st.HasMoreTokens())
            {
                token = st.NextToken();
                if (token.Equals("."))
                {
                    token         = st.NextToken();
                    key.beginChar = System.Convert.ToInt32(token);
                    if (st.HasMoreTokens())
                    {
                        token = st.NextToken();
                    }
                    else
                    {
                        return(key);
                    }
                }
                do
                {
                    if (token.Equals("n"))
                    {
                        key.numeric = true;
                    }
                    else
                    {
                        if (token.Equals("r"))
                        {
                            key.reverse = true;
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (st.HasMoreTokens())
                    {
                        token = st.NextToken();
                    }
                    else
                    {
                        return(key);
                    }
                }while (true);
                if (token.Equals(","))
                {
                    token = st.NextToken();
                    //the first token must be a number
                    key.endFieldIdx = System.Convert.ToInt32(token);
                    if (st.HasMoreTokens())
                    {
                        token = st.NextToken();
                        if (token.Equals("."))
                        {
                            token       = st.NextToken();
                            key.endChar = System.Convert.ToInt32(token);
                            if (st.HasMoreTokens())
                            {
                                token = st.NextToken();
                            }
                            else
                            {
                                return(key);
                            }
                        }
                        do
                        {
                            if (token.Equals("n"))
                            {
                                key.numeric = true;
                            }
                            else
                            {
                                if (token.Equals("r"))
                                {
                                    key.reverse = true;
                                }
                                else
                                {
                                    throw new ArgumentException("Invalid -k argument. " + "Must be of the form -k pos1,[pos2], where pos is of the form "
                                                                + "f[.c]nr");
                                }
                            }
                            if (st.HasMoreTokens())
                            {
                                token = st.NextToken();
                            }
                            else
                            {
                                break;
                            }
                        }while (true);
                    }
                    return(key);
                }
                throw new ArgumentException("Invalid -k argument. " + "Must be of the form -k pos1,[pos2], where pos is of the form "
                                            + "f[.c]nr");
            }
            return(key);
        }