Skip to content

Commit

Permalink
Add more documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
KarthikSubbarao committed Jul 2, 2024
1 parent 6f9ccc2 commit b679f23
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/bloom_config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use lazy_static::lazy_static;
use std::sync::atomic::AtomicI64;

// TODO: Define appropriate min / default / max values.
// TODO: Review min / default / max values for the configs.
// TODO: Decide if we need default false positive rate as a config.
// TODO: Decide if we need a config for the max number of allowed sub filters per object.

pub const BLOOM_MAX_ITEM_COUNT_DEFAULT: i64 = 100000;
pub const BLOOM_MAX_ITEM_COUNT_MIN: i64 = 1;
Expand Down
4 changes: 1 addition & 3 deletions src/commands/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub fn bloom_filter_add_value(
}
None => {
// Instantiate empty bloom filter.
// TODO: Define the default false positive rate as a config.
let fp_rate = 0.001;
let capacity = bloom_config::BLOOM_MAX_ITEM_COUNT.load(Ordering::Relaxed) as u32;
let expansion = bloom_config::BLOOM_EXPANSION.load(Ordering::Relaxed) as u32;
Expand Down Expand Up @@ -204,15 +203,14 @@ pub fn bloom_filter_reserve(ctx: &Context, input_args: &[RedisString]) -> RedisR

pub fn bloom_filter_insert(ctx: &Context, input_args: &[RedisString]) -> RedisResult {
let argc = input_args.len();
// At the very least, we need: BF.INSERT <key> ITEM <item>
// At the very least, we need: BF.INSERT <key> ITEMS <item>
if argc < 4 {
return Err(RedisError::WrongArity);
}
let mut idx = 1;
// Parse the filter name
let filter_name = &input_args[idx];
idx += 1;
// TODO: Create and use a config for the default fp_rate.
let mut fp_rate = 0.001;
let mut capacity = bloom_config::BLOOM_MAX_ITEM_COUNT.load(Ordering::Relaxed) as u32;
let mut expansion = bloom_config::BLOOM_EXPANSION.load(Ordering::Relaxed) as u32;
Expand Down
1 change: 1 addition & 0 deletions src/commands/bloom_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct BloomFilterType {
}

impl BloomFilterType {
/// Create a new BloomFilterType object.
pub fn new_reserved(fp_rate: f32, capacity: u32, expansion: u32) -> BloomFilterType {
let bloom = BloomFilter::new(fp_rate, capacity);
let filters = vec![bloom];
Expand Down
11 changes: 10 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,47 @@ fn initialize(_ctx: &Context, _args: &[RedisString]) -> Status {
Status::Ok
}

pub fn deinitialize(_ctx: &Context) -> Status {
fn deinitialize(_ctx: &Context) -> Status {
Status::Ok
}

/// Command handler for BF.EXISTS <key> <item>
fn bloom_exists_command(ctx: &Context, args: Vec<RedisString>) -> RedisResult {
bloom::bloom_filter_exists(ctx, &args, false)
}

/// Command handler for BF.MEXISTS <key> <item> [<item> ...]
fn bloom_mexists_command(ctx: &Context, args: Vec<RedisString>) -> RedisResult {
bloom::bloom_filter_exists(ctx, &args, true)
}

/// Command handler for BF.ADD <key> <item>
fn bloom_add_command(ctx: &Context, args: Vec<RedisString>) -> RedisResult {
bloom::bloom_filter_add_value(ctx, &args, false)
}

/// Command handler for BF.MADD <key> <item> [<item> ...]
fn bloom_madd_command(ctx: &Context, args: Vec<RedisString>) -> RedisResult {
bloom::bloom_filter_add_value(ctx, &args, true)
}

/// Command handler for BF.CARD <key>
fn bloom_card_command(ctx: &Context, args: Vec<RedisString>) -> RedisResult {
bloom::bloom_filter_card(ctx, &args)
}

/// Command handler for BF.RESERVE <key> <false_positive_rate> <capacity> [EXPANSION <expansion>] | [NONSCALING]
fn bloom_reserve_command(ctx: &Context, args: Vec<RedisString>) -> RedisResult {
bloom::bloom_filter_reserve(ctx, &args)
}

/// Command handler for BF.INFO <key> [CAPACITY | SIZE | FILTERS | ITEMS | EXPANSION]
fn bloom_info_command(ctx: &Context, args: Vec<RedisString>) -> RedisResult {
bloom::bloom_filter_info(ctx, &args)
}

/// Command handler for:
/// BF.INSERT <key> [ERROR <fp_error>] [CAPACITY <capacity>] [EXPANSION <expansion>] [NOCREATE] [NONSCALING] ITEMS <item> [<item> ...]
fn bloom_insert_command(ctx: &Context, args: Vec<RedisString>) -> RedisResult {
bloom::bloom_filter_insert(ctx, &args)
}
Expand Down
2 changes: 1 addition & 1 deletion src/wrapper/bloom_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub unsafe extern "C" fn bloom_free(value: *mut c_void) {
}

/// # Safety
/// Compute the memory usage for a bloom string item
/// Compute the memory usage for a bloom object.
pub unsafe extern "C" fn bloom_mem_usage(value: *const c_void) -> usize {
let item = &*value.cast::<BloomFilterType>();
item.get_memory_usage()
Expand Down

0 comments on commit b679f23

Please sign in to comment.