예제 #1
0
        public void Add(string fieldName, FieldParseFunc parseHostField)
        {
            int    index          = GetFastHash(fieldName) % size;
            string lowerFieldName = fieldName.ToLower();

            if (HashRows[index] == null)
            {
                HashRows[index] = new HashRow()
                {
                    ParseFunc = parseHostField,
                    Name      = fieldName,
                    Next      = null
                };
            }
            else
            {
                HashRow cur = HashRows[index];
                while (cur.Next != null)
                {
                    cur = cur.Next;
                }

                cur.Next = new HashRow()
                {
                    Name      = fieldName,
                    Next      = null,
                    ParseFunc = parseHostField
                };
            }
        }
예제 #2
0
 private int[] GetSortedHashPtr(ref HashRow[] hashTabA)
 {
     int nbRow = hashTabA.Length;
     var sortedIndex = new int[hashTabA.LongLength];
     for (int i = 0; i < nbRow; i++)
         sortedIndex[i] = i;
     GetSortedPtr_Recursive(hashTabA, sortedIndex, 0, nbRow - 1);
     return sortedIndex;
 }
예제 #3
0
 private void SortOnHash_recursive(ref HashRow[] array, int lower, int upper)
 {
     int l = lower, u = upper;
     int mid = (lower + upper) / 2;
     UInt32 index = array[mid].Hash;
     while (l <= u) {
         while (array[l].Hash < index)
             l++;
         while (index < array[u].Hash)
             u--;
         if (l <= u) {
             HashRow buffer = array[l];
             array[l] = array[u];
             array[u] = buffer;
             l++; u--;
         }
     }
     if (lower < u) SortOnHash_recursive(ref array, lower, u);
     if (l < upper) SortOnHash_recursive(ref array, l, upper);
 }
예제 #4
0
 private static void GetSortedPtr_Recursive(HashRow[] array, int[] ptr, int left, int rigth)
 {
     int l = left, r = rigth;
     int m = (left + rigth) / 2;
     int midPtr = ptr[m];
     uint midValue = array[midPtr].Hash;
     while (l <= r) {
         while (array[ptr[l]].Hash < midValue || (array[ptr[l]].Hash == midValue && ptr[l] < midPtr))
             l++;
         while (midValue < array[ptr[r]].Hash || (array[ptr[r]].Hash == midValue && midPtr < ptr[r]))
             r--;
         if (l <= r) {
             int buffer = ptr[l];
             ptr[l] = ptr[r];
             ptr[r] = buffer;
             l++; r--;
         }
     }
     if (left < r) GetSortedPtr_Recursive(array, ptr, left, r);
     if (l < rigth) GetSortedPtr_Recursive(array, ptr, l, rigth);
 }
예제 #5
0
        public FieldParseFunc GetFuncOrDefault(byte[] buffer, int offset, int length)
        {
            int index = GetFastHash(buffer, offset, length) % size;

            //string s = Encoding.ASCII.GetString(buffer, offset, length);

            HashRow cur = HashRows[index];

            while (cur != null)
            {
                if (CompareBytes(buffer, offset, length, cur.Name))
                {
                    return(cur.ParseFunc);
                }
                else
                {
                    cur = cur.Next;
                }
            }

            return(defaultFunc);
        }
예제 #6
0
 HashRow[] GetRowsKey(object[,] data, int[] keyColIndexes)
 {
     int nbRow = data.GetLength(0);
     var hashKeys = new HashRow[nbRow];
     for (int r = 0, ri = 1; r < nbRow; r++, ri++) {
         string text = String.Empty;
         foreach (int colIndex in keyColIndexes)
             text += GetObjectText(data[ri, colIndex]);
         hashKeys[r].Key = text;
         hashKeys[r].Hash = ComputeHash(text);
         hashKeys[r].Row = ri;
     }
     return hashKeys;
 }
예제 #7
0
 private void SortOnHash(ref HashRow[] array)
 {
     SortOnHash_recursive(ref array, 0, array.Length - 1);
 }