intenthq/icicle

ported to c

usergoodvery opened this issue · 0 comments

Hi,

I did a simple c translation of your code as per below and ran it with fixed inputs (seconds and micros are actual output from within the lua scripts) and I get the following output:

(MAX_SEQUENCE: '4095', MIN_LOGICAL_SHARD_ID: '1', MAX_LOGICAL_SHARD_ID: '1023' ID='18435124110053871640'

Assuming that's the right ID based on the implementation below, as a verification I was wondering if you had a test in your environment that can be used to feed in the same input values to verify if it produces the same id?

I also tried to deconstruct the ID ie. extract the timestamp value, but could not get that to work...

#include <stdio.h>
int main ()
{
static const long CUSTOM_EPOCH = 1401277473;

  static const int LOGICAL_SHARD_ID_BITS = 10;
  static const int SEQUENCE_BITS = 12;

  static const int TIMESTAMP_SHIFT = SEQUENCE_BITS + LOGICAL_SHARD_ID_BITS;
  static const int LOGICAL_SHARD_ID_SHIFT = SEQUENCE_BITS;

  static const unsigned long MAX_SEQUENCE = ~(-1 << SEQUENCE_BITS);
  static const unsigned long MAX_LOGICAL_SHARD_ID = ~(-1 << LOGICAL_SHARD_ID_BITS);
  static const unsigned long MIN_LOGICAL_SHARD_ID = 1;
  static const long MAX_BATCH_SIZE = MAX_SEQUENCE + 1;
  #define ONE_MILLI_IN_MICRO_SECS 1000

//fixed inputs to validate against
   unsigned long sequence=24;
   unsigned long timestamp=(1454624775 * ONE_MILLI_IN_MICRO_SECS) + 
                    (593028 / ONE_MILLI_IN_MICRO_SECS);
   unsigned long logicalShardId = 1;

//construct id
unsigned long id = ((timestamp - CUSTOM_EPOCH) << TIMESTAMP_SHIFT)|
                              (logicalShardId << LOGICAL_SHARD_ID_SHIFT)|
                               sequence;
printf ("MAX_SEQUENCE: '%ld', MIN_LOGICAL_SHARD_ID: '%ld', MAX_LOGICAL_SHARD_ID: '%ld' ID='%lu'\n",
MAX_SEQUENCE, MIN_LOGICAL_SHARD_ID, MAX_LOGICAL_SHARD_ID, id );

return 0;
}