Commit 99bf9a25 authored by Raymond Hettinger's avatar Raymond Hettinger

Minor code cleanups.

parent 21ee10bf
...@@ -138,7 +138,7 @@ heappop_internal(PyObject *heap, int siftup_func(PyListObject *, Py_ssize_t)) ...@@ -138,7 +138,7 @@ heappop_internal(PyObject *heap, int siftup_func(PyListObject *, Py_ssize_t))
lastelt = PyList_GET_ITEM(heap, n-1) ; lastelt = PyList_GET_ITEM(heap, n-1) ;
Py_INCREF(lastelt); Py_INCREF(lastelt);
if (PyList_SetSlice(heap, n-1, n, NULL) < 0) { if (PyList_SetSlice(heap, n-1, n, NULL)) {
Py_DECREF(lastelt); Py_DECREF(lastelt);
return NULL; return NULL;
} }
...@@ -177,7 +177,7 @@ heapreplace_internal(PyObject *args, int siftup_func(PyListObject *, Py_ssize_t) ...@@ -177,7 +177,7 @@ heapreplace_internal(PyObject *args, int siftup_func(PyListObject *, Py_ssize_t)
return NULL; return NULL;
} }
if (PyList_GET_SIZE(heap) < 1) { if (PyList_GET_SIZE(heap) == 0) {
PyErr_SetString(PyExc_IndexError, "index out of range"); PyErr_SetString(PyExc_IndexError, "index out of range");
return NULL; return NULL;
} }
...@@ -222,7 +222,7 @@ heappushpop(PyObject *self, PyObject *args) ...@@ -222,7 +222,7 @@ heappushpop(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
if (PyList_GET_SIZE(heap) < 1) { if (PyList_GET_SIZE(heap) == 0) {
Py_INCREF(item); Py_INCREF(item);
return item; return item;
} }
...@@ -340,8 +340,8 @@ heapify_internal(PyObject *heap, int siftup_func(PyListObject *, Py_ssize_t)) ...@@ -340,8 +340,8 @@ heapify_internal(PyObject *heap, int siftup_func(PyListObject *, Py_ssize_t))
n is odd = 2*j+1, this is (2*j+1-1)/2 = j so j-1 is the largest, n is odd = 2*j+1, this is (2*j+1-1)/2 = j so j-1 is the largest,
and that's again n//2-1. and that's again n//2-1.
*/ */
for (i=n/2-1 ; i>=0 ; i--) for (i = n/2 - 1 ; i >= 0 ; i--)
if(siftup_func((PyListObject *)heap, i)) if (siftup_func((PyListObject *)heap, i))
return NULL; return NULL;
Py_RETURN_NONE; Py_RETURN_NONE;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment