2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
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.
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.
29 #include "base/intmath.hh"
30 #include "base/str.hh"
31 #include "mem/ruby/filters/LSB_CountingBloomFilter.hh"
32 #include "mem/ruby/system/System.hh"
36 LSB_CountingBloomFilter::LSB_CountingBloomFilter(string str
)
42 split_first(str
, head
, tail
, '_');
45 m_filter_size
= atoi(head
.c_str());
46 m_filter_size_bits
= floorLog2(m_filter_size
);
48 m_count
= atoi(tail
.c_str());
49 m_count_bits
= floorLog2(m_count
);
51 m_filter
.resize(m_filter_size
);
55 LSB_CountingBloomFilter::~LSB_CountingBloomFilter()
60 LSB_CountingBloomFilter::clear()
62 for (int i
= 0; i
< m_filter_size
; i
++) {
68 LSB_CountingBloomFilter::increment(const Address
& addr
)
70 int i
= get_index(addr
);
71 if (m_filter
[i
] < m_count
)
77 LSB_CountingBloomFilter::decrement(const Address
& addr
)
79 int i
= get_index(addr
);
85 LSB_CountingBloomFilter::merge(AbstractBloomFilter
* other_filter
)
91 LSB_CountingBloomFilter::set(const Address
& addr
)
97 LSB_CountingBloomFilter::unset(const Address
& addr
)
103 LSB_CountingBloomFilter::isSet(const Address
& addr
)
110 LSB_CountingBloomFilter::getCount(const Address
& addr
)
112 return m_filter
[get_index(addr
)];
116 LSB_CountingBloomFilter::getTotalCount()
120 for (int i
= 0; i
< m_filter_size
; i
++) {
121 count
+= m_filter
[i
];
127 LSB_CountingBloomFilter::getIndex(const Address
& addr
)
129 return get_index(addr
);
133 LSB_CountingBloomFilter::print(ostream
& out
) const
138 LSB_CountingBloomFilter::readBit(const int index
)
145 LSB_CountingBloomFilter::writeBit(const int index
, const int value
)
151 LSB_CountingBloomFilter::get_index(const Address
& addr
)
153 return addr
.bitSelect(RubySystem::getBlockSizeBits(),
154 RubySystem::getBlockSizeBits() +
155 m_filter_size_bits
- 1);