Page Speed Optimization Libraries  1.2.24.1
net/instaweb/util/public/fast_wildcard_group.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 #ifndef NET_INSTAWEB_UTIL_PUBLIC_FAST_WILDCARD_GROUP_H_
00020 #define NET_INSTAWEB_UTIL_PUBLIC_FAST_WILDCARD_GROUP_H_
00021 
00022 #include <vector>
00023 #include "net/instaweb/util/public/atomic_int32.h"
00024 #include "net/instaweb/util/public/basictypes.h"
00025 #include "net/instaweb/util/public/string.h"
00026 #include "net/instaweb/util/public/string_util.h"
00027 
00028 namespace net_instaweb {
00029 
00030 class Wildcard;
00031 
00051 
00094 class FastWildcardGroup {
00095  public:
00096   FastWildcardGroup()
00097       : rolling_hash_length_(kUncompiled) { }
00098   ~FastWildcardGroup();
00099 
00102   bool Match(const StringPiece& str, bool allow_by_default) const;
00103 
00106   void Allow(const StringPiece& wildcard);
00107 
00110   void Disallow(const StringPiece& wildcard);
00111 
00112   void CopyFrom(const FastWildcardGroup& src);
00113   void AppendFrom(const FastWildcardGroup& src);
00114 
00115   GoogleString Signature() const;
00116 
00117  private:
00119   static const int32 kUncompiled = -1;
00120   static const int32 kDontHash = 0;
00121 
00122   void Uncompile();
00123   void Clear();
00124   inline int& pattern_hash_index(uint64 rolling_hash) const;
00125   void Compile() const;
00126   void CompileNonTrivial() const;
00127 
00131   std::vector<Wildcard*> wildcards_;
00132   std::vector<bool> allow_; 
00133 
00135   mutable std::vector<uint64> rolling_hashes_; 
00136   mutable std::vector<int> effective_indices_; 
00137   mutable std::vector<int> wildcard_only_indices_;
00138   mutable std::vector<int> pattern_hash_index_; 
00139   mutable AtomicInt32 rolling_hash_length_;
00140 
00141   DISALLOW_COPY_AND_ASSIGN(FastWildcardGroup);
00142 };
00143 
00144 }  
00145 
00146 #endif  ///< NET_INSTAWEB_UTIL_PUBLIC_FAST_WILDCARD_GROUP_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines