src/core/model/hash.cc
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Tue, 13 Nov 2012 16:24:59 -0800
branchhash
changeset 9924 d5a552660be9
child 9925 660fc4dd2e05
permissions -rw-r--r--
General hash interface, with replaceable hash functions, defaults to murmur3.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9924
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
     2
/*
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
     3
 * Copyright (c) 2012 Lawrence Livermore National Laboratory
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
     4
 *
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
     8
 *
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    12
 * GNU General Public License for more details.
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    13
 *
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    17
 *
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    18
 * Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    19
 */
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    20
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    21
#include "ns3/hash.h"
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    22
#include "ns3/log.h"
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    23
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    24
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    25
namespace ns3 {
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    26
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    27
NS_LOG_COMPONENT_DEFINE ("Hash");
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    28
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    29
/*************************************************
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    30
 **  class Hash
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    31
 ************************************************/
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    32
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    33
TypeId
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    34
Hash::GetTypeId (void)
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    35
{
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    36
  static TypeId tid = TypeId ("ns3::Hash");
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    37
  return tid;
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    38
}
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    39
  
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    40
Hash::Hash ()
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    41
{
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    42
  m_impl = Create <HashImplNS::Murmur3> ();
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    43
}
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    44
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    45
Hash::Hash (Ptr<HashImplementation> hp)
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    46
  : m_impl(hp)
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    47
{
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    48
}
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    49
  
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    50
  
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    51
/*************************************************
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    52
 **  class HashImplementation
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    53
 ************************************************/
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    54
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    55
uint64_t
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    56
HashImplementation::GetHash64  (const char * buffer, const size_t size)
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    57
{
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    58
  NS_LOG_WARN("64-bit hash requested, only 32-bit implementation available");
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    59
  return GetHash32 (buffer, size);
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    60
}
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    61
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    62
} // namespace ns3