Remarks on std.container
Matthias Walter
xammy at xammy.homelinux.net
Thu Mar 8 01:21:48 PST 2012
Hi,
I wanted to have a binary heap where I can update entries and restore
the heap structure.
1. First I observed that due to the implementation of
std.container.BinaryHeap, keeping track of the position of a certain
value in the heap cannot be done directly, but it would be helpful to
pass a "Swapper" object (or function) to the methods that may change the
order of the elements such that this Swapper is called for every swap()
operation such that the user of the BinaryHeap can keep track of the
permutation.
2. I tried to create a heap structure on my own, using
std.container.Array as a store. Of course, it I also needs to perform
swap operations, but the following did not work:
std.algorithm.swap(arrayInstance[i], arrayInstance[j]);
Also there is no usable swap() method of Array. So do I really have to
perform the swap on my own? I mean, 3 lines of code aren't that much but
I really expected an easy way.
3. For my structure I wanted to check the heap structure in an
invariant(). Unfortunately, accessing stored elements of Array is no
const operation, hence I could not implement such an invariant.
Maybe I'm not using it correctly, so any help or comments would be nice.
Best regards,
Matthias
More information about the Digitalmars-d-learn
mailing list