<commit_before>package integer

import "sort"

type convexHullSortByPolarAngle SliceTuple

func (spa convexHullSortByPolarAngle) Less(i, j int) bool {
	i++
	j++
	return SliceTuple(spa).PointsCCW(0, i, j) > 0
}
func (spa convexHullSortByPolarAngle) Swap(i, j int) {
	i++
	j++
	spa[i], spa[j] = spa[j], spa[i]
}
func (spa convexHullSortByPolarAngle) Len() int { return len(spa) - 1 }

func (st SliceTuple) PointsCCW(i, j, k int) int {
	// (j.x - i.x)*(k.y - i.y) - (j.y - i.y)*(k.x - i.x)
	return (((*st[j])[0]-(*st[i])[0])*((*st[k])[1]-(*st[i])[1]) - ((*st[j])[1]-(*st[i])[1])*((*st[k])[0]-(*st[i])[0]))
}

func (st SliceTuple) PointsDistance2(i, j int) int {
	dx := ((*st[j])[0] - (*st[i])[0])
	dy := ((*st[j])[1] - (*st[i])[1])
	return dx*dx + dy*dy
}

func (st SliceTuple) convexHullLowestY() int {
	mini := 0
	miny := (*st[0])[1]
	minx := (*st[0])[0]
	for i := 1; i < len(st); i++ {
		y := (*st[i])[1]
		x := (*st[i])[0]
		if y < miny {
			mini = i
			miny = y
			minx = x
			continue
		}
		if y == miny && x < minx {
			mini = i
			miny = y
			minx = x
		}
	}
	return mini
}

func (st SliceTuple) ConvexHull() int {
	if len(st) <= 3 {
		return len(st)
	}

	st.Swap(0, st.convexHullLowestY())

	sort.Sort(convexHullSortByPolarAngle(st))

	M := 1
	for i := 2; i < len(st); i++ {
		for st.PointsCCW(M-1, M, i) < 0 {
			M--
		}

		M++
		st.Swap(M, i)

		if st.PointsCCW(M-2, M-1, M) == 0 {
			if st.PointsDistance2(M-2, M) > st.PointsDistance2(M-2, M-1) {
				st.Swap(M, M-1)
			}
			M--
		}
	}
	return M + 1
}<commit_msg>Fixed problems<commit_after>package integer

import "sort"

type convexHullSortByPolarAngle SliceTuple

func (spa convexHullSortByPolarAngle) Less(i, j int) bool {
	i++
	j++
	ccw := SliceTuple(spa).PointsCCW(0, i, j)
	if ccw != 0 {
		return ccw > 0
	}

	// sort collinears from furthest away to nearest
	dx := Abs((*spa[j])[0]-(*spa[0])[0]) - Abs((*spa[i])[0]-(*spa[0])[0])
	if dx != 0 {
		return dx < 0
	}

	return ((*spa[j])[1]-(*spa[0])[1])-((*spa[i])[1]-(*spa[0])[1]) < 0
}
func (spa convexHullSortByPolarAngle) Swap(i, j int) {
	i++
	j++
	spa[i], spa[j] = spa[j], spa[i]
}
func (spa convexHullSortByPolarAngle) Len() int { return len(spa) - 1 }

func (st SliceTuple) PointsCCW(i, j, k int) int {
	// (j.x - i.x)*(k.y - i.y) - (j.y - i.y)*(k.x - i.x)
	return (((*st[j])[0]-(*st[i])[0])*((*st[k])[1]-(*st[i])[1]) - ((*st[j])[1]-(*st[i])[1])*((*st[k])[0]-(*st[i])[0]))
}

func (st SliceTuple) PointsDistance2(i, j int) int {
	dx := ((*st[j])[0] - (*st[i])[0])
	dy := ((*st[j])[1] - (*st[i])[1])
	return dx*dx + dy*dy
}

func (st SliceTuple) convexHullLowestY() int {
	mini := 0
	miny := (*st[0])[1]
	minx := (*st[0])[0]
	for i := 1; i < len(st); i++ {
		y := (*st[i])[1]
		x := (*st[i])[0]
		if y < miny {
			mini = i
			miny = y
			minx = x
			continue
		}
		if y == miny && x < minx {
			mini = i
			miny = y
			minx = x
		}
	}
	return mini
}

func (st SliceTuple) ConvexHull() int {
	if len(st) <= 2 {
		return len(st)
	}

	st.Swap(0, st.convexHullLowestY())

	sort.Sort(convexHullSortByPolarAngle(st))

	M := 1
	i := 2
	end := len(st)

	// skip beginning collinears
	for st.PointsCCW(M-1, M, i) == 0 {
		i++
		if i == end {
			return 2
		}
	}

	// skip ending collinears
	for st.PointsCCW(0, end-1, end-2) == 0 {
		end--
	}

	for ; i < end; i++ {
		for st.PointsCCW(M-1, M, i) <= 0 {
			M--
		}

		M++
		st.Swap(M, i)
	}
	return M + 1
}
{'fraction_non_alphanumeric': 0.24613555291319858, 'fraction_numerical': 0.02794292508917955, 'mean_word_length': 3.029940119760479, 'pattern_counts': {'":': 0, '<': 17, '<?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': '7181749', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1689, 'n_words': 365}