Joseph Rushton Wakeling:

http://braingam.es/2013/07/complex-networks-in-d/

    size_t vertexCount() @property const pure nothrow
    {
        assert(_sumHead.length == _sumTail.length);
        return _sumHead.length - 1;
    }

Is that better written in a struct/class invariant?


        size_t degreeIn(immutable size_t v) const pure nothrow
        {
            assert(v + 1 < _sumTail.length);
            return _sumTail[v + 1] - _sumTail[v];
        }

Here you are looking for the method pre-condition.

And "in size_t v" is enough compared to "immutable size_t v".


auto neighbours(immutable size_t v) const
{
return chain(map!(a => _tail[_indexHead[a]])(iota(_sumHead[v], _sumHead[v + 1])), map!(a => _head[_indexTail[a]])(iota(_sumTail[v], _sumTail[v + 1])));
}

For such kind of code I suggest to use UFCS chains.
Also be careful with the performance of such range-based code, writing benchmarks. Unfortunately often DMD doesn't compile it efficiently.

Bye,
bearophile

Reply via email to