All pastes #1901997 Raw Edit

Someone

public python v1 · immutable
#1901997 ·published 2010-07-16 20:22 UTC
rendered paste body
"""struct bloomstat{    BIGNUM elements; /* size of array */    int ideal_hashes; /* num hash functions */    BIGNUM capacity; /* number of elements */    float e; /* max error rate */} ;typedef struct{    char *vector;    hash_t hash;    BIGNUM inserts;    struct bloomstat stat;    randoms random_nums;} bloom;/* public interface */int bloom_init(bloom *bloom,BIGNUM size,BIGNUM capacity, float error_rate,           int hashes,hash_t hash,int flags);int bloom_check(bloom *bloom,char *str);int bloom_add(bloom *bloom,char *str);int bloom_test(bloom *bloom,char *str,int MODE);void bloom_destroy(bloom *bloom);int bloom_serialize(bloom *bloom, char *fname);bloom * bloom_deserialize(char *fname);"""cdef extern from "bloom.h":    ctypedef unsigned long long BIGNUM    struct bloomstat:        int ideal_hashes        int elements    ctypedef struct bloom:        bloomstat *stat    # the hash_function must take a string and return a bignum    ctypedef BIGNUM (*hash_t)(char *str)    int bloom_init(bloom * bloom, BIGNUM size, BIGNUM capacity, float error_rate,                int hashes, hash_t hash, int_flags)    int bloom_check(bloom * bloom, char *str)    int bloom_add(bloom * bloom, char *str)    int bloom_test(bloom * bloom, char *str, int MODE)    void bloom_destry(bloom * bloom)    int bloom_serialize(bloom * bloom, char *fname)    bloom * bloom_deserialize(char *fname)    int get_suggestion(bloomstat *stats, BIGNUM n, double e)cdef class Elf:    cdef bloom* _bloom    def __cinit__(self, BIGNUM n_elements, float error_rate=0.001):        get_suggestion(self._bloom.stat, n_elements, error_rate)        bloom_init(self._bloom, self._bloom.stat.elements, n_elements, error_rate,                   self._bloom.stat.ideal_hashes, NULL, 1)    def add(self, astr):        return bloom_add(self._bloom, astr)    def __contains__(self, astr):        return bool(bloom_test(self._bloom, astr, 1))