jiacai2050 commented on code in PR #1540:
URL: https://github.com/apache/horaedb/pull/1540#discussion_r1669788299
##########
src/components/partitioned_lock/src/lib.rs:
##########
@@ -36,20 +36,33 @@ impl<T, B> PartitionedRwLock<T, B>
where
B: BuildHasher,
{
- pub fn try_new<F, E>(init_fn: F, partition_bit: usize, hash_builder: B) ->
Result<Self, E>
+ /// the old way to new a partitioned lock, retained for Compatibility
+ /// the capactity of partition is 2^partition_bit_Len
+ pub fn try_new_with_bit_len<F, E>(
+ init_fn: F,
+ partition_bit_len: usize,
+ hash_builder: B,
+ ) -> Result<Self, E>
where
F: Fn(usize) -> Result<T, E>,
{
- let partition_num = 1 << partition_bit;
- let partitions = (1..partition_num)
- .map(|_| init_fn(partition_num).map(RwLock::new))
- .collect::<Result<Vec<RwLock<T>>, E>>()?;
+ let partition_num = 1 << partition_bit_len;
+ PartitionedRwLock::try_new_with_partition_num(init_fn, partition_num,
hash_builder)
+ }
- Ok(Self {
- partitions,
- partition_mask: partition_num - 1,
- hash_builder,
- })
+ /// the suggested method of new a partitioned lock
+ /// the capactity is the next power of 2 of suggest_cap
+ /// example: suggest_cap = 10, partition_num = 16
Review Comment:
```suggestion
/// New cache with capacity round to `suggest_cap`'s power of 2
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]