Public bug reported:

The implementation of XmlNode::hash() is:

  uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const
  {
    XmlNode* node = const_cast<XmlNode*>(this);
    return hashfun::h32((void*)(&node), sizeof(node), FNV_32_INIT);
  }

Computing the hash of a pointer is pointless -- just cast the pointer:

  uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const
  {
    return reinterpret_cast<uint32_t>( this );
  }

Indeed, the std::hash() function in C++11 for T* does exactly this.

** Affects: zorba
     Importance: Low
     Assignee: Matthias Brantner (matthias-brantner)
         Status: New

** Changed in: zorba
     Assignee: (unassigned) => Matthias Brantner (matthias-brantner)

-- 
You received this bug notification because you are a member of Zorba
Coders, which is the registrant for Zorba.
https://bugs.launchpad.net/bugs/1010051

Title:
  Pointless hash function in simple store

Status in Zorba - The XQuery Processor:
  New

Bug description:
  The implementation of XmlNode::hash() is:

    uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const
    {
      XmlNode* node = const_cast<XmlNode*>(this);
      return hashfun::h32((void*)(&node), sizeof(node), FNV_32_INIT);
    }

  Computing the hash of a pointer is pointless -- just cast the pointer:

    uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const
    {
      return reinterpret_cast<uint32_t>( this );
    }

  Indeed, the std::hash() function in C++11 for T* does exactly this.

To manage notifications about this bug go to:
https://bugs.launchpad.net/zorba/+bug/1010051/+subscriptions

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to