| 35 | } |
| 36 | |
| 37 | int |
| 38 | BPlusTree_init(BPlusTree *self, PyObject *args, PyObject *kwds) { |
| 39 | static char *kwlist[] = {"capacity", NULL}; |
| 40 | int capacity = DEFAULT_CAPACITY; |
| 41 | |
| 42 | if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwlist, &capacity)) { |
| 43 | return -1; |
| 44 | } |
| 45 | |
| 46 | if (capacity < MIN_CAPACITY) { |
| 47 | PyErr_Format(PyExc_ValueError, |
| 48 | "capacity must be at least %d, got %d", |
| 49 | MIN_CAPACITY, capacity); |
| 50 | return -1; |
| 51 | } |
| 52 | |
| 53 | self->capacity = capacity; |
| 54 | self->min_keys = capacity / 2; |
| 55 | |
| 56 | /* Create initial root (leaf) */ |
| 57 | self->root = node_create(NODE_LEAF, capacity); |
| 58 | if (!self->root) { |
| 59 | return -1; |
| 60 | } |
| 61 | self->leaves = self->root; |
| 62 | |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | BPlusTree_dealloc(BPlusTree *self) { |
nothing calls this directly
no test coverage detected