Skip to content

Instantly share code, notes, and snippets.

@naftaliharris
Last active December 28, 2015 01:39
Show Gist options
  • Select an option

  • Save naftaliharris/7422389 to your computer and use it in GitHub Desktop.

Select an option

Save naftaliharris/7422389 to your computer and use it in GitHub Desktop.

Revisions

  1. naftaliharris revised this gist Nov 14, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion partition.c
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ int partition(LSObject *ls, int left, int right) {

    for (int i = left + 1; i < right; i++) {
    __builtin_prefetch(ob_item[i+3]); /* This is the added line */
    IFLT(ob_item[i], pivot) {
    IF_LESS_THAN(ob_item[i], pivot) {
    last_less++;
    SWAP(i, last_less);
    }
  2. naftaliharris revised this gist Nov 14, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion partition.c
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    /* Modified slightly from https://github.com/naftaliharris/lazysort */
    int partition(LSObject *ls, int left, int right) {
    PyObject **ob_item = ls->xs->ob_item;
    PyObject **ob_item = ls->xs->ob_item; /* The array to be sorted */
    int piv_idx = pick_pivot(ls, left, right);
    PyObject *pivot = ob_item[piv_idx];

  3. naftaliharris renamed this gist Nov 14, 2013. 1 changed file with 4 additions and 6 deletions.
    10 changes: 4 additions & 6 deletions gistfile1.c → partition.c
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,16 @@
    /* Modified slightly from https://github.com/naftaliharris/lazysort */
    static Py_ssize_t
    partition(LSObject *ls, Py_ssize_t left, Py_ssize_t right)
    {
    int partition(LSObject *ls, int left, int right) {
    PyObject **ob_item = ls->xs->ob_item;
    Py_ssize_t piv_idx = pick_pivot(ls, left, right);
    int piv_idx = pick_pivot(ls, left, right);
    PyObject *pivot = ob_item[piv_idx];

    SWAP(left, piv_idx);
    Py_ssize_t last_less = left;
    int last_less = left;

    /* Invariant: last_less and everything to its left is less than
    * pivot or the pivot itself */

    for (Py_ssize_t i = left + 1; i < right; i++) {
    for (int i = left + 1; i < right; i++) {
    __builtin_prefetch(ob_item[i+3]); /* This is the added line */
    IFLT(ob_item[i], pivot) {
    last_less++;
  4. naftaliharris revised this gist Nov 14, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.c
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    /* Modified slightly from https://github.com/naftaliharris/lazysort */
    static Py_ssize_t
    partition(LSObject *ls, Py_ssize_t left, Py_ssize_t right)
    {
  5. naftaliharris revised this gist Nov 14, 2013. 1 changed file with 2 additions and 14 deletions.
    16 changes: 2 additions & 14 deletions gistfile1.c
    Original file line number Diff line number Diff line change
    @@ -2,25 +2,16 @@ static Py_ssize_t
    partition(LSObject *ls, Py_ssize_t left, Py_ssize_t right)
    {
    PyObject **ob_item = ls->xs->ob_item;

    PyObject *tmp; /* Used by SWAP macro */
    PyObject *pivot;
    int ltflag;

    Py_ssize_t piv_idx = pick_pivot(ls, left, right);
    if (piv_idx < 0) {
    return -1;
    }
    pivot = ob_item[piv_idx];
    PyObject *pivot = ob_item[piv_idx];

    SWAP(left, piv_idx);
    Py_ssize_t last_less = left;

    /* Invariant: last_less and everything to its left is less than
    * pivot or the pivot itself */

    Py_ssize_t i;
    for (i = left + 1; i < right; i++) {
    for (Py_ssize_t i = left + 1; i < right; i++) {
    __builtin_prefetch(ob_item[i+3]); /* This is the added line */
    IFLT(ob_item[i], pivot) {
    last_less++;
    @@ -30,7 +21,4 @@ partition(LSObject *ls, Py_ssize_t left, Py_ssize_t right)

    SWAP(left, last_less);
    return last_less;

    fail: /* From IFLT macro */
    return -1;
    }
  6. naftaliharris created this gist Nov 11, 2013.
    36 changes: 36 additions & 0 deletions gistfile1.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    static Py_ssize_t
    partition(LSObject *ls, Py_ssize_t left, Py_ssize_t right)
    {
    PyObject **ob_item = ls->xs->ob_item;

    PyObject *tmp; /* Used by SWAP macro */
    PyObject *pivot;
    int ltflag;

    Py_ssize_t piv_idx = pick_pivot(ls, left, right);
    if (piv_idx < 0) {
    return -1;
    }
    pivot = ob_item[piv_idx];

    SWAP(left, piv_idx);
    Py_ssize_t last_less = left;

    /* Invariant: last_less and everything to its left is less than
    * pivot or the pivot itself */

    Py_ssize_t i;
    for (i = left + 1; i < right; i++) {
    __builtin_prefetch(ob_item[i+3]); /* This is the added line */
    IFLT(ob_item[i], pivot) {
    last_less++;
    SWAP(i, last_less);
    }
    }

    SWAP(left, last_less);
    return last_less;

    fail: /* From IFLT macro */
    return -1;
    }