Skip to content

refactor(theta): theta hash table into raw table, preparing for tuple reuse#146

Merged
tisonkun merged 3 commits into
apache:mainfrom
ariesdevil:raw-hash-table
Jul 10, 2026
Merged

refactor(theta): theta hash table into raw table, preparing for tuple reuse#146
tisonkun merged 3 commits into
apache:mainfrom
ariesdevil:raw-hash-table

Conversation

@ariesdevil

Copy link
Copy Markdown
Contributor

Summary

As @ZENOTME mentioned, we should first extract a reusable hashtable trait for the upcoming tuple implementation.

related: #145

@tisonkun tisonkun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I remember we reject a general Hashable solution as in #118.

But this PR anyway seems like to introduce RawHashTableEntry rather than Hashable.

I noticed that it's a crate-level trait. Would it benefits from being an enum rather than a trait?

@ZENOTME

ZENOTME commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

I remember we reject a general Hashable solution as in #118.

But this PR anyway seems like to introduce RawHashTableEntry rather than Hashable.

I noticed that it's a crate-level trait. Would it benefits from being an enum rather than a trait?

enum means that entry can be different type in single hash table. But in our case, hash table is reuse as

type ThetaHashTable = RawHashTable<ThateHashEntry>

type TupleHashTable = RawHashTable<TupleHashEntry>

Seems trait is more clear.

I remember we reject a general Hashable solution as in #118.

This hash table is for reuse logic between tuple and theta sketch. Not export to user.

@tisonkun

Copy link
Copy Markdown
Member

SGTM.

We can merge #145 now and rebase this PR onto it and continue the review :D

@ZENOTME

ZENOTME commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

SGTM.

We can merge #145 now and rebase this PR onto it and continue the review :D

We can merge this first actually. Otherwise, this PR need to rewrite union. 🤣

Comment thread datasketches/src/theta/hash_table.rs Outdated
Comment on lines +56 to +70
pub(crate) const MAX_THETA: u64 = i64::MAX as u64;
/// Minimum log2 of K
const MIN_LG_K: u8 = 5;
pub(crate) const MIN_LG_K: u8 = 5;
/// Maximum log2 of K
const MAX_LG_K: u8 = 26;
pub(crate) const MAX_LG_K: u8 = 26;
/// Default log2 of K
const DEFAULT_LG_K: u8 = 12;
pub(crate) const DEFAULT_LG_K: u8 = 12;
/// Resize threshold (0.5 = 50% load factor)
const HASH_TABLE_RESIZE_THRESHOLD: f64 = 0.5;
pub(crate) const HASH_TABLE_RESIZE_THRESHOLD: f64 = 0.5;
/// Rebuild threshold (15/16 = 93.75% load factor)
const HASH_TABLE_REBUILD_THRESHOLD: f64 = 15.0 / 16.0;
pub(crate) const HASH_TABLE_REBUILD_THRESHOLD: f64 = 15.0 / 16.0;
/// Stride hash bits (7 bits for stride calculation)
pub(crate) const STRIDE_HASH_BITS: u8 = 7;
/// Stride mask
pub(crate) const STRIDE_MASK: u64 = (1 << STRIDE_HASH_BITS) - 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These pub(crate) should be useless. They are limited to the theta module and can be already accessed by any sub module.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These are defined as pub(crate) because they will be used in subsequent PRs in the stacked PRs; the tuple implementation requires using these constants.
If you feel this PR shouldn't be written this way, I can make the changes.

FYI: https://github.com/apache/datasketches-rust/pull/138/changes#diff-f3568728db442efe8852306fd065409eb9c4286921170ef66c3cde0b9d452be4R31-R33

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fair enough. Then let's keep the pub(crate) structure now and do a review (refactor) later when all the function code landed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess we can finally move the shared code to a datasketches/thetacommon module later. This is how datasketches-java organizes code also.

But let's review this then.

Comment thread datasketches/src/theta/raw_hash_table.rs
Comment thread datasketches/src/theta/hash_table.rs Outdated

@ZENOTME ZENOTME left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@tisonkun tisonkun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Further improvement suggestions can be addressed once we get all the functions landed.

@tisonkun
tisonkun enabled auto-merge (squash) July 10, 2026 13:07
@tisonkun
tisonkun merged commit 8c1514f into apache:main Jul 10, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants