Skip to content

Commit 303d78b

Browse files
authored
CLN: Hashtable rename struct members (#57704)
Hashtable rename struct members
1 parent 0f7ded2 commit 303d78b

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

Diff for: pandas/_libs/hashtable.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ cdef class StringHashTable(HashTable):
174174

175175
cdef struct Int64VectorData:
176176
int64_t *data
177-
Py_ssize_t n, m
177+
Py_ssize_t size, capacity
178178

179179
cdef class Vector:
180180
cdef bint external_view_exists

Diff for: pandas/_libs/hashtable_class_helper.pxi.in

+37-37
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ dtypes = [('Complex128', 'complex128', 'khcomplex128_t'),
133133

134134
ctypedef struct {{name}}VectorData:
135135
{{c_type}} *data
136-
Py_ssize_t n, m
136+
Py_ssize_t size, capacity
137137

138138
{{endif}}
139139

@@ -143,8 +143,8 @@ ctypedef struct {{name}}VectorData:
143143
cdef void append_data_{{dtype}}({{name}}VectorData *data,
144144
{{c_type}} x) noexcept nogil:
145145

146-
data.data[data.n] = x
147-
data.n += 1
146+
data.data[data.size] = x
147+
data.size += 1
148148

149149
{{endfor}}
150150

@@ -164,7 +164,7 @@ ctypedef fused vector_data:
164164
StringVectorData
165165

166166
cdef bint needs_resize(vector_data *data) noexcept nogil:
167-
return data.n == data.m
167+
return data.size == data.capacity
168168

169169
# ----------------------------------------------------------------------
170170
# Vector
@@ -209,26 +209,26 @@ cdef class {{name}}Vector(Vector):
209209
{{endif}}
210210

211211
def __cinit__(self):
212-
self.data.n = 0
213-
self.data.m = _INIT_VEC_CAP
214-
self.ao = np.empty(self.data.m, dtype=np.{{dtype}})
212+
self.data.size = 0
213+
self.data.capacity = _INIT_VEC_CAP
214+
self.ao = np.empty(self.data.capacity, dtype=np.{{dtype}})
215215
self.data.data = <{{c_type}}*>self.ao.data
216216

217217
cdef resize(self):
218-
self.data.m = max(self.data.m * 4, _INIT_VEC_CAP)
219-
self.ao.resize(self.data.m, refcheck=False)
218+
self.data.capacity = max(self.data.capacity * 4, _INIT_VEC_CAP)
219+
self.ao.resize(self.data.capacity, refcheck=False)
220220
self.data.data = <{{c_type}}*>self.ao.data
221221

222222
def __len__(self) -> int:
223-
return self.data.n
223+
return self.data.size
224224

225225
cpdef ndarray to_array(self):
226-
if self.data.m != self.data.n:
226+
if self.data.capacity != self.data.size:
227227
if self.external_view_exists:
228228
# should never happen
229229
raise ValueError("should have raised on append()")
230-
self.ao.resize(self.data.n, refcheck=False)
231-
self.data.m = self.data.n
230+
self.ao.resize(self.data.size, refcheck=False)
231+
self.data.capacity = self.data.size
232232
self.external_view_exists = True
233233
return self.ao
234234

@@ -254,45 +254,45 @@ cdef class StringVector(Vector):
254254
StringVectorData data
255255

256256
def __cinit__(self):
257-
self.data.n = 0
258-
self.data.m = _INIT_VEC_CAP
259-
self.data.data = <char **>malloc(self.data.m * sizeof(char *))
257+
self.data.size = 0
258+
self.data.capacity = _INIT_VEC_CAP
259+
self.data.data = <char **>malloc(self.data.capacity * sizeof(char *))
260260
if self.data.data is NULL:
261261
raise MemoryError()
262262

263263
cdef resize(self):
264264
cdef:
265265
char **orig_data
266-
Py_ssize_t i, m
266+
Py_ssize_t i, orig_capacity
267267

268-
m = self.data.m
269-
self.data.m = max(self.data.m * 4, _INIT_VEC_CAP)
268+
orig_capacity = self.data.capacity
269+
self.data.capacity = max(self.data.capacity * 4, _INIT_VEC_CAP)
270270

271271
orig_data = self.data.data
272-
self.data.data = <char **>malloc(self.data.m * sizeof(char *))
272+
self.data.data = <char **>malloc(self.data.capacity * sizeof(char *))
273273
if self.data.data is NULL:
274274
raise MemoryError()
275-
for i in range(m):
275+
for i in range(orig_capacity):
276276
self.data.data[i] = orig_data[i]
277277

278278
def __dealloc__(self):
279279
free(self.data.data)
280280

281281
def __len__(self) -> int:
282-
return self.data.n
282+
return self.data.size
283283

284284
cpdef ndarray[object, ndim=1] to_array(self):
285285
cdef:
286286
ndarray ao
287287
Py_ssize_t n
288288
object val
289289

290-
ao = np.empty(self.data.n, dtype=object)
291-
for i in range(self.data.n):
290+
ao = np.empty(self.data.size, dtype=object)
291+
for i in range(self.data.size):
292292
val = self.data.data[i]
293293
ao[i] = val
294294
self.external_view_exists = True
295-
self.data.m = self.data.n
295+
self.data.capacity = self.data.size
296296
return ao
297297

298298
cdef void append(self, char *x) noexcept:
@@ -311,37 +311,37 @@ cdef class ObjectVector(Vector):
311311

312312
cdef:
313313
PyObject **data
314-
Py_ssize_t n, m
314+
Py_ssize_t size, capacity
315315
ndarray ao
316316

317317
def __cinit__(self):
318-
self.n = 0
319-
self.m = _INIT_VEC_CAP
318+
self.size = 0
319+
self.capacity = _INIT_VEC_CAP
320320
self.ao = np.empty(_INIT_VEC_CAP, dtype=object)
321321
self.data = <PyObject**>self.ao.data
322322

323323
def __len__(self) -> int:
324-
return self.n
324+
return self.size
325325

326326
cdef append(self, object obj):
327-
if self.n == self.m:
327+
if self.size == self.capacity:
328328
if self.external_view_exists:
329329
raise ValueError("external reference but "
330330
"Vector.resize() needed")
331-
self.m = max(self.m * 2, _INIT_VEC_CAP)
332-
self.ao.resize(self.m, refcheck=False)
331+
self.capacity = max(self.capacity * 2, _INIT_VEC_CAP)
332+
self.ao.resize(self.capacity, refcheck=False)
333333
self.data = <PyObject**>self.ao.data
334334

335335
Py_INCREF(obj)
336-
self.data[self.n] = <PyObject*>obj
337-
self.n += 1
336+
self.data[self.size] = <PyObject*>obj
337+
self.size += 1
338338

339339
cpdef ndarray[object, ndim=1] to_array(self):
340-
if self.m != self.n:
340+
if self.capacity != self.size:
341341
if self.external_view_exists:
342342
raise ValueError("should have raised on append()")
343-
self.ao.resize(self.n, refcheck=False)
344-
self.m = self.n
343+
self.ao.resize(self.size, refcheck=False)
344+
self.capacity = self.size
345345
self.external_view_exists = True
346346
return self.ao
347347

Diff for: pandas/_libs/intervaltree.pxi.in

+5-5
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ cdef class IntervalTree(IntervalMixin):
145145
# overflow -> no match, which is already handled below
146146
pass
147147

148-
if result.data.n == old_len:
148+
if result.data.size == old_len:
149149
result.append(-1)
150-
elif result.data.n > old_len + 1:
150+
elif result.data.size > old_len + 1:
151151
raise KeyError(
152152
'indexer does not intersect a unique set of intervals')
153-
old_len = result.data.n
153+
old_len = result.data.size
154154
return result.to_array().astype('intp')
155155

156156
def get_indexer_non_unique(self, ndarray[scalar_t, ndim=1] target):
@@ -172,10 +172,10 @@ cdef class IntervalTree(IntervalMixin):
172172
# overflow -> no match, which is already handled below
173173
pass
174174

175-
if result.data.n == old_len:
175+
if result.data.size == old_len:
176176
result.append(-1)
177177
missing.append(i)
178-
old_len = result.data.n
178+
old_len = result.data.size
179179
return (result.to_array().astype('intp'),
180180
missing.to_array().astype('intp'))
181181

0 commit comments

Comments
 (0)