, , , RowKey . , PartitionKey, , RowKey (, "scope-id" → "12-8374" ).
, enzi. Base64, , 16 . , , / .
public static string NumberToId(int number, bool ascending = true)
{
if (!ascending)
number = 16777215 - number;
return new string(new[] {
SixBitToChar((byte)((number & 16515072) >> 18)),
SixBitToChar((byte)((number & 258048) >> 12)),
SixBitToChar((byte)((number & 4032) >> 6)),
SixBitToChar((byte)(number & 63)) });
}
public static int IdToNumber(string id, bool ascending = true)
{
var number = ((int)CharToSixBit(id[0]) << 18) | ((int)CharToSixBit(id[1]) << 12) | ((int)CharToSixBit(id[2]) << 6) | (int)CharToSixBit(id[3]);
return ascending ? number : -1 * (number - 16777215);
}
[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
static char SixBitToChar(byte b)
{
if (b == 0)
return '!';
if (b == 1)
return '$';
if (b < 12)
return (char)((int)b - 2 + (int)'0');
if (b < 38)
return (char)((int)b - 12 + (int)'A');
return (char)((int)b - 38 + (int)'a');
}
[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
static byte CharToSixBit(char c)
{
if (c == '!')
return 0;
if (c == '$')
return 1;
if (c <= '9')
return (byte)((int)c - (int)'0' + 2);
if (c <= 'Z')
return (byte)((int)c - (int)'A' + 12);
return (byte)((int)c - (int)'a' + 38);
}
false , , . ! $ Base64, RowKey. , , RowKey, . :
0 → !!!! asc zzzz desc
1000 → !! Dc asc zzkL desc
2000 → !! TE asc zzUj desc
3000 → !! - asc zzF5 desc
4000 → !! yU asc zz $T desc
5000 → ! $C6 asc zylr desc
6000 → ! $Rk asc zyWD desc
7000 → ! $hM asc zyGb desc
8000 → ! $x! asc zy0z desc
9000 → ! 0Ac asc zxnL desc