Bouncer / bouncer / linear_sketches / headers / LinearSketch.h
LinearSketch.h
Raw
#ifndef LINEAR_SKETCH_H
#define LINEAR_SKETCH_H

/*******************************************************/
/*    Base Linear sketch declarations                  */
/*******************************************************/
typedef struct {
    PyObject_HEAD
    byte epsilon : 7; 
    byte delta : 7; 
} LinearSketch;

static void LinearSketch_dealloc(LinearSketch*); 
static PyObject *LinearSketch_new(PyTypeObject*, PyObject *, PyObject *);
static int LinearSketch_init(LinearSketch *, PyObject *, PyObject *);
static PyObject*get_delta(LinearSketch* , void* );
static PyObject*get_epsilon(LinearSketch* , void* );

static PyObject*
get_epsilon(LinearSketch* self, void* closure)
{
    return PyFloat_FromDouble( byte_to_float(self->epsilon) );
}

static PyObject*
get_delta(LinearSketch* self, void* closure)
{
    return PyFloat_FromDouble(byte_to_float(self->delta) );

}


PyGetSetDef get_LinearSketch_sets[] = {
     {"epsilon",  /* name */
     (getter) get_epsilon,
     NULL,
     NULL,  /* doc */
     NULL /* closure */},
     {"delta",  /* name */
     (getter) get_delta,
     NULL,
     NULL,  /* doc */
     NULL /* closure */},
    {NULL}
};

static PyTypeObject LinearSketch_type = {
    PyVarObject_HEAD_INIT(NULL, 0)
    .tp_name = "sketches.LinearSketch",
    .tp_doc = "Linear Sketch class",
    .tp_basicsize = sizeof(LinearSketch),
    .tp_itemsize = 0,
    .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
    .tp_new = LinearSketch_new,
    .tp_init = (initproc)LinearSketch_init,
    .tp_dealloc = (destructor)LinearSketch_dealloc,
    .tp_getset = get_LinearSketch_sets,
};

#endif //LINEAR_SKETCH_H