github.com/segmentio/parquet-go@v0.0.0-20230712180008-5d42db8f0d47/page_bounds_purego.go (about)

     1  //go:build purego || !amd64
     2  
     3  package parquet
     4  
     5  import (
     6  	"encoding/binary"
     7  )
     8  
     9  func boundsInt32(data []int32) (min, max int32) {
    10  	if len(data) > 0 {
    11  		min = data[0]
    12  		max = data[0]
    13  
    14  		for _, v := range data[1:] {
    15  			if v < min {
    16  				min = v
    17  			}
    18  			if v > max {
    19  				max = v
    20  			}
    21  		}
    22  	}
    23  	return min, max
    24  }
    25  
    26  func boundsInt64(data []int64) (min, max int64) {
    27  	if len(data) > 0 {
    28  		min = data[0]
    29  		max = data[0]
    30  
    31  		for _, v := range data[1:] {
    32  			if v < min {
    33  				min = v
    34  			}
    35  			if v > max {
    36  				max = v
    37  			}
    38  		}
    39  	}
    40  	return min, max
    41  }
    42  
    43  func boundsUint32(data []uint32) (min, max uint32) {
    44  	if len(data) > 0 {
    45  		min = data[0]
    46  		max = data[0]
    47  
    48  		for _, v := range data[1:] {
    49  			if v < min {
    50  				min = v
    51  			}
    52  			if v > max {
    53  				max = v
    54  			}
    55  		}
    56  	}
    57  	return min, max
    58  }
    59  
    60  func boundsUint64(data []uint64) (min, max uint64) {
    61  	if len(data) > 0 {
    62  		min = data[0]
    63  		max = data[0]
    64  
    65  		for _, v := range data[1:] {
    66  			if v < min {
    67  				min = v
    68  			}
    69  			if v > max {
    70  				max = v
    71  			}
    72  		}
    73  	}
    74  	return min, max
    75  }
    76  
    77  func boundsFloat32(data []float32) (min, max float32) {
    78  	if len(data) > 0 {
    79  		min = data[0]
    80  		max = data[0]
    81  
    82  		for _, v := range data[1:] {
    83  			if v < min {
    84  				min = v
    85  			}
    86  			if v > max {
    87  				max = v
    88  			}
    89  		}
    90  	}
    91  	return min, max
    92  }
    93  
    94  func boundsFloat64(data []float64) (min, max float64) {
    95  	if len(data) > 0 {
    96  		min = data[0]
    97  		max = data[0]
    98  
    99  		for _, v := range data[1:] {
   100  			if v < min {
   101  				min = v
   102  			}
   103  			if v > max {
   104  				max = v
   105  			}
   106  		}
   107  	}
   108  	return min, max
   109  }
   110  
   111  func boundsBE128(data [][16]byte) (min, max []byte) {
   112  	if len(data) > 0 {
   113  		minHi := binary.BigEndian.Uint64(data[0][:8])
   114  		maxHi := minHi
   115  		minIndex := 0
   116  		maxIndex := 0
   117  		for i := 1; i < len(data); i++ {
   118  			hi := binary.BigEndian.Uint64(data[i][:8])
   119  			lo := binary.BigEndian.Uint64(data[i][8:])
   120  			switch {
   121  			case hi < minHi:
   122  				minHi, minIndex = hi, i
   123  			case hi == minHi:
   124  				minLo := binary.BigEndian.Uint64(data[minIndex][8:])
   125  				if lo < minLo {
   126  					minHi, minIndex = hi, i
   127  				}
   128  			}
   129  			switch {
   130  			case hi > maxHi:
   131  				maxHi, maxIndex = hi, i
   132  			case hi == maxHi:
   133  				maxLo := binary.BigEndian.Uint64(data[maxIndex][8:])
   134  				if lo > maxLo {
   135  					maxHi, maxIndex = hi, i
   136  				}
   137  			}
   138  		}
   139  		min = data[minIndex][:]
   140  		max = data[maxIndex][:]
   141  	}
   142  	return min, max
   143  }