gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NonCountingBloomFilter.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
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 
30 
31 #include "base/intmath.hh"
32 #include "base/str.hh"
34 
35 using namespace std;
36 
38 {
39  // head contains filter size, tail contains bit offset from block number
40  m_filter_size = head;
41  m_offset = tail;
42  m_filter_size_bits = floorLog2(m_filter_size);
43 
44  m_filter.resize(m_filter_size);
45  clear();
46 }
47 
49 {
50 }
51 
52 void
54 {
55  for (int i = 0; i < m_filter_size; i++) {
56  m_filter[i] = 0;
57  }
58 }
59 
60 void
62 {
63  // Not used
64 }
65 
66 void
68 {
69  // Not used
70 }
71 
72 void
74 {
75  // assumes both filters are the same size!
76  NonCountingBloomFilter * temp = (NonCountingBloomFilter*) other_filter;
77  for (int i = 0; i < m_filter_size; ++i){
78  m_filter[i] |= (*temp)[i];
79  }
80 }
81 
82 void
84 {
85  int i = get_index(addr);
86  m_filter[i] = 1;
87 }
88 
89 void
91 {
92  int i = get_index(addr);
93  m_filter[i] = 0;
94 }
95 
96 bool
98 {
99  int i = get_index(addr);
100  return (m_filter[i]);
101 }
102 
103 
104 int
106 {
107  return m_filter[get_index(addr)];
108 }
109 
110 int
112 {
113  int count = 0;
114 
115  for (int i = 0; i < m_filter_size; i++) {
116  count += m_filter[i];
117  }
118  return count;
119 }
120 
121 void
122 NonCountingBloomFilter::print(ostream& out) const
123 {
124 }
125 
126 int
128 {
129  return get_index(addr);
130 }
131 
132 int
134 {
135  return m_filter[index];
136 }
137 
138 void
139 NonCountingBloomFilter::writeBit(const int index, const int value)
140 {
141  m_filter[index] = value;
142 }
143 
144 int
146 {
147  return bitSelect(addr, RubySystem::getBlockSizeBits() + m_offset,
148  RubySystem::getBlockSizeBits() + m_offset +
149  m_filter_size_bits - 1);
150 }
151 
152 
count
Definition: misc.hh:704
Bitfield< 30, 0 > index
Addr bitSelect(Addr addr, unsigned int small, unsigned int big)
Definition: Address.cc:34
Bitfield< 7 > i
Definition: miscregs.hh:1378
void merge(AbstractBloomFilter *other_filter)
ip6_addr_t addr
Definition: inet.hh:335
void writeBit(const int index, const int value)
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
int floorLog2(unsigned x)
Definition: intmath.hh:100
NonCountingBloomFilter(int head, int tail)
void print(std::ostream &out) const
int readBit(const int index)
static uint32_t getBlockSizeBits()
Definition: RubySystem.hh:75

Generated on Fri Jun 9 2017 13:03:49 for gem5 by doxygen 1.8.6