<commit_before>package util

import "reflect"

// IsNil returns true if the reflect.Value is equivalent to nil.
func IsNil(v reflect.Value) bool {
	if !v.IsValid() || v.Kind().String() == "unsafe.Pointer" {
		return true
	}
	if (v.Kind() == reflect.Interface || v.Kind() == reflect.Ptr) && v.IsNil() {
		return true
	}
	return false
}

// IsNumber returns true if the reflect.Value is a number value.
func IsNumber(v reflect.Value) bool {
	switch v.Kind() {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64:
		return true
	}
	return false
}

// Equal returns true if the two reflect.Values are equal.
func Equal(left, right reflect.Value) bool {
	leftIsNil, rightIsNil := IsNil(left), IsNil(right)
	if leftIsNil && rightIsNil {
		return true
	}
	if (!leftIsNil && rightIsNil) || (leftIsNil && !rightIsNil) {
		return false
	}
	if left.Kind() == reflect.Interface || left.Kind() == reflect.Ptr {
		left = left.Elem()
	}
	if right.Kind() == reflect.Interface || right.Kind() == reflect.Ptr {
		right = right.Elem()
	}
	if !left.IsValid() || !right.IsValid() {
		return true
	}
	if IsNumber(left) && IsNumber(right) {
		if right.Type().ConvertibleTo(left.Type()) {
			right = right.Convert(left.Type())
		}
	}
	if left.CanInterface() && right.CanInterface() {
		return reflect.DeepEqual(left.Interface(), right.Interface())
	}
	return reflect.DeepEqual(left, right)
}<commit_msg>Allow Equal() to work with numbers compared with strings<commit_after>package util

import (
	"reflect"
)

// IsNil returns true if the reflect.Value is equivalent to nil.
func IsNil(v reflect.Value) bool {
	if !v.IsValid() || v.Kind().String() == "unsafe.Pointer" {
		return true
	}
	if (v.Kind() == reflect.Interface || v.Kind() == reflect.Ptr) && v.IsNil() {
		return true
	}
	return false
}

// IsNumber returns true if the reflect.Value is a number value.
func IsNumber(v reflect.Value) bool {
	switch v.Kind() {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64:
		return true
	}
	return false
}

// Equal returns true if the two reflect.Values are equal.
func Equal(left, right reflect.Value) bool {
	leftIsNil, rightIsNil := IsNil(left), IsNil(right)
	if leftIsNil && rightIsNil {
		return true
	}
	if (!leftIsNil && rightIsNil) || (leftIsNil && !rightIsNil) {
		return false
	}
	if left.Kind() == reflect.Interface || left.Kind() == reflect.Ptr {
		left = left.Elem()
	}
	if right.Kind() == reflect.Interface || right.Kind() == reflect.Ptr {
		right = right.Elem()
	}
	if !left.IsValid() || !right.IsValid() {
		return true
	}
	leftNum := IsNumber(left)
	rightNum := IsNumber(right)
	if leftNum && rightNum {
		if right.Type().ConvertibleTo(left.Type()) {
			right = right.Convert(left.Type())
		}
	}
	if leftNum && !rightNum && right.Kind() == reflect.String {
		if rv, err := StrToInt64(right.String()); err == nil {
			right = reflect.ValueOf(rv)
			if right.Type().ConvertibleTo(left.Type()) {
				right = right.Convert(left.Type())
			}
		}
	}
	if rightNum && !leftNum && left.Kind() == reflect.String {
		if lv, err := StrToInt64(left.String()); err == nil {
			left = reflect.ValueOf(lv)
			if left.Type().ConvertibleTo(right.Type()) {
				left = left.Convert(right.Type())
			}
		}
	}
	if left.CanInterface() && right.CanInterface() {
		return reflect.DeepEqual(left.Interface(), right.Interface())
	}
	return reflect.DeepEqual(left, right)
}
{'fraction_non_alphanumeric': 0.1568842567196928, 'fraction_numerical': 0.010970927043335162, 'mean_word_length': 3.9417344173441733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4762986', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1232, 'n_words': 312}