Port a benchmark to D?

Timon Gehr timon.gehr at gmx.ch
Fri Jun 3 13:38:47 PDT 2011


bearophile wrote:
> Timon Gehr:
>
>> have you already noticed how incredibly stupid some parts of the implementation
of cpp are?
>
> Some of those "stupid" things come from the very strict Google C++ coding
standards.

sure? Eg.

  UnionFindNode *FindSet() {
    typedef std::list<UnionFindNode *> NodeListType;
    NodeListType nodeList;

    UnionFindNode *node = this;
    while (node != node->parent()) {
      if (node->parent() != node->parent()->parent())
        nodeList.push_back(node);
      node = node->parent();
    }

    // Path Compression, all nodes' parents point to the 1st level parent.
    NodeListType::iterator iter = nodeList.begin();
    NodeListType::iterator end  = nodeList.end();
    for (; iter != end; ++iter)
      (*iter)->set_parent(node->parent());

    return node;
  }

They create a new linked list of nodes on the way to the root. It is not that that
is just basically the same they already had when following the parent pointers.
They obviously need a copy.
Also, they made sure that node==node->parent(). (node is the a root) But then they
call node->parent(). etc...

Timon


More information about the Digitalmars-d mailing list