On Wednesday, 19 June 2019 at 06:00:28 UTC, Jonathan M Davis
wrote:
On Tuesday, June 18, 2019 10:27:46 PM MDT lili via
Do you known reason for why Dlang Range are consumed by
iterating over them. I this design is strange.
If you want an overview of ranges, you can watch this:
https://www.
On Tuesday, June 18, 2019 10:27:46 PM MDT lili via Digitalmars-d-learn
wrote:
> On Tuesday, 18 June 2019 at 17:25:51 UTC, Johannes Loher wrote:
> > The result of heapify is a BinaryHeap, which is a range. writeln
> > basically prints ranges by iterating over them and printing
&
On Tuesday, 18 June 2019 at 17:25:51 UTC, Johannes Loher wrote:
The result of heapify is a BinaryHeap, which is a range. writeln
basically prints ranges by iterating over them and printing
each element
(except for the types which are special cased, such as dynamic
arrays
etc.). However, ranges
mpty());
> ~~~
> dmd v2.086.0 run all assert passed. Why?
Looking at std/container/binaryheap.d, heapify returns the type BinaryHeap
which provides the API for an input range but no toString. As such, writeln
likely uses the range API to read the elements and print them. And that's
going
t passed. Why?
The result of heapify is a BinaryHeap, which is a range. writeln
basically prints ranges by iterating over them and printing each element
(except for the types which are special cased, such as dynamic arrays
etc.). However, ranges are consumed by iterating over them, which
expl
Hi Guys:
see this code
~~~
int[] ar = [1,2,3,4,52,34,22];
auto h = heapify(ar);
assert(h.length() == ar.length);
writeln("h:",h);
assert(h.empty());
~~~
dmd v2.086.0 run all assert passed. Why?
On Tuesday, 14 November 2017 at 04:13:16 UTC, Era Scarecrow wrote:
On Monday, 13 November 2017 at 16:26:20 UTC, balddenimhero
wrote:
In the course of writing a minimal example I removed more than
necessary in the previous pastebin (the passed IntOrder has
not even been used). Thus here is the c
{
foreach(i, ref v; arr) {
a ~= E(order[i%$], &v);
}
h = BinaryHeap!(E[])(a);
}
E[] a;
BinaryHeap!(E[]) h;
// alias h this;
static struct E {
int weight;
T* v;
//alias v this;
int opCmp(E a) const {
return a.weight-weight;
}
}
}
[/code]
Ou
h the `h` member having type `BinaryHeap(int[],
"a`BinaryHeap!(int[], f)` the types do not quite match (line 18).
Maybe I'm missing something obvious or approaching this in the
wrong way. Do you have any suggestions on how to achieve the
desired result?
In case it helps, here is th
e8e44?compiler=dmd
The `Foo` class is supposed to wrap a binary heap (to be used
as priority queue) and order its contents according to
`o.isLess`. However I do not manage to initialise the according
member variable.
Obviously, with the `h` member having type `BinaryHeap(int[],
"a`BinaryHeap
to be used as
priority queue) and order its contents according to `o.isLess`.
However I do not manage to initialise the according member
variable.
Obviously, with the `h` member having type `BinaryHeap(int[],
"a`BinaryHeap!(int[], f)` the types do not quite match (line 18).
Maybe I
Oh, struct/class semantics really confuses me!
On Saturday, 30 September 2017 at 09:27:23 UTC, Shigeki Karita
wrote:
https://dpaste.dzfl.pl/cd605899d050
why this code cannot convert to foreach (over Structs and
Classes with Ranges).
auto h = new BinaryHeap!(int[])(new int[0]);
typeof(h).stringof.writeln;
static assert
https://dpaste.dzfl.pl/cd605899d050
why this code cannot convert to foreach (over Structs and Classes
with Ranges).
auto h = new BinaryHeap!(int[])(new int[0]);
typeof(h).stringof.writeln;
static assert(isInputRange!(typeof(h)));
h.insert(3);
h.insert(1);
h.insert(2
On Sunday, 9 April 2017 at 13:31:05 UTC, Michael Coulombe wrote:
This is a bug in the insert method. I created a bug report for
you and submitted a pull request for a fix:
https://issues.dlang.org/show_bug.cgi?id=17314
Ah, so it is. Thanks!!
On Sunday, 9 April 2017 at 00:36:00 UTC, TheGag96 wrote:
I'm trying to use a binary heap initialized with one element.
However, this always seems to cause a range violation for some
reason. This small example will do it:
import std.stdio, std.container;
void main() {
auto pq = heapify([5]);
I'm trying to use a binary heap initialized with one element.
However, this always seems to cause a range violation for some
reason. This small example will do it:
import std.stdio, std.container;
void main() {
auto pq = heapify([5]);
pq.insert(8);
}
...And it produces this error: https:/
What I HAD TO do to get it to compile:
programResultsQ = heapify!(compareResults,
Array!(Results!(O,I)))(Array!(Results!(O,I))([Results!(O,I)()]),
1);
programResultsQ.popFront();
What running it says:
AssertionFailure at line 381 of std.container.array.d, which
looks like:
/**
Constructor
ideas. How can I improve this declaration? Using Phobos
sometimes is such a mystery.
I mean initialization...
Here's the corresponding declaration:
alias ProgramResultsQueue(O,I) =
BinaryHeap!(Array!(Results!(O,I)), compareResults); /* module
scope */
ProgramResultsQueue
,I) =
BinaryHeap!(Array!(Results!(O,I)), compareResults);
class ProgramOptimizer(O, I)
{
ProgramResultsQueue!(O,I) programResultsQ =
heapify!(compareResults,
Array!(Results!(O,I)))(Array!(Results!(O,I)),
0);
}
void main
I've got:
alias ProgramResultsQueue(O,I) =
BinaryHeap!(Array!(Results!(O,I)), compareResults);
outside the class ProgramOptimizer. Inside the class I have:
ProgramResultsQueue!(O,I) programResultsQ =
heapify!(compareResults,
Array!(Results!(O,I)))(Array!(Results!(O,I)), 0);
at
On Sunday, 29 March 2015 at 20:05:22 UTC, Nordlöw wrote:
What's the most efficient way to extract a the storage from a
BinaryHeap and then sort it?
Is there a better way other than
binaryHeap.release.sort
than makes use of the heap property? For example
while (!binaryHeap.
What's the most efficient way to extract a the storage from a
BinaryHeap and then sort it?
Is there a better way other than
binaryHeap.release.sort
than makes use of the heap property? For example
while (!binaryHeap.empty)
{
sortedStorage ~= binaryHeap.
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
{
i
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)
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
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
I am trying to figure out how to change the value of an element
in a BinaryHeap (from std.container) and have it repositioned
such that the heap is still valid.
Can anyone help me with this? The approach I would have taken (I
think) is to remove the elements that get new values from the
heap
On Thursday, 7 November 2013 at 14:31:27 UTC, Agustin wrote:
On Thursday, 7 November 2013 at 12:29:44 UTC, bearophile wrote:
Agustin:
no property 'popFront' for type 'BinaryHeap!(uint[])'
Try to use front and removeFront (I don't know why there is
removeFront in
On Thursday, 7 November 2013 at 12:29:44 UTC, bearophile wrote:
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
I had to implement a
On Thursday, 7 November 2013 at 12:45:11 UTC, Agustin wrote:
On Thursday, 7 November 2013 at 12:29:44 UTC, bearophile wrote:
Agustin:
no property 'popFront' for type 'BinaryHeap!(uint[])'
Try to use front and removeFront (I don't know why there is
removeFront in
On Thursday, 7 November 2013 at 12:29:44 UTC, bearophile wrote:
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
Saddly i had t
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
On Thursday, 7 November 2013 at 12:14:22 UTC, Agustin wrote:
On Thursday, 7 November 2013 at 09:00:11 UTC, bearophile wrote:
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 Binar
On Thursday, 7 November 2013 at 09:00:11 UTC, bearophile wrote:
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
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
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?
Hi guys,
does anybody know how to use std.container.BinaryHepa as a growable heap?
Using T[] as Store is annoying since one has to do
T[] store = heap.release();
store ~= newElement;
heap.acquire(store);
to insert an element into the heap, as BinaryHeap is not able to append
to ranges
On 9/22/11 7:20 PM, Ellery Newcomer wrote:
Looks like a bug in Array. emplace doesn't accept a pointer to a chunk
for class types.
Report that puppy!
See
https://github.com/D-Programming-Language/phobos/commit/65a0c2158b1d2ea8e9d3094746739da636266089.
David
On 09/22/2011 06:10 AM, Cheng Wei wrote:
>
> Is this a bug or I use the binary heap wrongly? Thanks a lot!
Looks like a bug in Array. emplace doesn't accept a pointer to a chunk
for class types.
Report that puppy!
import std.container;
class T {
int i;
}
void main() {
auto array = Array!(T);
auto heap = BinaryHeap!(Array!(T), "a.i < b.i")(array);
}
After compiling:
dmd2/linux/bin32/../../src/phobos/std/container.d(1612): Error:
template std.conv.emplace(T) if (!is(T == class)) d
barring
the oddities of dynamic arrays). I've never used BinaryHeap, but glancing at
it, my guess would be that the correct solution (if you want to use Array with
it) is to create an Array and then pass its range to heapify:
Array!uint a;
//... put stuff in a.
auto heap = heapify(a[]);
I'
g., by Andrei and in the docs) that the standard
> way is combining BinaryHeap with an Array. Which is fine with me.
> Except I can't make it work. E.g., I try:
>
> Array!uint A;
> auto Q = heapify(A);
>
> The error is
>
> /path/to/phobos/std/container.d(2658):
I need a (growable) binary heap, and I'm trying to avoid writing one
myself (which isn't too hard, of course :) ... but for some reason I
can't figure out how to use Phobos to do it.
I've seen stated (e.g., by Andrei and in the docs) that the standard
way is combining Bina
On 2011-03-06 14:58:10 +0100, Magnus Lie Hetland said:
[corrected the example below, replacing int with string]
that works just fine. However, if I try
alias Tuple!(real,string) Entry;
Array!Entry Q;
then I get the following errors:
container.d(1549): Error: this for _data needs to be
On 2011-03-06 15:00:29 +0100, David Nadlinger said:
On 3/6/11 2:58 PM, Magnus Lie Hetland wrote:
alias Tuple!(real,int) Entry;
Array!Entry Q;
[...]
alias Tuple!(real,int) Entry;
Array!Entry Q;
Is it just me, or is there really no difference between the two snippets? ;)
$(WITTY_REPLY) ;-)
T
On 3/6/11 2:58 PM, Magnus Lie Hetland wrote:
alias Tuple!(real,int) Entry;
Array!Entry Q;
[…]
alias Tuple!(real,int) Entry;
Array!Entry Q;
Is it just me, or is there really no difference between the two snippets? ;)
David
thing ... when I use priority queues, I'm usually not
interested in just having a set of priorities -- the payload data is
what it's all about. So I thought I'd just use an Array of Tuples,
managed by BinaryHeap (possibly with a custom comparison, to avoid
comparing the payloads). But
Just wondering: If I want a growable binary heap (I'd be open to other
priority queue structures, for that matter ;), is the standard way in D
(w/Phobos) to combine std.container.BinaryHeap with
std.container.Array? Any reason why BinaryHeap can't deal with ordinary
dynamic array app
Matthias Walter:
> Any further ideas for this problem, or did I cover everything already?
For a C programmer the solution with pointers seems more natural, for a
Pascal-family programmer the solution with indexes seems more natural, a bit
safer (and it is probably just as fast). A third possibl
Hi all,
suppose I have an array of comparable Foo structs which I want to access
in a sorted order (e.g. a priority queue) using a BinaryHeap object (I
know that for just sorting, the BinHeap is not the right tools), but I
do not want to change the order of the objects in the original array.
I
51 matches
Mail list logo