<commit_before># dekuan/dedid
An unique id generator for primary key of distributed database



# ALGORITHM

### Bit structure
It's a 64 bits bigint.

~~~
0 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx x xxxxxx xxxxxx xx xxxxxxxx
~~~

### Details

Bits	| Usage	| Remark
----------|---------|--------
0			| Reserved| Always be 0
41			| Escaped Time (in millisecond)|0~69 years
6			| Data center|0~63
6			| Data node in the data center |0~63
10			| Random|0~1023




# Mark bits

### Center
~~~
0 00000000 00000000 00000000 00000000 00000000 0 111111 000000 00 00000000

00000000 00000000 00000000 00000000 00000000 00111111 00000000 00000000

00       00       00       00       00       3F       00       00
~~~

### Node
~~~
0 00000000 00000000 00000000 00000000 00000000 0 000000 111111 00 00000000

00000000 00000000 00000000 00000000 00000000 00000000 11111100 00000000

00       00       00       00       00       00       FC       00
~~~


### Escaped Time
~~~
0 11111111 11111111 11111111 11111111 11111111 1 000000 000000 00 00000000

01111111 11111111 11111111 11111111 11111111 11000000 00000000 00000000

7F       FF       FF       FF       FF       C0       00       00
~~~


### Random
~~~
0 00000000 00000000 00000000 00000000 00000000 0 000000 000000 11 11111111

00000000 00000000 00000000 00000000 00000000 00000000 00000011 11111111

00       00       00       00       00       00       03       FF
~~~


# HOW TO USE

### Create an new id

~~~
$cDId		= CDId::getInstance();
$nCenter	= 61;
$nNode		= 37;

$arrD		= [];
$nNewId	= $cDId->createId( $nCenter, $nNode, $arrD );

echo "new id = " . $nNewId . "\r\n";
print_r( $arrD );

~~~

##### output

~~~
new id = 98037672957548006
Array
(
    [center] => 61
    [node] => 37
    [time] => 23374002684
    [rand] => 486
)
~~~


### Parse an id for getting the details

~~~
$cDId		= CDId::getInstance();
$arrId		= $cDId->parseId( 98037672957548006 );
print_r( $arrId );

~~~

##### output

~~~
Array
(<commit_msg>Upgrade readme.md<commit_after># dekuan/dedid
An unique id generator for primary key of distributed database



# ALGORITHM

### Bit structure
It's a 64 bits bigint.

~~~
0 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx x xxxxxx xxxxxx xx xxxxxxxx
~~~

### Details

Bits	| Usage	| Remark
----------|---------|--------
0			| Reserved| Always be 0
41			| Escaped Time (in millisecond)|0~69 years
6			| Data center|0~63
6			| Data node in the data center |0~63
10			| Random|0~1023




# Mark bits

### Center
~~~
0 00000000 00000000 00000000 00000000 00000000 0 111111 000000 00 00000000

00000000 00000000 00000000 00000000 00000000 00111111 00000000 00000000

00       00       00       00       00       3F       00       00
~~~

### Node
~~~
0 00000000 00000000 00000000 00000000 00000000 0 000000 111111 00 00000000

00000000 00000000 00000000 00000000 00000000 00000000 11111100 00000000

00       00       00       00       00       00       FC       00
~~~


### Escaped Time
~~~
0 11111111 11111111 11111111 11111111 11111111 1 000000 000000 00 00000000

01111111 11111111 11111111 11111111 11111111 11000000 00000000 00000000

7F       FF       FF       FF       FF       C0       00       00
~~~


### Random
~~~
0 00000000 00000000 00000000 00000000 00000000 0 000000 000000 11 11111111

00000000 00000000 00000000 00000000 00000000 00000000 00000011 11111111

00       00       00       00       00       00       03       FF
~~~


# HOW TO USE

### Create an new id normally

~~~
$cDId		= CDId::getInstance();
$nCenter	= 61;
$nNode		= 37;

$arrD		= [];
$nNewId	= $cDId->createId( $nCenter, $nNode, null, $arrD );

echo "new id = " . $nNewId . "\r\n";
print_r( $arrD );

~~~

##### output

~~~
new id = 98037672957548006
Array
(
    [center] => 61
    [node] => 37
    [time] => 23374002684
    [rand] => 486
)
~~~


### Create an new id with crc32 hash value

~~~
$cDId		= CDId::getInstance();
$nCenter	= 0;
$nNode		= 15;

$sSrc		= "dekuan";
$arrD		= [];
$nNewId	= $cDId->createId( $nCenter, $nNode, $sSrc, $arrD );

echo "new id = " . $nNewId . "\r\n";
print_r( $arrD );

~~~

##### output

~~~
new id = 99087647783270610
Array
(
    [center] => 0
    [node] => 15
    [time] => 23624336191
    [rand] => 210
)
~~~




### Parse an id for getting the details

~~~
$cDId		= CDId::getInstance();
$arrId		= $cDId->parseId( 98037672957548006 );
print_r( $arrId );

~~~

##### output

~~~
Array
(
{'fraction_non_alphanumeric': 0.1250855968956859, 'fraction_numerical': 0.30198584797991324, 'mean_word_length': 2.5424413904607923, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 116, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1287708', 'n_tokens_mistral': 2694, 'n_tokens_neox': 1484, 'n_words': 504}