Commit f9b32386 authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

initial commit

parent a25ef657
Loading
Loading
Loading
Loading

include/Bloom.h

0 → 100644
+70 −0
Original line number Diff line number Diff line
//
// Created by Ari Trachtenberg on 3/15/17.
//

#ifndef BLOOM_OBJECT_H
#define BLOOM_OBJECT_H

#include <string>
#include <array>

using namespace std;

/**
 * Represents a Bloom object corresponding to a character-based Bloom filter.
 * \tparam length The length (in characters) of the Bloom filter.
 */
template<size_t length>
class Bloom {
public:
    /**
     * Instantiate an empty Bloom filter object
     */
    Bloom () = default;

    /**
     * @return A pointer to an empty Bloom filter.
     */
    virtual unique_ptr< Bloom > makeBloom() = 0;

    /**
     * Instantiates a Bloom filter object from a given \param theFilter string
     * \param theFilter The object is created to represent this \param theFilter
     * \pre \param theFilter must have been produced by the \ref getFilter()
     *     method of some BloomFilter object of the same length, or else the
     *     behavior is unspecified.
     * \return A pointer to a Bloom filter corresponding to \param theFilter
     */
     virtual unique_ptr< Bloom > makeBloom(const array<char,length>& theFilter) = 0;

    /**
     * inserts \param item into the Bloom object.
     */
     virtual void insert(string item)=0;

    /**
     * Checks whether \param item is in the Bloom filter object.
     * @return  true if \param item may be in the Bloom filter object
     *          false if \param item  is definitely not in the Bloom filter object
     */
    virtual bool exists(string item)=0;

    /**
     * \return A filter string representing the Bloom object
     */
    const array<char,length> getFilter() const { return filter; }

    /**
     * Destructor for the Bloom object
     */
    virtual ~Bloom() = default;

protected:
    /**
     * The filter itself.
     */
    array<char,length> filter;
};


#endif //BLOOM_OBJECT_H

main.cpp

0 → 100644
+18 −0
Original line number Diff line number Diff line
//
// Created by Ari Trachtenberg on 3/5/26.
//

#include<iostream>
#include "include/MyBloom.h"

using namespace std;

int main() {
    MyBloom<10> test;
    test.insert("hello");
    test.insert("world");

    cout << test.exists("hello") << endl;
    cout << test.exists("world") << endl;
    cout << test.exists("bart") << endl;
}
 No newline at end of file