blob: 36a9ee8aa5a45ad2a3ea1fc6a33c6d94aa282755 [file] [log] [blame]
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -07001/* -*- 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
Alexander Afanasyev070aa482011-08-20 00:38:25 -070021#ifndef CCNX_HASH_HELPER_H
22#define CCNX_HASH_HELPER_H
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070023
24#include <string>
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070025#include <boost/foreach.hpp>
Alexander Afanasyev070aa482011-08-20 00:38:25 -070026#include "name-components.h"
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070027
Alexander Afanasyev070aa482011-08-20 00:38:25 -070028namespace ns3
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070029{
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070030
Alexander Afanasyev070aa482011-08-20 00:38:25 -070031/**
32 * \ingroup ccnx-helpers
33 * \brief Helper providing hash value for the name prefix
34 *
35 * The whole prefix is considered as a long string with '/' delimiters
36 *
37 * \todo Testing is required to determine if this hash function
38 * actually provides good hash results
39 */
40struct CcnxPrefixHash : public std::unary_function<Name::Components, std::size_t>
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070041{
Alexander Afanasyev070aa482011-08-20 00:38:25 -070042 std::size_t
43 operator() (const Name::Components &prefix) const
44 {
45 std::size_t hash = 23;
46 BOOST_FOREACH (const std::string &str, prefix.GetComponents ())
47 {
48 hash += str.size ();
49 hash = ((hash << 6) ^ (hash >> 27)) + '/';
50 BOOST_FOREACH (char c, str)
51 {
52 hash = ((hash << 6) ^ (hash >> 27)) + c;
53 }
54 }
55 return hash;
56 }
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070057};
Alexander Afanasyev070aa482011-08-20 00:38:25 -070058
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// };
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070064
Alexander Afanasyev070aa482011-08-20 00:38:25 -070065} // namespace ns3
66
67#endif // CCNX_HASH_HELPER_H