github.com/apache/arrow/go/v7@v7.0.1/parquet/internal/utils/_lib/min_max.c (about)

     1  // Licensed to the Apache Software Foundation (ASF) under one
     2  // or more contributor license agreements.  See the NOTICE file
     3  // distributed with this work for additional information
     4  // regarding copyright ownership.  The ASF licenses this file
     5  // to you under the Apache License, Version 2.0 (the
     6  // "License"); you may not use this file except in compliance
     7  // with the License.  You may obtain a copy of the License at
     8  //
     9  // http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  #include "arch.h"
    18  #include <stdint.h>
    19  #include <limits.h>
    20  #include <math.h>
    21  #include <float.h>
    22  
    23  void FULL_NAME(int32_max_min)(int32_t values[], int len, int32_t* minout, int32_t* maxout) {
    24    int32_t max = INT32_MIN;
    25    int32_t min = INT32_MAX;
    26  
    27    for (int i = 0; i < len; ++i) {
    28      min = min < values[i] ? min : values[i];
    29      max = max > values[i] ? max : values[i];
    30    }
    31  
    32    *maxout = max;
    33    *minout = min;
    34  }
    35  
    36  void FULL_NAME(uint32_max_min)(uint32_t values[], int len, uint32_t* minout, uint32_t* maxout) {
    37    uint32_t max = 0;
    38    uint32_t min = UINT32_MAX;
    39  
    40    for (int i = 0; i < len; ++i) {
    41      min = min < values[i] ? min : values[i];
    42      max = max > values[i] ? max : values[i];
    43    }
    44  
    45    *maxout = max;
    46    *minout = min;
    47  }
    48  
    49  void FULL_NAME(int64_max_min)(int64_t values[], int len, int64_t* minout, int64_t* maxout) {
    50    int64_t max = INT64_MIN;
    51    int64_t min = INT64_MAX;
    52  
    53    for (int i = 0; i < len; ++i) {
    54      min = min < values[i] ? min : values[i];
    55      max = max > values[i] ? max : values[i];
    56    }
    57  
    58    *maxout = max;
    59    *minout = min;
    60  }
    61  
    62  void FULL_NAME(uint64_max_min)(uint64_t values[], int len, uint64_t* minout, uint64_t* maxout) {
    63    uint64_t max = 0;
    64    uint64_t min = UINT64_MAX;
    65  
    66    for (int i = 0; i < len; ++i) {
    67      min = min < values[i] ? min : values[i];
    68      max = max > values[i] ? max : values[i];
    69    }
    70  
    71    *maxout = max;
    72    *minout = min;
    73  }