src/core/model/hash.cc
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Tue, 13 Nov 2012 16:32:31 -0800
branchhash
changeset 9928 f88602ff0540
parent 9925 660fc4dd2e05
child 9929 3e8510caf03a
permissions -rw-r--r--
Fix Hash (Ptr<HashFunc>) implementation, check for null m_impl, add test cases
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
Hash::Hash ()
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    34
{
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    35
  m_impl = Create <HashImplNS::Murmur3> ();
9928
f88602ff0540 Fix Hash (Ptr<HashFunc>) implementation, check for null m_impl, add test cases
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9925
diff changeset
    36
  NS_ASSERT (m_impl != 0);
9924
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    37
}
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
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
    40
  : m_impl(hp)
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    41
{
9928
f88602ff0540 Fix Hash (Ptr<HashFunc>) implementation, check for null m_impl, add test cases
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9925
diff changeset
    42
  NS_ASSERT (m_impl != 0);
9924
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
  
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    46
/*************************************************
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    47
 **  class HashImplementation
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
9925
660fc4dd2e05 Use Hash32_t, Hash64_t typedefs to indicate that hashes are opaque.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9924
diff changeset
    50
Hash::Hash64_t
9924
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    51
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
    52
{
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    53
  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
    54
  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
    55
}
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    56
d5a552660be9 General hash interface, with replaceable hash functions, defaults to murmur3.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
diff changeset
    57
} // namespace ns3