Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(common): unify implementation of hash key #9671

Merged
merged 16 commits into from
May 11, 2023
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ strum = "0.24"
strum_macros = "0.24"
sysinfo = { version = "0.26", default-features = false }
thiserror = "1"
tinyvec = { version = "1", features = ["rustc_1_55", "grab_spare_slice"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need rustc_1_55 and grab_spare_slice? Maybe should leave some comments inline.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because some interfaces of tinyvec are only available under these features. Should be documented by this crate.

tokio = { version = "0.2", package = "madsim-tokio", features = [
"rt",
"rt-multi-thread",
Expand Down
29 changes: 28 additions & 1 deletion src/common/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ pub trait ArrayBuilder: Send + Sync + Sized + 'static {
self.append_n(1, value);
}

/// Append an owned value to builder.
fn append_owned(&mut self, value: Option<<Self::ArrayType as Array>::OwnedItem>) {
let value = value.as_ref().map(|s| s.as_scalar_ref());
self.append(value)
}

fn append_null(&mut self) {
self.append(None)
}
Expand Down Expand Up @@ -308,8 +314,9 @@ impl<A: Array> CompactableArray for A {
/// name, array type, builder type }` tuples. Refer to the following implementations as examples.
#[macro_export]
macro_rules! for_all_variants {
($macro:ident) => {
($macro:ident $(, $x:tt)*) => {
$macro! {
$($x, )*
{ Int16, int16, I16Array, I16ArrayBuilder },
{ Int32, int32, I32Array, I32ArrayBuilder },
{ Int64, int64, I64Array, I64ArrayBuilder },
Expand All @@ -332,6 +339,20 @@ macro_rules! for_all_variants {
};
}

macro_rules! do_dispatch {
($impl:expr, $type:ident, $inner:ident, $body:tt, $( { $variant_name:ident, $suffix_name:ident, $array:ty, $builder:ty } ),*) => {
match $impl {
$( $type::$variant_name($inner) => $body, )*
}
};
}

macro_rules! dispatch_all_variants {
($impl:expr, $type:ident, $scalar:ident, $body:tt) => {{
for_all_variants! { do_dispatch, $impl, $type, $scalar, $body }
}};
}

/// Define `ArrayImpl` with macro.
macro_rules! array_impl_enum {
( $( { $variant_name:ident, $suffix_name:ident, $array:ty, $builder:ty } ),*) => {
Expand Down Expand Up @@ -634,6 +655,12 @@ macro_rules! impl_array {
$( Self::$variant_name(inner) => ArrayBuilderImpl::$variant_name(inner.create_builder(capacity)), )*
}
}

pub fn data_type(&self) -> DataType {
match self {
$( Self::$variant_name(inner) => inner.data_type(), )*
}
}
}
}
}
Expand Down
Loading