digitalmars.D.learn - BinaryHeap
- Agustin (3/3) Nov 06 2013 I'm trying to use BinaryHeap and i found out that i cannot use
- bearophile (6/9) Nov 07 2013 Please show the code :-)
- Agustin (7/16) Nov 07 2013 BinaryHeap!(uint[]) heap;
- Agustin (9/29) Nov 07 2013 It seems that i need to have a pointer to the underlying array.
- bearophile (5/6) Nov 07 2013 Try to use front and removeFront (I don't know why there is
- Agustin (12/18) Nov 07 2013 Saddly i had to do this
- Agustin (3/24) Nov 07 2013 By looking at the source, having "private @property ref Store
- Agustin (10/16) Nov 07 2013 I had to implement a custom IterableBinaryHeap implementation.
- Agustin (6/25) Nov 27 2013 The above code was working until i upgrade to DMD32 D Compiler
I'm trying to use BinaryHeap and i found out that i cannot use foreach(). My question is, there is any other way to do it?, can i iterate a BinaryHeap?
Nov 06 2013
Agustin:I'm trying to use BinaryHeap and i found out that i cannot use foreach(). My question is, there is any other way to do it?, can i iterate a BinaryHeap?Please show the code :-) Perhaps you need to look at the head, pop the head item, look at the head, etc. Bye, bearophile
Nov 07 2013
On Thursday, 7 November 2013 at 09:00:11 UTC, bearophile wrote:Agustin:BinaryHeap!(uint[]) heap; foreach(type; heap) { .... } no property 'popFront' for type 'BinaryHeap!(uint[])'I'm trying to use BinaryHeap and i found out that i cannot use foreach(). My question is, there is any other way to do it?, can i iterate a BinaryHeap?Please show the code :-) Perhaps you need to look at the head, pop the head item, look at the head, etc. Bye, bearophile
Nov 07 2013
On Thursday, 7 November 2013 at 12:14:22 UTC, Agustin wrote:On Thursday, 7 November 2013 at 09:00:11 UTC, bearophile wrote:It seems that i need to have a pointer to the underlying array. uint[] intArray; BinaryHeap!(uint[]) heap; heap.acquire(intArray); foreach(int; intArray) { .... }Agustin:BinaryHeap!(uint[]) heap; foreach(type; heap) { .... } no property 'popFront' for type 'BinaryHeap!(uint[])'I'm trying to use BinaryHeap and i found out that i cannot use foreach(). My question is, there is any other way to do it?, can i iterate a BinaryHeap?Please show the code :-) Perhaps you need to look at the head, pop the head item, look at the head, etc. Bye, bearophile
Nov 07 2013
Agustin:no property 'popFront' for type 'BinaryHeap!(uint[])'Try to use front and removeFront (I don't know why there is removeFront instead of popFront). Bye, bearophile
Nov 07 2013
On Thursday, 7 November 2013 at 12:29:44 UTC, bearophile wrote:Agustin:Saddly i had to do this auto clone = _heap.dup; while (!clone.empty()) { auto item = clone.front(); // ... Do something with item clone.removeFront(); } Iterate directly over a binary heap will be better perfomance wise than doing that because i had to clone the heap to be able to iterate over without removing items from the original heap.no property 'popFront' for type 'BinaryHeap!(uint[])'Try to use front and removeFront (I don't know why there is removeFront instead of popFront). Bye, bearophile
Nov 07 2013
On Thursday, 7 November 2013 at 12:45:11 UTC, Agustin wrote:On Thursday, 7 November 2013 at 12:29:44 UTC, bearophile wrote:By looking at the source, having "private property ref Store _store()" public will help a lot.Agustin:Saddly i had to do this auto clone = _heap.dup; while (!clone.empty()) { auto item = clone.front(); // ... Do something with item clone.removeFront(); } Iterate directly over a binary heap will be better perfomance wise than doing that because i had to clone the heap to be able to iterate over without removing items from the original heap.no property 'popFront' for type 'BinaryHeap!(uint[])'Try to use front and removeFront (I don't know why there is removeFront instead of popFront). Bye, bearophile
Nov 07 2013
On Thursday, 7 November 2013 at 12:29:44 UTC, bearophile wrote:Agustin:I had to implement a custom IterableBinaryHeap implementation. http://pastebin.com/GeVAeCch IterableBinaryHeap!(Array!uint, "a < b") heap; heap.insert(0); heap.insert(3); heap.insert(2); heap.insert(1); foreach(item; heap) writeln(item);no property 'popFront' for type 'BinaryHeap!(uint[])'Try to use front and removeFront (I don't know why there is removeFront instead of popFront). Bye, bearophile
Nov 07 2013
On Thursday, 7 November 2013 at 14:31:27 UTC, Agustin wrote:On Thursday, 7 November 2013 at 12:29:44 UTC, bearophile wrote:The above code was working until i upgrade to DMD32 D Compiler v2.064. Now i got: "Error: cannot uniquely infer foreach argument types" Help!Agustin:I had to implement a custom IterableBinaryHeap implementation. http://pastebin.com/GeVAeCch IterableBinaryHeap!(Array!uint, "a < b") heap; heap.insert(0); heap.insert(3); heap.insert(2); heap.insert(1); foreach(item; heap) writeln(item);no property 'popFront' for type 'BinaryHeap!(uint[])'Try to use front and removeFront (I don't know why there is removeFront instead of popFront). Bye, bearophile
Nov 27 2013