-
Notifications
You must be signed in to change notification settings - Fork 17
Basic serialization and deserialization of diff filters #71
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d90d6f0
implement basic serialization and deserialization of diff counts as b…
itsibitzi 3e33988
Refactor serialization tests for geo diff count types
itsibitzi c143f4f
Move serialization code to dedicated module
itsibitzi fc9c45d
Modify module docs to explain that big endian is not supported.
itsibitzi aa215ce
Linting fixes and alignment testing
itsibitzi 42f76b8
Fix test name/config mismatch in diff_count test. Thanks Copilot!
itsibitzi a80c3e6
Update diff_count serialization test to use less clowny padding
itsibitzi 3fc9ff3
Reworks for geofilter serialization work
itsibitzi 0b63f37
Remove whitespace in geofilters bitvec
itsibitzi 14c5b08
Merge branch 'main' into sc-20250723-serialize
itsibitzi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,11 +1,11 @@ | ||||||||||||||
| use std::borrow::Cow; | ||||||||||||||
| use std::cmp::Ordering; | ||||||||||||||
| use std::mem::{size_of, size_of_val}; | ||||||||||||||
| use std::ops::{Index, Range}; | ||||||||||||||
| use std::ops::{Deref as _, Index, Range}; | ||||||||||||||
|
|
||||||||||||||
| use crate::config::BitChunk; | ||||||||||||||
| use crate::config::IsBucketType; | ||||||||||||||
| use crate::config::BITS_PER_BLOCK; | ||||||||||||||
| use crate::config::{BitChunk, BYTES_PER_BLOCK}; | ||||||||||||||
|
|
||||||||||||||
| /// A bit vector where every bit occupies exactly one bit (in contrast to `Vec<bool>` where each | ||||||||||||||
| /// bit consumes 1 byte). It only implements the minimum number of operations that we need for our | ||||||||||||||
|
|
@@ -72,6 +72,10 @@ impl BitVec<'_> { | |||||||||||||
| self.num_bits | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| pub fn is_empty(&self) -> bool { | ||||||||||||||
| self.num_bits() == 0 | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /// Tests the bit specified by the provided zero-based bit position. | ||||||||||||||
| pub fn test_bit(&self, index: usize) -> bool { | ||||||||||||||
| assert!(index < self.num_bits); | ||||||||||||||
|
|
@@ -133,6 +137,53 @@ impl BitVec<'_> { | |||||||||||||
| let Self { num_bits, blocks } = self; | ||||||||||||||
| size_of_val(num_bits) + blocks.len() * size_of::<u64>() | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| #[cfg(target_endian = "little")] | ||||||||||||||
| pub fn from_bytes(mut buf: &[u8]) -> Self { | ||||||||||||||
| if buf.is_empty() { | ||||||||||||||
| return Self::default(); | ||||||||||||||
| } | ||||||||||||||
| // The first byte of the serialized BitVec is used to indicate how many | ||||||||||||||
| // of the bits in the left-most u64 block are *unoccupied*. | ||||||||||||||
| // See [`BitVec::write`] implementation for how this is done. | ||||||||||||||
| assert!( | ||||||||||||||
| buf[0] < 64, | ||||||||||||||
| "Number of unoccupied bits should be <64, got {}", | ||||||||||||||
|
itsibitzi marked this conversation as resolved.
|
||||||||||||||
| buf[0] | ||||||||||||||
| ); | ||||||||||||||
| let num_bits = (buf.len() - 1) * 8 - buf[0] as usize; | ||||||||||||||
| buf = &buf[1..]; | ||||||||||||||
| assert_eq!( | ||||||||||||||
| buf.len() % BYTES_PER_BLOCK, | ||||||||||||||
| 0, | ||||||||||||||
| "buffer should be a multiple of 8 bytes, got {}", | ||||||||||||||
| buf.len() | ||||||||||||||
| ); | ||||||||||||||
| let blocks = unsafe { | ||||||||||||||
| std::mem::transmute::<&[u8], &[u64]>(std::slice::from_raw_parts( | ||||||||||||||
| buf.as_ptr(), | ||||||||||||||
| buf.len() / BYTES_PER_BLOCK, | ||||||||||||||
| )) | ||||||||||||||
| }; | ||||||||||||||
|
||||||||||||||
| }; | |
| let (prefix, blocks, suffix) = unsafe { buf.align_to::<u64>() }; | |
| assert!( | |
| prefix.is_empty() && suffix.is_empty(), | |
| "Buffer is not properly aligned for u64" | |
| ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.