digitalmars.D.learn - Problem Instantiating a BinaryHeap with a Comparison Function the
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (9/9) Feb 19 2015 I can understand how to correctly define an instance of
- Gary Willoughby (13/22) Feb 19 2015 I don't know if the lambda form can access the outer scope. Try
- Tobias Pankrath (18/19) Feb 19 2015 On Thursday, 19 February 2015 at 11:56:19 UTC, Nordlöw wrote:
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (9/28) Feb 19 2015 I modified my algorithm to be more like
I can understand how to correctly define an instance of BinaryHeap in my class DijkstraWalker at https://github.com/nordlow/justd/blob/master/knet/traversal.d#L264 because the comparsion function can't ge access to the class member distMap I get the error need 'this' for 'distMap' of type 'Tuple!(double, Ref!(Node))[Ref!(Node)]' What to do?
Feb 19 2015
On Thursday, 19 February 2015 at 11:56:19 UTC, Nordlöw wrote:I can understand how to correctly define an instance of BinaryHeap in my class DijkstraWalker at https://github.com/nordlow/justd/blob/master/knet/traversal.d#L264 because the comparsion function can't ge access to the class member distMap I get the error need 'this' for 'distMap' of type 'Tuple!(double, Ref!(Node))[Ref!(Node)]' What to do?I don't know if the lambda form can access the outer scope. Try different forms for the comparer: auto comparer = delegate (a, b) { return this.distMap[a][0] < this.distMap[b][0]; } BinaryHeap!(Nds, comparer) pendingNds; or BinaryHeap!(Nds, "this.distMap[a][0] < this.distMap[b][0]") pendingNds; Caveat: this is off the top of my head and no way even tested or read the docs. :)
Feb 19 2015
On Thursday, 19 February 2015 at 11:56:19 UTC, Nordlöw wrote: Please provide reduced examples. This fails: class C { int[] a; alias BH = BinaryHeap!(int[], (x, y) => (x+a < y)); } This works: class C { int[] a; void foo() { alias BH = BinaryHeap!(int[], (x, y) => (x+a < y)); } } But will create an instance of BinaryHeap per member function.What to do?Dunno.
Feb 19 2015
On Thursday, 19 February 2015 at 14:12:51 UTC, Tobias Pankrath wrote:On Thursday, 19 February 2015 at 11:56:19 UTC, Nordlöw wrote: Please provide reduced examples. This fails: class C { int[] a; alias BH = BinaryHeap!(int[], (x, y) => (x+a < y)); } This works: class C { int[] a; void foo() { alias BH = BinaryHeap!(int[], (x, y) => (x+a < y)); } } But will create an instance of BinaryHeap per member function.I modified my algorithm to be more like http://rosettacode.org/wiki/Dijkstra%27s_algorithm#D which doesn't require a special comparison function for RedBlackTree. See update at: https://github.com/nordlow/justd/blob/master/knet/traversal.d#L108 Thanks anyway.What to do?Dunno.
Feb 19 2015