chromium/third_party/grpc/src/src/core/lib/gpr/useful.h

//
//
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//

#ifndef GRPC_SRC_CORE_LIB_GPR_USEFUL_H
#define GRPC_SRC_CORE_LIB_GPR_USEFUL_H

#include <grpc/support/port_platform.h>

#include <cstddef>

#include "absl/strings/string_view.h"
#include "absl/types/variant.h"

/// useful utilities that don't belong anywhere else

namespace grpc_core {

template <typename T>
T Clamp(T val, T min, T max) {}

/// rotl, rotr assume x is unsigned
template <typename T>
constexpr T RotateLeft(T x, T n) {}
template <typename T>
constexpr T RotateRight(T x, T n) {}

// Set the n-th bit of i
template <typename T>
T SetBit(T* i, size_t n) {}

// Clear the n-th bit of i
template <typename T>
T ClearBit(T* i, size_t n) {}

// Get the n-th bit of i
template <typename T>
bool GetBit(T i, size_t n) {}

namespace useful_detail {
inline constexpr uint32_t HexdigitBitcount(uint32_t x) {}
}  // namespace useful_detail

inline constexpr uint32_t BitCount(uint32_t i) {}

inline constexpr uint32_t BitCount(uint64_t i) {}

inline constexpr uint32_t BitCount(uint16_t i) {}
inline constexpr uint32_t BitCount(uint8_t i) {}
inline constexpr uint32_t BitCount(int64_t i) {}
inline constexpr uint32_t BitCount(int32_t i) {}
inline constexpr uint32_t BitCount(int16_t i) {}
inline constexpr uint32_t BitCount(int8_t i) {}

// This function uses operator< to implement a qsort-style comparison, whereby:
// if a is smaller than b, a number smaller than 0 is returned.
// if a is bigger than b, a number greater than 0 is returned.
// if a is neither smaller nor bigger than b, 0 is returned.
template <typename T>
int QsortCompare(const T& a, const T& b) {}

template <typename... X>
int QsortCompare(const absl::variant<X...>& a, const absl::variant<X...>& b) {}

inline int QsortCompare(absl::string_view a, absl::string_view b) {}

inline int QsortCompare(const std::string& a, const std::string& b) {}

template <typename A, typename B>
int QsortCompare(const std::pair<A, B>& a, const std::pair<A, B>& b) {}

template <typename T>
constexpr size_t HashPointer(T* p, size_t range) {}

// Compute a+b.
// If the result is greater than INT64_MAX, return INT64_MAX.
// If the result is less than INT64_MIN, return INT64_MIN.
inline int64_t SaturatingAdd(int64_t a, int64_t b) {}

inline uint32_t MixHash32(uint32_t a, uint32_t b) {}

inline uint32_t RoundUpToPowerOf2(uint32_t v) {}

}  // namespace grpc_core

#define GPR_ARRAY_SIZE(array)

#endif  // GRPC_SRC_CORE_LIB_GPR_USEFUL_H