Create a new node */
| 90 | |
| 91 | /* Create a new node */ |
| 92 | BPlusNode* node_create(NodeType type, uint16_t capacity) { |
| 93 | size_t data_size; |
| 94 | |
| 95 | if (type == NODE_LEAF) { |
| 96 | data_size = capacity * 2 * sizeof(PyObject*); |
| 97 | } else { |
| 98 | data_size = (capacity * 2 + 1) * sizeof(PyObject*); |
| 99 | } |
| 100 | |
| 101 | BPlusNode *node = (BPlusNode*)cache_aligned_alloc(sizeof(BPlusNode) + data_size); |
| 102 | if (!node) { |
| 103 | PyErr_NoMemory(); |
| 104 | return NULL; |
| 105 | } |
| 106 | |
| 107 | /* Initialize metadata */ |
| 108 | node->num_keys = 0; |
| 109 | node->capacity = capacity; |
| 110 | node->type = type; |
| 111 | node->_unused = 0; /* Reserved for future use */ |
| 112 | node->next = NULL; |
| 113 | |
| 114 | /* Clear data array */ |
| 115 | memset(node->data, 0, data_size); |
| 116 | |
| 117 | return node; |
| 118 | } |
| 119 | |
| 120 | /* Destroy a node and decref all Python objects */ |
| 121 | void node_destroy(BPlusNode *node) { |
no test coverage detected