Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #ifndef ccnx_hash_helper_h |
| 22 | #define ccnx_hash_helper_h |
| 23 | |
| 24 | #include <string> |
| 25 | #include <boost/unordered_map.hpp> |
| 26 | #include <boost/functional/hash.hpp> |
| 27 | #include <boost/foreach.hpp> |
| 28 | |
| 29 | //size of content store |
| 30 | #define NDN_CONTENT_STORE_SIZE 100 |
| 31 | //maximum length of content name |
| 32 | #define NDN_MAX_NAME_LENGTH 30 |
| 33 | |
| 34 | //using namespace std; |
| 35 | |
| 36 | #define KEY(x) x->first |
| 37 | #define VALUE(x) x->second |
| 38 | |
| 39 | |
| 40 | /*template<typename T> |
| 41 | struct hash : public std::unary_function<T, std::size_t> { |
| 42 | std::size_t operator()(T const&) const; |
| 43 | };*/ |
| 44 | |
| 45 | struct string_hash : public std::unary_function<std::string, std::size_t> |
| 46 | { |
| 47 | inline std::size_t operator( )( std::string str ) const |
| 48 | { |
| 49 | std::size_t hash = str.size() + 23; |
| 50 | for( std::string::const_iterator it = str.begin( ); it!=str.end(); it++ ) |
| 51 | { |
| 52 | hash = ((hash << 6) ^ (hash >> 27)) + static_cast<std::size_t>( *it ); |
| 53 | } |
| 54 | |
| 55 | return boost::hash_value(hash); //hash; |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | // A collision-chaining hash table mapping strings to ints. |
| 60 | template<typename Value> |
| 61 | class string_key_hash_t : public boost::unordered_map<std::string,Value, string_hash, std::equal_to<std::string>,std::allocator<std::string> > |
| 62 | { |
| 63 | }; |
| 64 | |
| 65 | #endif |