Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fast_wildcard_group.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef PAGESPEED_KERNEL_BASE_FAST_WILDCARD_GROUP_H_
20 #define PAGESPEED_KERNEL_BASE_FAST_WILDCARD_GROUP_H_
21 
22 #include <vector>
27 
28 namespace net_instaweb {
29 
30 class Wildcard;
31 
51 
95  public:
99  static const int kMinPatterns = 11;
100 
102  : rolling_hash_length_(kUncompiled) { }
104  : rolling_hash_length_(kUncompiled) {
105  CopyFrom(src);
106  }
107 
108  ~FastWildcardGroup();
109  FastWildcardGroup& operator=(const FastWildcardGroup& other) {
110  CopyFrom(other);
111  return *this;
112  }
113 
116  bool Match(const StringPiece& str, bool allow_by_default) const;
117 
120  void Allow(const StringPiece& wildcard);
121 
124  void Disallow(const StringPiece& wildcard);
125 
126  void CopyFrom(const FastWildcardGroup& src);
127  void AppendFrom(const FastWildcardGroup& src);
128 
130  void Merge(const FastWildcardGroup& src) { AppendFrom(src); }
131 
132  GoogleString Signature() const;
133 
135  int num_wildcards() const { return wildcards_.size(); }
136  bool empty() const { return wildcards_.empty(); }
137 
138  private:
140  static const int32 kUncompiled = -1;
141  static const int32 kDontHash = 0;
142 
143  void Uncompile();
144  void Clear();
145  inline int& pattern_hash_index(uint64 rolling_hash) const;
146  void Compile() const;
147  void CompileNonTrivial() const;
148 
152  std::vector<Wildcard*> wildcards_;
153  std::vector<bool> allow_;
154 
156  mutable std::vector<uint64> rolling_hashes_;
157  mutable std::vector<int> effective_indices_;
158  mutable std::vector<int> wildcard_only_indices_;
159  mutable std::vector<int> pattern_hash_index_;
160  mutable AtomicInt32 rolling_hash_length_;
161 
163 };
164 
165 }
166 
167 #endif
Definition: fast_wildcard_group.h:94
Definition: signature.h:42
static const int kMinPatterns
Definition: fast_wildcard_group.h:99
void Allow(const StringPiece &wildcard)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
bool Match(const StringPiece &str, bool allow_by_default) const
void Merge(const FastWildcardGroup &src)
Alias for use of CopyOnWrite.
Definition: fast_wildcard_group.h:130
void Disallow(const StringPiece &wildcard)
int num_wildcards() const
Return the number of configured wildcards.
Definition: fast_wildcard_group.h:135