<commit_before>#ifndef BLOOM_SBF_H
#define BLOOM_SBF_H
#include "bloom.h"

/**
 * Defines a callback function that 
 * takes an arbitrary pointer value, the number of bytes required,
 * and a reference to bloom_bitmap for output. Returns an int as
 * status, 0 is success.
 */
typedef int(*bloom_sbf_callback)(void* in, uint64_t bytes, bloom_bitmap *out);

/**
 * The parameters to configure a scalable bloom filter.
 * See DEFAULT_PARAMS and SLOW_GROW_PARAMS.
 */
typedef struct {
    uint64_t initial_capacity;      // Initial size
    double fp_probability;          // FP probability
    uint32_t scale_size;              // Scale size for new filters
    double probability_reduction;   // New filter, fp_prob reduciton
} bloom_sbf_params;

/**
 * These are the default parameters for bloom_sbf_params.
 * Creates an initial capacity for 1 million items, 1/1000
 * false positive rate, 4x scaling, and a 90% false positive
 * probability reduction with each new filter. This works well
 * in most situations.
 */
#define SBF_DEFAULT_PARAMS {1e6, 1e-3, 4, 0.9}

/**
 * These are memory sensitive parameters for bloom_sbf_params.
 * This will grow more slowly than the DEFAULT_PARAMS, but 
 * increases the changes of false positives.
 * Creates an initial capacity for 1 million items, 1/1000
 * false positive rate, 2x scaling, and a 80% false positive
 * probability reduction with each new filter.
 */
#define SBF_SLOW_GROW_PARAMS {1e6, 1e-3, 2, 0.8}

/**
 * Represents a scalable bloom filters
 */
typedef struct {
    bloom_sbf_params params;              // Our parameters

    bloom_sbf_callback callback;    // Callback, or NULL for auto
    void *callback_input;           // Callback input if any

    uint32_t num_filters;           // The number of filters
    bloom_bloomfilter **filters;     // Array into the filters

    unsigned char *dirty_filters;   // Used to set a dirty flag

    uint64_t *capacities;            // Tracks the per-filter capacity
} bloom_sbf;

/**
 * Creates a new scalable bloom filter using given bloom filters.
 * @arg params The parameters of the new SBF
 * @arg cb The callback function to invoke. NULL to use anonymous bitmaps.
 * @arg cb_in The opaque pointer to provide to the callback.<commit_msg>Change the default SBF params to reduce initial size, and tighten default probability.<commit_after>#ifndef BLOOM_SBF_H
#define BLOOM_SBF_H
#include "bloom.h"

/**
 * Defines a callback function that 
 * takes an arbitrary pointer value, the number of bytes required,
 * and a reference to bloom_bitmap for output. Returns an int as
 * status, 0 is success.
 */
typedef int(*bloom_sbf_callback)(void* in, uint64_t bytes, bloom_bitmap *out);

/**
 * The parameters to configure a scalable bloom filter.
 * See DEFAULT_PARAMS and SLOW_GROW_PARAMS.
 */
typedef struct {
    uint64_t initial_capacity;      // Initial size
    double fp_probability;          // FP probability
    uint32_t scale_size;              // Scale size for new filters
    double probability_reduction;   // New filter, fp_prob reduciton
} bloom_sbf_params;

/**
 * These are the default parameters for bloom_sbf_params.
 * Creates an initial capacity for 1 million items, 1/1000
 * false positive rate, 4x scaling, and a 90% false positive
 * probability reduction with each new filter. This works well
 * in most situations.
 */
#define SBF_DEFAULT_PARAMS {1e5, 1e-4, 4, 0.9}

/**
 * These are memory sensitive parameters for bloom_sbf_params.
 * This will grow more slowly than the DEFAULT_PARAMS, but 
 * increases the changes of false positives.
 * Creates an initial capacity for 1 million items, 1/1000
 * false positive rate, 2x scaling, and a 80% false positive
 * probability reduction with each new filter.
 */
#define SBF_SLOW_GROW_PARAMS {1e5, 1e-4, 2, 0.8}

/**
 * Represents a scalable bloom filters
 */
typedef struct {
    bloom_sbf_params params;              // Our parameters

    bloom_sbf_callback callback;    // Callback, or NULL for auto
    void *callback_input;           // Callback input if any

    uint32_t num_filters;           // The number of filters
    bloom_bloomfilter **filters;     // Array into the filters

    unsigned char *dirty_filters;   // Used to set a dirty flag

    uint64_t *capacities;            // Tracks the per-filter capacity
} bloom_sbf;

/**
 * Creates a new scalable bloom filter using given bloom filters.
 * @arg params The parameters of the new SBF
 * @arg cb The callback function to invoke. NULL to use anonymous bitmaps.
 * @arg cb_in The opaque pointer to provide to the callback.
{'fraction_non_alphanumeric': 0.07175672719317436, 'fraction_numerical': 0.01881426383723474, 'mean_word_length': 3.217712177121771, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4182624', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1292, 'n_words': 547}