00001 00002 /* 00003 | Author: Michael Schmidt; 00004 | Gunnar Jehl 00005 | 00006 | ************************* SOFTWARE LICENSE AGREEMENT *********************** 00007 | This source code is published under the BSD License. 00008 | 00009 | See file 'LICENSE.txt' that comes with this distribution or 00010 | http://dbis.informatik.uni-freiburg.de/index.php?project=GCX/license.php 00011 | for the full license agreement. 00012 | 00013 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00014 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00015 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00016 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00017 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00018 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00019 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00020 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00021 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00022 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00023 | POSSIBILITY OF SUCH DAMAGE. 00024 | **************************************************************************** 00025 */ 00026 00035 #ifndef STRINGHASH_H 00036 #define STRINGHASH_H 00037 00038 #include <vector> 00039 00044 #define HASH_BASE 31 00045 00047 using namespace std; 00048 00057 struct TagInfo { 00063 TagInfo(const char *_tag, unsigned _index):tag(_tag), 00064 index(_index) { 00065 } ~TagInfo() { 00069 delete[]tag; 00070 } 00071 00076 const char *tag; 00077 00083 unsigned index; 00084 }; 00085 00094 class StringHash { 00095 00096 public: 00100 StringHash(); 00101 00105 virtual ~ StringHash(); 00106 00113 unsigned hash(const char *s); 00114 00123 unsigned hash(const char *s, unsigned start_offset, unsigned end_offset); 00124 00125 private: 00133 unsigned h(const char *s); 00134 00144 unsigned h(const char *s, unsigned start_offset, unsigned end_offset); 00145 00151 int base; 00152 00158 vector < TagInfo * >*matches; 00159 00164 unsigned free_index; 00165 }; 00166 00167 #endif // STRINGHASH_H