[OT] Finding longest documents

Jarrett Billingsley jarrett.billingsley at gmail.com
Tue Oct 14 21:06:57 PDT 2008


On Tue, Oct 14, 2008 at 5:53 PM, bearophile <bearophileHUGS at lycos.com> wrote:
> Christopher Wright:
>> http://dsource.org/projects/tango/browser/trunk/tango/util/container/more/Heap.d?rev=3959
>
> Very nice, thank you. Few quick comments (no deep comments, I haven't used it nor read it carefully):
>
> In this lines:
> assert (other.pop is 4);
>
> I think it's better to use
> assert(other.pop == 4);
>
>
> This lines show that a bulk addition method may be useful, that accepts any lazy/eagar iterable:
> MaxHeap!(uint) h;
> h ~= 1;
> h ~= 3;
> h ~= 2;
> h ~= 4;
>
>
> The following aliases can be moved just below their respective methods, with a /// ditto before them:
> alias pop       remove;
> alias push      opCatAssign;
>
>
> This style of comments:
> /** Inserts all elements in the given array into the heap. */
>
> Can sometimes be replaced by:
> /// Inserts all elements in the given array into the heap.
>
>
> The class ddoc misses the explanation for the Min template argument:
> struct Heap(T, bool Min) {
>
>
> Some lines of comments are too much long, they may be broken at 80-95 chars long.
>
>
> An optional 'key' callable can be added; it can be used as sorting key mapper (Swartz-style). If not specified it can be "null" that means the current behaviour.
>
>
> Few other handy methods may be added:
>
> A merge() (~ and ~=) method can be added, maybe.
>
> heapreplace(heap, item) (pop and return the smallest item from the heap, and also push the new item. The heap size doesn't change)
>
> heapify(iterable)
> nlargest(n, iterable)
> nsmallest(n, iterable)
>
>
> The following is not a critic, just a note, I think programs with such low code density are harder to read to me, they seem like fresh snow:
>
> /** Inserts all elements in the given array into the heap. */
> void push (T[] array)
> {
>        while (heap.length < next + array.length)
>        {
>                heap.length = 2 * heap.length + 32;
>        }
>        foreach (t; array) push (t);
> }
>
>
> I'd write that as this, allowing me to have more code on the screen:
>
> /// Inserts all elements in the given array into the heap.
> void push(T[] array) {
>    while (heap.length < next + array.length)
>        heap.length = 2 * heap.length + 32;
>    foreach (t; array)
>        push(t);
> }
>

Bearophile, you're doing it again.  Why are you so hung up on how
other people format their code?  Please, please get over it.



More information about the Digitalmars-d mailing list