clickhouse_rs_cityhash_sys/
lib.rs

1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4
5use std::os::raw::c_char;
6
7#[repr(C)]
8#[derive(Debug, Copy, Clone, Eq, PartialEq)]
9pub struct UInt128 {
10    pub lo: u64,
11    pub hi: u64,
12}
13
14extern "C" {
15    fn CityHash128(s: *const c_char, len: usize) -> UInt128;
16}
17
18pub fn city_hash_128<B: AsRef<[u8]>>(source: B) -> UInt128 {
19    let buffer = source.as_ref();
20    unsafe { CityHash128(buffer.as_ptr() as *const c_char, buffer.len()) }
21}
22
23#[test]
24fn test_city_hash_128() {
25    let expected = UInt128 {
26        lo: 0x900ff195577748fe,
27        hi: 0x13a9176355b20d7e,
28    };
29    let actual = city_hash_128("abc");
30    assert_eq!(expected, actual)
31}