Skip to content

Commit db49fff

Browse files
committed
cargo fmt
1 parent 268a9f1 commit db49fff

1 file changed

Lines changed: 9 additions & 24 deletions

File tree

  • datafusion/spark/src/function/math

datafusion/spark/src/function/math/hex.rs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,14 @@ impl ScalarUDFImpl for SparkHex {
111111
}
112112
}
113113

114+
/// Hex encoding lookup tables for fast byte-to-hex conversion
115+
const HEX_CHARS_LOWER: &[u8; 16] = b"0123456789abcdef";
116+
const HEX_CHARS_UPPER: &[u8; 16] = b"0123456789ABCDEF";
117+
114118
#[inline]
115119
fn hex_int64(num: i64, buffer: &mut Vec<u8>) {
116-
const HEX_CHARS: &[u8; 16] = b"0123456789ABCDEF";
117-
118120
if num == 0 {
119-
buffer.push(HEX_CHARS[0]);
121+
buffer.push(HEX_CHARS_UPPER[0]);
120122
return;
121123
}
122124

@@ -126,31 +128,13 @@ fn hex_int64(num: i64, buffer: &mut Vec<u8>) {
126128
while n != 0 && i > 0 {
127129
i -= 1;
128130
let digest = (n & 0xF) as u8;
129-
temp[i] = HEX_CHARS[digest as usize];
131+
temp[i] = HEX_CHARS_UPPER[digest as usize];
130132
n >>= 4;
131133
}
132134

133135
buffer.extend_from_slice(&temp[i..]);
134136
}
135137

136-
/// Hex encoding lookup tables for fast byte-to-hex conversion
137-
const HEX_CHARS_LOWER: &[u8; 16] = b"0123456789abcdef";
138-
const HEX_CHARS_UPPER: &[u8; 16] = b"0123456789ABCDEF";
139-
140-
#[inline]
141-
fn hex_encode<T: AsRef<[u8]>>(data: T, lower_case: bool, buffer: &mut Vec<u8>) {
142-
let bytes = data.as_ref();
143-
let hex_chars = if lower_case {
144-
HEX_CHARS_LOWER
145-
} else {
146-
HEX_CHARS_UPPER
147-
};
148-
for &b in bytes {
149-
buffer.push(hex_chars[(b >> 4) as usize]);
150-
buffer.push(hex_chars[(b & 0x0f) as usize]);
151-
}
152-
}
153-
154138
/// Generic hex encoding for byte array types
155139
fn hex_encode_bytes<'a, I, T>(
156140
iter: I,
@@ -189,7 +173,7 @@ where
189173
}
190174

191175
/// Generic hex encoding for int64 type
192-
fn hex_encode_int64<'a, I>(iter: I, len: usize) -> Result<ColumnarValue, DataFusionError>
176+
fn hex_encode_int64<I>(iter: I, len: usize) -> Result<ColumnarValue, DataFusionError>
193177
where
194178
I: Iterator<Item = Option<i64>>,
195179
{
@@ -270,7 +254,8 @@ pub fn compute_hex(
270254
DataType::Int64 => {
271255
let int_values = as_int64_array(values)?;
272256
hex_encode_int64(
273-
keys.iter().map(|k| k.map(|idx| int_values.value(idx as usize))),
257+
keys.iter()
258+
.map(|k| k.map(|idx| int_values.value(idx as usize))),
274259
dict.len(),
275260
)
276261
}

0 commit comments

Comments
 (0)