Skip to content

Commit

Permalink
Minor improvements to docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou committed Aug 17, 2022
1 parent 21fc1c4 commit 3c173b5
Showing 1 changed file with 86 additions and 71 deletions.
157 changes: 86 additions & 71 deletions cpp/src/arrow/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ static inline bool is_floating(Type::type type_id) {
/// \brief Check for a numeric type
///
/// This predicate doesn't match decimals (see `is_decimal`).
///
/// \param[in] type_id the type-id to check
/// \return whether type-id is a numeric type one
static inline bool is_numeric(Type::type type_id) {
Expand Down Expand Up @@ -961,6 +962,7 @@ static inline bool is_decimal(Type::type type_id) {
/// \brief Check for a primitive type
///
/// This predicate doesn't match null, decimals and binary-like types.
///
/// \param[in] type_id the type-id to check
/// \return whether type-id is a primitive type one
static inline bool is_primitive(Type::type type_id) {
Expand Down Expand Up @@ -995,7 +997,9 @@ static inline bool is_primitive(Type::type type_id) {

/// \brief Check for a base-binary-like type
///
/// This predicate doesn't match fixed-size binary types.
/// This predicate doesn't match fixed-size binary types and will otherwise
/// match all binary- and string-like types regardless of offset width.
///
/// \param[in] type_id the type-id to check
/// \return whether type-id is a base-binary-like type one
static inline bool is_base_binary_like(Type::type type_id) {
Expand All @@ -1011,7 +1015,7 @@ static inline bool is_base_binary_like(Type::type type_id) {
return false;
}

/// \brief Check for a binary-like type
/// \brief Check for a binary-like type (i.e. with 32-bit offsets)
///
/// \param[in] type_id the type-id to check
/// \return whether type-id is a binary-like type one
Expand All @@ -1026,7 +1030,7 @@ static inline bool is_binary_like(Type::type type_id) {
return false;
}

/// \brief Check for a large-binary-like type
/// \brief Check for a large-binary-like type (i.e. with 64-bit offsets)
///
/// \param[in] type_id the type-id to check
/// \return whether type-id is a large-binary-like type one
Expand All @@ -1041,7 +1045,7 @@ static inline bool is_large_binary_like(Type::type type_id) {
return false;
}

/// \brief Check for a binary type
/// \brief Check for a binary (non-string) type
///
/// \param[in] type_id the type-id to check
/// \return whether type-id is a binary type one
Expand Down Expand Up @@ -1138,54 +1142,6 @@ static inline bool is_fixed_width(Type::type type_id) {
return is_primitive(type_id) || is_dictionary(type_id) || is_fixed_size_binary(type_id);
}

static inline int bit_width(Type::type type_id) {
switch (type_id) {
case Type::BOOL:
return 1;
case Type::UINT8:
case Type::INT8:
return 8;
case Type::UINT16:
case Type::INT16:
return 16;
case Type::UINT32:
case Type::INT32:
case Type::DATE32:
case Type::TIME32:
return 32;
case Type::UINT64:
case Type::INT64:
case Type::DATE64:
case Type::TIME64:
case Type::TIMESTAMP:
case Type::DURATION:
return 64;

case Type::HALF_FLOAT:
return 16;
case Type::FLOAT:
return 32;
case Type::DOUBLE:
return 64;

case Type::INTERVAL_MONTHS:
return 32;
case Type::INTERVAL_DAY_TIME:
return 64;
case Type::INTERVAL_MONTH_DAY_NANO:
return 128;

case Type::DECIMAL128:
return 128;
case Type::DECIMAL256:
return 256;

default:
break;
}
return 0;
}

/// \brief Check for a list-like type
///
/// \param[in] type_id the type-id to check
Expand Down Expand Up @@ -1238,6 +1194,65 @@ static inline bool is_union(Type::type type_id) {
return false;
}

/// \brief Return the values bit width of a type
///
/// \param[in] type_id the type-id to check
/// \return the values bit width, or 0 if the type does not have fixed-width values
///
/// For Type::FIXED_SIZE_BINARY, you will instead need to inspect the concrete
/// DataType to get this information.
static inline int bit_width(Type::type type_id) {
switch (type_id) {
case Type::BOOL:
return 1;
case Type::UINT8:
case Type::INT8:
return 8;
case Type::UINT16:
case Type::INT16:
return 16;
case Type::UINT32:
case Type::INT32:
case Type::DATE32:
case Type::TIME32:
return 32;
case Type::UINT64:
case Type::INT64:
case Type::DATE64:
case Type::TIME64:
case Type::TIMESTAMP:
case Type::DURATION:
return 64;

case Type::HALF_FLOAT:
return 16;
case Type::FLOAT:
return 32;
case Type::DOUBLE:
return 64;

case Type::INTERVAL_MONTHS:
return 32;
case Type::INTERVAL_DAY_TIME:
return 64;
case Type::INTERVAL_MONTH_DAY_NANO:
return 128;

case Type::DECIMAL128:
return 128;
case Type::DECIMAL256:
return 256;

default:
break;
}
return 0;
}

/// \brief Return the offsets bit width of a type
///
/// \param[in] type_id the type-id to check
/// \return the offsets bit width, or 0 if the type does not have offsets
static inline int offset_bit_width(Type::type type_id) {
switch (type_id) {
case Type::STRING:
Expand Down Expand Up @@ -1269,7 +1284,7 @@ static inline bool is_integer(const DataType& type) { return is_integer(type.id(
/// \param[in] type the type to check
/// \return whether type is a signed integer type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_signed_integer(const DataType& type) {
return is_signed_integer(type.id());
}
Expand All @@ -1279,7 +1294,7 @@ static inline bool is_signed_integer(const DataType& type) {
/// \param[in] type the type to check
/// \return whether type is an unsigned integer type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_unsigned_integer(const DataType& type) {
return is_unsigned_integer(type.id());
}
Expand All @@ -1289,39 +1304,39 @@ static inline bool is_unsigned_integer(const DataType& type) {
/// \param[in] type the type to check
/// \return whether type is a floating point type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_floating(const DataType& type) { return is_floating(type.id()); }

/// \brief Check for a numeric type (number except boolean type)
///
/// \param[in] type the type to check
/// \return whether type is a numeric type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_numeric(const DataType& type) { return is_numeric(type.id()); }

/// \brief Check for a decimal type
///
/// \param[in] type the type to check
/// \return whether type is a decimal type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_decimal(const DataType& type) { return is_decimal(type.id()); }

/// \brief Check for a primitive type
///
/// \param[in] type the type to check
/// \return whether type is a primitive type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_primitive(const DataType& type) { return is_primitive(type.id()); }

/// \brief Check for a binary or string-like type (except fixed-size binary)
///
/// \param[in] type the type to check
/// \return whether type is a binary or string-like type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_base_binary_like(const DataType& type) {
return is_base_binary_like(type.id());
}
Expand All @@ -1331,7 +1346,7 @@ static inline bool is_base_binary_like(const DataType& type) {
/// \param[in] type the type to check
/// \return whether type is a binary-like type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_binary_like(const DataType& type) {
return is_binary_like(type.id());
}
Expand All @@ -1341,7 +1356,7 @@ static inline bool is_binary_like(const DataType& type) {
/// \param[in] type the type to check
/// \return whether type is a large-binary-like type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_large_binary_like(const DataType& type) {
return is_large_binary_like(type.id());
}
Expand All @@ -1351,39 +1366,39 @@ static inline bool is_large_binary_like(const DataType& type) {
/// \param[in] type the type to check
/// \return whether type is a binary type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_binary(const DataType& type) { return is_binary(type.id()); }

/// \brief Check for a string type
///
/// \param[in] type the type to check
/// \return whether type is a string type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_string(const DataType& type) { return is_string(type.id()); }

/// \brief Check for a temporal type, including time and timestamps for each unit
///
/// \param[in] type the type to check
/// \return whether type is a temporal type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_temporal(const DataType& type) { return is_temporal(type.id()); }

/// \brief Check for an interval type
///
/// \param[in] type the type to check
/// \return whether type is a interval type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_interval(const DataType& type) { return is_interval(type.id()); }

/// \brief Check for a dictionary type
///
/// \param[in] type the type to check
/// \return whether type is a dictionary type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_dictionary(const DataType& type) {
return is_dictionary(type.id());
}
Expand All @@ -1393,7 +1408,7 @@ static inline bool is_dictionary(const DataType& type) {
/// \param[in] type the type to check
/// \return whether type is a fixed-size-binary type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_fixed_size_binary(const DataType& type) {
return is_fixed_size_binary(type.id());
}
Expand All @@ -1403,7 +1418,7 @@ static inline bool is_fixed_size_binary(const DataType& type) {
/// \param[in] type the type to check
/// \return whether type is a fixed-width type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_fixed_width(const DataType& type) {
return is_fixed_width(type.id());
}
Expand All @@ -1413,23 +1428,23 @@ static inline bool is_fixed_width(const DataType& type) {
/// \param[in] type the type to check
/// \return whether type is a list-like type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_list_like(const DataType& type) { return is_list_like(type.id()); }

/// \brief Check for a nested type
///
/// \param[in] type the type to check
/// \return whether type is a nested type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_nested(const DataType& type) { return is_nested(type.id()); }

/// \brief Check for a union type
///
/// \param[in] type the type to check
/// \return whether type is a union type
///
/// Convenience for checking using the types' id
/// Convenience for checking using the type's id
static inline bool is_union(const DataType& type) { return is_union(type.id()); }

/// @}
Expand Down

0 comments on commit 3c173b5

Please sign in to comment.