public static uint[][] HistogramByteComponents(ulong[] inArray, Int32 l, Int32 r) { const int numberOfBins = 256; const int numberOfDigits = sizeof(ulong); uint[][] count = new uint[numberOfDigits][]; for (int i = 0; i < numberOfDigits; i++) { count[i] = new uint[numberOfBins]; } var union = new UInt64ByteUnion(); for (int current = l; current <= r; current++) // Scan the array and count the number of times each digit value appears - i.e. size of each bin { union.integer = inArray[current]; count[0][union.byte0]++; count[1][union.byte1]++; count[2][union.byte2]++; count[3][union.byte3]++; count[4][union.byte4]++; count[5][union.byte5]++; count[6][union.byte6]++; count[7][union.byte7]++; } return(count); }
public static Tuple<uint[][], UInt64[]> HistogramByteComponentsAndKeyArray<T>(T[] inArray, Int32 l, Int32 r, Func<T, UInt64> getKey) { const int numberOfBins = 256; const int numberOfDigits = sizeof(UInt32); var inKeys = new UInt64[inArray.Length]; var count = new uint[numberOfDigits][]; for (int i = 0; i < numberOfDigits; i++) count[i] = new uint[numberOfBins]; #if true var union = new UInt64ByteUnion(); for (int current = l; current <= r; current++) // Scan the array and count the number of times each digit value appears - i.e. size of each bin { union.integer = getKey(inArray[current]); inKeys[current] = union.integer; count[0][union.byte0]++; count[1][union.byte1]++; count[2][union.byte2]++; count[3][union.byte3]++; count[4][union.byte4]++; count[5][union.byte5]++; count[6][union.byte6]++; count[7][union.byte7]++; } #else for (int current = l; current <= r; current++) // Scan the array and count the number of times each digit value appears - i.e. size of each bin { uint value = inArray[current]; count[0][ value & 0xff ]++; count[1][(value & 0xff00) >> 8]++; count[2][(value & 0xff0000) >> 16]++; count[3][(value & 0xff000000) >> 24]++; } #endif return new Tuple<uint[][], UInt64[]>(count, inKeys); }
public static int[] HistogramByteComponentsUsingUnion(ulong[] inArray, Int32 l, Int32 r, int shiftRightAmount) { const int numberOfBins = 256; int[] count = new int[numberOfBins]; int whichByte = shiftRightAmount / 8; var union = new UInt64ByteUnion(); switch (whichByte) { case 0: for (int current = l; current <= r; current++) // Scan the array and count the number of times each digit value appears - i.e. size of each bin { union.integer = inArray[current]; count[union.byte0]++; } break; case 1: for (int current = l; current <= r; current++) { union.integer = inArray[current]; count[union.byte1]++; } break; case 2: for (int current = l; current <= r; current++) { union.integer = inArray[current]; count[union.byte2]++; } break; case 3: for (int current = l; current <= r; current++) { union.integer = inArray[current]; count[union.byte3]++; } break; case 4: for (int current = l; current <= r; current++) { union.integer = inArray[current]; count[union.byte4]++; } break; case 5: for (int current = l; current <= r; current++) { union.integer = inArray[current]; count[union.byte5]++; } break; case 6: for (int current = l; current <= r; current++) { union.integer = inArray[current]; count[union.byte6]++; } break; case 7: for (int current = l; current <= r; current++) { union.integer = inArray[current]; count[union.byte7]++; } break; } return(count); }
public static uint[][] HistogramNBitsPerComponents(ulong[] inArray, Int32 l, Int32 r, int bitsPerComponent) { int numberOfBins = 1 << bitsPerComponent; int numberOfDigits = (sizeof(uint) * 8 + bitsPerComponent - 1) / bitsPerComponent; // round up uint[][] countLeft = new uint[numberOfDigits][]; for (int i = 0; i < numberOfDigits; i++) { countLeft[i] = new uint[numberOfBins]; } if (bitsPerComponent == 8) { var union = new UInt64ByteUnion(); for (int current = l; current <= r; current++) // Scan the array and count the number of times each digit value appears - i.e. size of each bin { union.integer = inArray[current]; countLeft[0][union.byte0]++; countLeft[1][union.byte1]++; countLeft[2][union.byte2]++; countLeft[3][union.byte3]++; countLeft[4][union.byte4]++; countLeft[5][union.byte5]++; countLeft[6][union.byte6]++; countLeft[7][union.byte7]++; } } else if (bitsPerComponent == 9) { for (int current = l; current <= r; current++) { ulong value = inArray[current]; countLeft[0][value & 0x1ff]++; countLeft[1][(value & 0x3fe00) >> 9]++; countLeft[2][(value & 0x7fc0000) >> 18]++; countLeft[3][(value & 0xff8000000) >> 27]++; countLeft[4][(value & 0x1ff000000000) >> 36]++; countLeft[5][(value & 0x3fe00000000000) >> 45]++; countLeft[6][(value & 0x7fc0000000000000) >> 54]++; countLeft[7][(value & 0x8000000000000000) >> 63]++; } } else if (bitsPerComponent == 10) // useful for 64-bit { for (int current = l; current <= r; current++) { ulong value = inArray[current]; countLeft[0][value & 0x3ff]++; countLeft[1][(value & 0xffc00) >> 10]++; countLeft[2][(value & 0x3ff00000) >> 20]++; countLeft[3][(value & 0xffc0000000) >> 30]++; countLeft[4][(value & 0x3ff0000000000) >> 40]++; countLeft[5][(value & 0xffc000000000000) >> 50]++; countLeft[6][(value & 0xf000000000000000) >> 60]++; } } else if (bitsPerComponent == 11) { for (int current = l; current <= r; current++) { ulong value = inArray[current]; countLeft[0][value & 0x7ff]++; countLeft[1][(value & 0x3ff800) >> 11]++; countLeft[2][(value & 0x1ffc00000) >> 22]++; countLeft[3][(value & 0xffe00000000) >> 33]++; countLeft[4][(value & 0x7ff00000000000) >> 44]++; countLeft[5][(value & 0xff80000000000000) >> 55]++; } } else if (bitsPerComponent == 12) { for (int current = l; current <= r; current++) { ulong value = inArray[current]; countLeft[0][value & 0xfff]++; countLeft[1][(value & 0xfff000) >> 12]++; countLeft[2][(value & 0xfff000000) >> 24]++; countLeft[3][(value & 0xfff000000000) >> 36]++; countLeft[4][(value & 0xfff000000000000) >> 48]++; countLeft[5][(value & 0xf000000000000000) >> 60]++; } } else if (bitsPerComponent == 13) { for (int current = l; current <= r; current++) { ulong value = inArray[current]; countLeft[0][value & 0x1fff]++; countLeft[1][(value & 0x3ffe000) >> 13]++; countLeft[2][(value & 0x7ffc000000) >> 26]++; countLeft[3][(value & 0xfff8000000000) >> 39]++; countLeft[4][(value & 0xfff0000000000000) >> 52]++; } } else if (bitsPerComponent == 16) { var union = new UInt64UShortUnion(); for (int current = l; current <= r; current++) { union.integer = inArray[current]; countLeft[0][union.ushort0]++; countLeft[1][union.ushort1]++; countLeft[2][union.ushort0]++; countLeft[3][union.ushort1]++; } } else { uint componentMask = (uint)numberOfBins - 1; for (int current = l; current <= r; current++) // Scan the array and count the number of times each digit value appears - i.e. size of each bin { ulong value = inArray[current]; for (int i = 0; i < numberOfDigits; i++) { countLeft[i][value & componentMask]++; componentMask <<= bitsPerComponent; } } } return(countLeft); }