<commit_before>/*
 * ccn/bloom.h
 * 
 * Copyright 2008 Palo Alto Research Center, Inc. All rights reserved.
 *
 * Bloom filters
 *
 * $Id$
 */

#ifndef CCN_BLOOM_DEFINED
#define CCN_BLOOM_DEFINED
#include <stddef.h>

struct ccn_bloom;

/*
 * Create an empty Bloom filter, sized appropriately for the estimated
 * number of members.
 */
struct ccn_bloom *ccn_bloom_create(int estimated_members,
                                   const unsigned char seed[4]);

/*
 * Create an updatable Bloom filter from a wire representation.
 * Result does not share storage with the input.
 */
struct ccn_bloom *ccn_bloom_from_wire(const void *data, size_t size);

/*
 * Deallocation.
 */
void ccn_bloom_destroy(struct ccn_bloom **);

/*
 * Add an element.
 * Returns the number of bits changed in the filter.
 */
int ccn_bloom_insert(struct ccn_bloom *b, const void *key, size_t size);

/*
 * Test for membership. False positives are possible.
 */
int ccn_bloom_match(struct ccn_bloom *b, const void *key, size_t size);

/*
 * Fetch the number of elements in the filter.  If b was created
 * from a wire representation, this will be approximate.
 */
int ccn_bloom_n(struct ccn_bloom *b);

/*
 * Return the number of bytes needed for the on-wire representation.
 */
int ccn_bloom_wiresize(struct ccn_bloom *b);

/*
 * Store the on-wire representation.
 */
int ccn_bloom_store_wire(struct ccn_bloom *b,
                         unsigned char *dest, size_t destsize);

/*
 * This structure reflects the on-wire representation of the Bloom filter.
 */
struct ccn_bloom_wire {
    unsigned char lg_bits;  /* 13 maximum (8 kilobits), 3 minimum (one byte) */
    unsigned char n_hash;   /* number of hash functions to employ */
    unsigned char method;   /* allow for various hashing algorithms */
    unsigned char reserved; /* must be 0 for now */
    unsigned char seed[4];  /* can seed hashes differently */
    unsigned char bloom[1024]; /* 8 kilobits maximum */
};

/*
 * ccn_bloom_validate_wire: Check for a valid on-wire representation
 * If not valid, returns NULL.
 * If valid, returns buf cast to the new pointer type.
 */
const struct ccn_bloom_wire *
    ccn_bloom_validate_wire(const void *buf, size_t size);
/*
 * ccn_bloom_match_wire: Test membership using on-wire representation
 * Caller is expected to have validated f.
 */
int ccn_bloom_match_wire(const struct ccn_bloom_wire *f,
                         const void *key, size_t size);

#endif<commit_msg>document return value<commit_after>/*
 * ccn/bloom.h
 * 
 * Copyright 2008 Palo Alto Research Center, Inc. All rights reserved.
 *
 * Bloom filters
 *
 * $Id$
 */

#ifndef CCN_BLOOM_DEFINED
#define CCN_BLOOM_DEFINED
#include <stddef.h>

struct ccn_bloom;

/*
 * Create an empty Bloom filter, sized appropriately for the estimated
 * number of members.
 */
struct ccn_bloom *ccn_bloom_create(int estimated_members,
                                   const unsigned char seed[4]);

/*
 * Create an updatable Bloom filter from a wire representation.
 * Result does not share storage with the input.
 */
struct ccn_bloom *ccn_bloom_from_wire(const void *data, size_t size);

/*
 * Deallocation.
 */
void ccn_bloom_destroy(struct ccn_bloom **);

/*
 * Add an element.
 * Returns the number of bits changed in the filter.
 */
int ccn_bloom_insert(struct ccn_bloom *b, const void *key, size_t size);

/*
 * Test for membership. False positives are possible.
 */
int ccn_bloom_match(struct ccn_bloom *b, const void *key, size_t size);

/*
 * Fetch the number of elements in the filter.  If b was created
 * from a wire representation, this will be approximate.
 */
int ccn_bloom_n(struct ccn_bloom *b);

/*
 * Return the number of bytes needed for the on-wire representation.
 */
int ccn_bloom_wiresize(struct ccn_bloom *b);

/*
 * Store the on-wire representation.
 */
int ccn_bloom_store_wire(struct ccn_bloom *b,
                         unsigned char *dest, size_t destsize);

/*
 * This structure reflects the on-wire representation of the Bloom filter.
 */
struct ccn_bloom_wire {
    unsigned char lg_bits;  /* 13 maximum (8 kilobits), 3 minimum (one byte) */
    unsigned char n_hash;   /* number of hash functions to employ */
    unsigned char method;   /* allow for various hashing algorithms */
    unsigned char reserved; /* must be 0 for now */
    unsigned char seed[4];  /* can seed hashes differently */
    unsigned char bloom[1024]; /* 8 kilobits maximum */
};

/*
 * ccn_bloom_validate_wire: Check for a valid on-wire representation
 * If not valid, returns NULL.
 * If valid, returns buf cast to the new pointer type.
 */
const struct ccn_bloom_wire *
    ccn_bloom_validate_wire(const void *buf, size_t size);
/*
 * ccn_bloom_match_wire: Test membership using on-wire representation
 * Caller is expected to have validated f.
 * Returns true to indicate a match.
 */
int ccn_bloom_match_wire(const struct ccn_bloom_wire *f,
                         const void *key, size_t size);

#endif
{'fraction_non_alphanumeric': 0.08916683477910026, 'fraction_numerical': 0.0064555174500706075, 'mean_word_length': 3.296360485268631, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6477144', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1537, 'n_words': 557}