Skip to content

Instantly share code, notes, and snippets.

@mallyvai
Created November 27, 2010 07:04
Show Gist options
  • Save mallyvai/717664 to your computer and use it in GitHub Desktop.
Save mallyvai/717664 to your computer and use it in GitHub Desktop.
Python List implementation and notable functions
"""
py_list_notes.txt
Created by Vaibhav Mallya on 2010-11-26.
Copyright (c) 2010 Vaibhav Mallya. All rights reserved, to this version, and all previous versions, of this file.
"""
http://svn.python.org/projects/python/trunk/Objects/listobject.c
Function: static PyObject * list_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
Notable portion:
for (i = 0; i < len; i++) {
PyObject *v = src[i];
Py_INCREF(v);
dest[i] = v;
}
Estimated complexity:
O(n)
Function: static PyObject * list_concat(PyListObject *a, PyObject *bb)
Notable portion:
for (i = 0; i < Py_SIZE(a); i++) {
PyObject *v = src[i];
Py_INCREF(v);
dest[i] = v;
}
src = b->ob_item;
dest = np->ob_item + Py_SIZE(a);
for (i = 0; i < Py_SIZE(b); i++) {
PyObject *v = src[i];
Py_INCREF(v);
dest[i] = v;
}
Estimated Complexity:
O(len(a)) + O(len(b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment