Skip to content

Commit 4f609f8

Browse files
committed
implemented BlockIndex.sizeof
1 parent d02268f commit 4f609f8

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/_arraykit.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4812,6 +4812,14 @@ BlockIndex_length(BlockIndexObject *self){
48124812
}
48134813

48144814

4815+
static PyObject *
4816+
BlockIndex_sizeof(BlockIndexObject *self) {
4817+
return PyLong_FromSsize_t(
4818+
Py_TYPE(self)->tp_basicsize
4819+
+ (self->bir_capacity) * sizeof(BlockIndexRecord)
4820+
);
4821+
}
4822+
48154823

48164824
// Given an index, return just the block index.
48174825
static PyObject*
@@ -4864,6 +4872,7 @@ static PyMethodDef BlockIndex_methods[] = {
48644872
{"register", (PyCFunction)BlockIndex_register, METH_O, NULL},
48654873
{"__getstate__", (PyCFunction) BlockIndex_getstate, METH_NOARGS, NULL},
48664874
{"__setstate__", (PyCFunction) BlockIndex_setstate, METH_O, NULL},
4875+
{"__sizeof__", (PyCFunction) BlockIndex_sizeof, METH_NOARGS, NULL},
48674876
{"to_list", (PyCFunction)BlockIndex_to_list, METH_NOARGS, NULL},
48684877
{"to_bytes", (PyCFunction)BlockIndex_to_bytes, METH_NOARGS, NULL},
48694878
{"copy", (PyCFunction)BlockIndex_copy, METH_NOARGS, NULL},

test/test_block_index.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ def test_block_index_copy_b(self) -> None:
141141
del bi2
142142
self.assertEqual(dt2, np.dtype(np.float64))
143143

144+
145+
#---------------------------------------------------------------------------
146+
def test_block_index_sizeof_a(self) -> None:
147+
bi1 = BlockIndex()
148+
so1 = sys.getsizeof(bi1)
149+
bi1.register(np.arange(100).reshape(2,50))
150+
so2 = sys.getsizeof(bi1)
151+
self.assertTrue(so1 < so2)
152+
144153
#---------------------------------------------------------------------------
145154

146155
def test_block_index_len_a(self) -> None:

0 commit comments

Comments
 (0)