Skip to content

Commit 8631aa6

Browse files
committed
Add docs with signatures to SonyFlake and MachineIDLCG
1 parent 48809fc commit 8631aa6

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

sonyflake_turbo.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,21 @@ static PyObject *sonyflake_next(struct sonyflake_state *self) {
271271
return PyLong_FromUnsignedLongLong(sonyflake_id);
272272
}
273273

274+
PyDoc_STRVAR(sonyflake_doc,
275+
"SonyFlake(*machine_id, start_time=None)\n--\n\n"
276+
"SonyFlake ID generator implementation that combines multiple ID generators into one to improve throughput.\n"
277+
"Upon counter overflow, it switches to the next machine ID and sleeps only when all machine ids are exhausted for time"
278+
"frame of 10ms. This produces always-increasing id sequence.\n"
279+
);
280+
274281
static PyType_Slot sonyflake_type_slots[] = {
275282
{Py_tp_alloc, PyType_GenericAlloc},
276283
{Py_tp_dealloc, sonyflake_dealloc},
277284
{Py_tp_iter, PyObject_SelfIter},
278285
{Py_tp_iternext, sonyflake_next},
279286
{Py_tp_new, sonyflake_new},
280287
{Py_tp_init, sonyflake_init},
288+
{Py_tp_doc, sonyflake_doc},
281289
{0, 0},
282290
};
283291

@@ -349,13 +357,20 @@ static PyObject *machine_id_lcg_next(struct machine_id_lcg_state *self) {
349357
return PyLong_FromLong(machine_id_lcg_atomic(&self->machine_id));
350358
}
351359

360+
PyDoc_STRVAR(machine_id_lcg_doc,
361+
"MachineIDLCG(seed, /)\n--\n\n"
362+
"LCG with params a=32309, c=13799, m=65536.\n"
363+
"Provides a thread-safe way to generate pseudo-random sequence of machine ids to be used as args to SonyFlake.\n"
364+
);
365+
366+
352367
static PyType_Slot machine_id_lcg_slots[] = {
353368
{Py_tp_alloc, PyType_GenericAlloc},
354369
{Py_tp_dealloc, machine_id_lcg_dealloc},
355370
{Py_tp_iter, PyObject_SelfIter},
356371
{Py_tp_iternext, machine_id_lcg_next},
357372
{Py_tp_new, machine_id_lcg_new},
358-
{Py_tp_doc, "LCG with params a=32309, c=13799, m=65536"},
373+
{Py_tp_doc, machine_id_lcg_doc},
359374
{0, 0},
360375
};
361376

0 commit comments

Comments
 (0)