<commit_before>package piet

import "fmt"

type Point struct {
  x int
  y int
}

func AddPoints(a, b Point) Point { return Point{a.x+b.x, a.y+b.y} }

func (p Point) Equal(q Point) bool { return p.x == q.x && p.y == q.y }

func (p Point) ToString() string { return fmt.Sprintf("(%d, %d)", p.x, p.y) }

func Lesser(p, q Point, b bool) bool {
  if b { // compare x
    return p.x < q.x
  } else {
    return p.y < q.y
  }
}

func SortPointSlice(ps []Point, target, reverse bool) []Point {
  for i := 0; i < len(ps); i++ {
    for j := 1; j < len(ps)-i; j++ {
      if reverse {
        if Lesser(ps[j-1], ps[j], target) {
          ps[j], ps[j-1] = ps[j-1], ps[j]
        }
      } else {
        if Lesser(ps[j], ps[j-1], target) {
          ps[j], ps[j-1] = ps[j-1], ps[j]
        }
      }
    }
  }
  return ps
}<commit_msg>implement quick sort<commit_after>package piet

import "fmt"

type Point struct {
  x int
  y int
}

func AddPoints(a, b Point) Point { return Point{a.x+b.x, a.y+b.y} }

func (p Point) Equal(q Point) bool { return p.x == q.x && p.y == q.y }

func (p Point) ToString() string { return fmt.Sprintf("(%d, %d)", p.x, p.y) }

func Lesser(p, q Point, b, reverse bool) bool {
  if b { // compare x
    if reverse {
      return p.x >= q.x
    } else {
      return p.x < q.x
    }
  } else {
    if reverse {
      return p.y >= q.y
    } else {
      return p.y < q.y
    }
  }
}
/*
func SortPointSlice(ps []Point, target, reverse bool) []Point {
  for i := 1; i < len(ps); i++ {
    tmp := ps[i]
    if Lesser(tmp, ps[i-1], target, reverse) {
      ps[i] = ps[i-1]
      var j int
      for j = i-1; j > 0 && Lesser(tmp, ps[j-1], target, reverse); j-- {
        ps[j] = ps[j-1]
      }
      ps[j] = tmp
    }
  }
  return ps
}*/

func SortPointSlice(ps []Point, target, reverse bool) []Point {
  if len(ps) <= 1 {
    return ps
  }
  var left = []Point{}
  var right = []Point{}
  x := ps[0]
  for _, d := range ps[1:] {
    if Lesser(d, x, target, reverse) {
      left = append(left, d)
    } else {
      right = append(right, d)
    }
  }
  return append(SortPointSlice(left, target, reverse), append([]Point{x}, SortPointSlice(right, target, reverse)...)...)
}
{'fraction_non_alphanumeric': 0.18472793781435756, 'fraction_numerical': 0.00823045267489712, 'mean_word_length': 2.148201438848921, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1730190', 'n_tokens_mistral': 888, 'n_tokens_neox': 879, 'n_words': 256}