1/* 2 * Copyright (c) 2019 Inria 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Daniel Carvalho 29 */ 30 31#include "base/filters/perfect_bloom_filter.hh" 32 33#include "params/BloomFilterPerfect.hh" 34 35namespace BloomFilter { 36 37Perfect::Perfect(const BloomFilterPerfectParams* p) 38 : Base(p) 39{ 40} 41 42Perfect::~Perfect() 43{ 44} 45 46void 47Perfect::clear() 48{ 49 entries.clear(); 50} 51 52void 53Perfect::merge(const Base* other) 54{ 55 auto* cast_other = static_cast<const Perfect*>(other); 56 entries.insert(cast_other->entries.begin(), cast_other->entries.end()); 57} 58 59void 60Perfect::set(Addr addr) 61{ 62 entries.insert(addr); 63} 64 65void 66Perfect::unset(Addr addr) 67{ 68 entries.erase(addr); 69} 70 71int 72Perfect::getCount(Addr addr) const 73{ 74 return entries.find(addr) != entries.end(); 75} 76 77int 78Perfect::getTotalCount() const 79{ 80 return entries.size(); 81} 82 83} // namespace BloomFilter 84 85BloomFilter::Perfect* 86BloomFilterPerfectParams::create() 87{ 88 return new BloomFilter::Perfect(this); 89} 90 91