github.com/parquet-go/parquet-go@v0.20.0/page_max_purego.go (about)

     1  //go:build purego || !amd64
     2  
     3  package parquet
     4  
     5  import "encoding/binary"
     6  
     7  // -----------------------------------------------------------------------------
     8  // TODO: use generics versions of the these functions to reduce the amount of
     9  // code to maintain when we drop compatilibty with Go version older than 1.18.
    10  // -----------------------------------------------------------------------------
    11  
    12  func maxInt32(data []int32) (max int32) {
    13  	if len(data) > 0 {
    14  		max = data[0]
    15  
    16  		for _, value := range data {
    17  			if value > max {
    18  				max = value
    19  			}
    20  		}
    21  	}
    22  	return max
    23  }
    24  
    25  func maxInt64(data []int64) (max int64) {
    26  	if len(data) > 0 {
    27  		max = data[0]
    28  
    29  		for _, value := range data {
    30  			if value > max {
    31  				max = value
    32  			}
    33  		}
    34  	}
    35  	return max
    36  }
    37  
    38  func maxUint32(data []uint32) (max uint32) {
    39  	if len(data) > 0 {
    40  		max = data[0]
    41  
    42  		for _, value := range data {
    43  			if value > max {
    44  				max = value
    45  			}
    46  		}
    47  	}
    48  	return max
    49  }
    50  
    51  func maxUint64(data []uint64) (max uint64) {
    52  	if len(data) > 0 {
    53  		max = data[0]
    54  
    55  		for _, value := range data {
    56  			if value > max {
    57  				max = value
    58  			}
    59  		}
    60  	}
    61  	return max
    62  }
    63  
    64  func maxFloat32(data []float32) (max float32) {
    65  	if len(data) > 0 {
    66  		max = data[0]
    67  
    68  		for _, value := range data {
    69  			if value > max {
    70  				max = value
    71  			}
    72  		}
    73  	}
    74  	return max
    75  }
    76  
    77  func maxFloat64(data []float64) (max float64) {
    78  	if len(data) > 0 {
    79  		max = data[0]
    80  
    81  		for _, value := range data {
    82  			if value > max {
    83  				max = value
    84  			}
    85  		}
    86  	}
    87  	return max
    88  }
    89  
    90  func maxBE128(data [][16]byte) (min []byte) {
    91  	if len(data) > 0 {
    92  		m := binary.BigEndian.Uint64(data[0][:8])
    93  		j := 0
    94  		for i := 1; i < len(data); i++ {
    95  			x := binary.BigEndian.Uint64(data[i][:8])
    96  			switch {
    97  			case x > m:
    98  				m, j = x, i
    99  			case x == m:
   100  				y := binary.BigEndian.Uint64(data[i][8:])
   101  				n := binary.BigEndian.Uint64(data[j][8:])
   102  				if y > n {
   103  					m, j = x, i
   104  				}
   105  			}
   106  		}
   107  		min = data[j][:]
   108  	}
   109  	return min
   110  }