Remarks on std.container

Ellery Newcomer ellery-newcomer at utulsa.edu
Thu Mar 8 07:18:27 PST 2012



On 03/08/2012 03:21 AM, Matthias Walter wrote:
> Hi,
>
> I wanted to have a binary heap where I can update entries and restore
> the heap structure.
>

<shameless plug>

I totally built this functionality in to multi_index's red black tree, 
hash table, and heap indeces.

-------------------------------------------------
alias MultiIndexContainer!(int, IndexedBy!(Heap!())) C1;

C1 c = new C1;
c.insert([1,2,3,4,5]);

auto rng = c[];

<point rng to item you want>

// modify the value, then heap is restored by container
c.modify(rng, (ref int i){ i = 42; });
-------------------------------------------------

If you have a more complicated type, you can also set up a signals and 
slots thing so you can keep a reference to your object and modify it and 
the container will automatically fix the heap without you having to use 
modify.

I also started on converting ranges from one index to ranges of another 
for e.g. using a hash table to reference your value/object, but I'm 
waiting on compiler bugs.

</shameless plug>


More information about the Digitalmars-d-learn mailing list