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

Update data-structure-on-rocksdb.md for Hyperloglog #207

Merged
merged 5 commits into from
Jul 31, 2024

Conversation

tutububug
Copy link
Contributor

No description provided.

```
- `size` records the number of registers, which is a constant, even no element is added.

#### hyperloglog sub keys-values
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind try Bitmap structure? "bitfield" command might help in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had changed my previous implementation of the storage format, currently, the format is the same as the bitmap's, and each HLL subkey represents a segment with 1024 registers.
Also, I tried to use bitfield, but finally, I found that it requires byte alignment because of 'memcpy' (it should only be able to operate bits within a byte). The implementation of Redis only uses 6 bits, not aligned, to save more space, so it seems not suitable.
However, another problem arises. When the register is set to 6-bit, unit test runs fail on a few OS releases in CI, but there is no problem when it is set to 8-bit, maybe it has something to do with byte alignment, but I don’t know the reason yet. Therefore, the current implementation still maintains 8 bits without using bitfield.
If I understand something wrong, correct me, thanks.


```text
+---------------+
key|version|register_index => | 0s count |
Copy link
Member

Choose a reason for hiding this comment

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

we can denote the format of count. In current implementation, the count is an count-to-string ?

@mapleFU
Copy link
Member

mapleFU commented Apr 3, 2024

Thanks! I'll take a careful round these two days

@tisonkun tisonkun requested a review from mapleFU April 15, 2024 00:36
```
The register index is calculated using the first 14 bits of the user element's hash value (64 bits), which is why the register array length is 16384.
The length of consecutive zeros is calculated using the last 50 digits of the hash value of the user key.
Inspired by the bitmap implementation, hyperloglog divides the register array into 16 segments, each with 1024 registers.
Copy link
Member

Choose a reason for hiding this comment

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

So it's now not actually register_index? But something like segment index.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is register_index, the same as the bitmap segment in which the 1st segment subkey is 'subkey0', the 2nd is 'subkey1024', and so on.

Copy link
Member

@PragmaTwice PragmaTwice left a comment

Choose a reason for hiding this comment

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

Looks good to me.

It can be merged after the implementation is merged into unstable.

@mapleFU mapleFU merged commit a212185 into apache:main Jul 31, 2024
1 check 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.

4 participants