Re: benchmark on binary trees

2015-12-06 Thread Alex via Digitalmars-d-learn
Ok, lets conclude this post for now. Did some comparison runs with the original C++ code. Missed this at the beginning. The results so far are as following: Here is the original code in C++. http://benchmarksgame.alioth.debian.org/u64q/program.php?test=binarytrees&lang=gpp&id=6 With modificatio

Re: benchmark on binary trees

2015-12-04 Thread Alex via Digitalmars-d-learn
On Friday, 4 December 2015 at 23:23:37 UTC, anonymous wrote: Why the parallel version is slower then the sequential? If you set int n = 14 in the main function the parallel version is MUCH slower then the sequential. At my machine 7x slower. Shouldn't it be the other way round? I don't know w

Re: benchmark on binary trees

2015-12-04 Thread Alex via Digitalmars-d-learn
On Friday, 4 December 2015 at 19:31:22 UTC, anonymous wrote: Why did you expect the C++ inspired version to be faster? Just because the original was written in C++? From a quick skim the two versions seem to be pretty much identical, aside from names and struct vs class. Names don't make a d

benchmark on binary trees

2015-12-04 Thread Alex via Digitalmars-d-learn
Hi everybody, this is going to be a learning by doing a benchmark test - post. Found this "game" on the web http://benchmarksgame.alioth.debian.org/u64q/performance.php?test=binarytrees and wanted to experiment on my self, I tried to reimplement some code in D. This: http://dpaste.dzfl.pl/4d8e

Re: Program exited with code -11

2015-11-26 Thread Alex via Digitalmars-d-learn
On Thursday, 26 November 2015 at 08:15:02 UTC, Rikki Cattermole wrote: You forgot to load the pointers to the functions in the shared library :) https://github.com/DerelictOrg/DerelictSFML2 OMG. I am embarrassed. Thank you very much.

Program exited with code -11

2015-11-26 Thread Alex via Digitalmars-d-learn
Hello guys. I am beginner with D and a hobbyist in general when it comes to programming. I am following an SFML tutorial in C++ and trying to "translate it" to D (at least the parts I think I understand). I am using Derelict SFML2 bindgings to CSFML. First I tried to do it procedural way and

Re: on structs by reference

2015-11-16 Thread Alex via Digitalmars-d-learn
On Monday, 16 November 2015 at 07:51:53 UTC, Ali Çehreli wrote: import std.stdio; /* This is the storage to the slices that objects will share. * * (Surprisingly, creating a slice dynamically is not possible due * to syntax issues: new int[N] means "allocates N ints and make * a slice fro

Re: on structs by reference

2015-11-14 Thread Alex via Digitalmars-d-learn
On Saturday, 14 November 2015 at 11:48:42 UTC, Mike Parker wrote: So, I create a first var of type S, then the second and copied the first into the second. The behavior is like intended, the array inside the struct is copied. But this is a deep copy, as the third block shows. If I change the a

on structs by reference

2015-11-14 Thread Alex via Digitalmars-d-learn
Hi everybody, I have the following question about "by reference" behavior related to structs. I have a struct, say S, which contains a member of reference type struct S { int[] member; } and I have a main, for testing: void main() { S s; // = new S(); s.arr = [1,2,3];

Re: opCmp with structs

2015-11-07 Thread Alex via Digitalmars-d-learn
Ok... found the solution. The technical at least. import std.algorithm; import std.range; void main(){ ku[] tt = [ku(2), ku(1)]; //writeln(tt); auto index3 = new size_t[tt.length]; makeIndex!("a.id < b.id")(tt, index3); auto ind = indexed(tt, index3);

Re: opCmp with structs

2015-11-07 Thread Alex via Digitalmars-d-learn
Found something useful, here: http://dlang.org/phobos/std_algorithm_sorting.html#makeIndex with that I can achieve the following void main(){ ku[] tt = [ku(2), ku(1)]; //writeln(tt); auto index3 = new size_t[tt.length]; makeIndex!("a.id < b.id")(tt, index3);

Re: opCmp with structs

2015-11-07 Thread Alex via Digitalmars-d-learn
On Saturday, 7 November 2015 at 14:36:25 UTC, Mike Parker wrote: So my general question is: why immutable variables shouldn't be able to be moved (inside an array)? To be pedantic, sort isn't actually moving anything. It's reassigning elements, i.e. a[1] = a[2]. The immutable member makes

Re: opCmp with structs

2015-11-07 Thread Alex via Digitalmars-d-learn
On Saturday, 7 November 2015 at 00:19:56 UTC, Ali Çehreli wrote: Continuing from your hint: So, opCmp works but it is sort() that cannot move objects of ku around because of that immutable variable. So my general question is: why immutable variables shouldn't be able to be moved (inside an a

Re: opCmp with structs

2015-11-07 Thread Alex via Digitalmars-d-learn
On Saturday, 7 November 2015 at 10:24:03 UTC, BBaz wrote: void main() { ku*[] tt = [new ku(2),new ku(1)]; sort(tt); } Don't really like this ;) not because writeln(tt); doesn't work any more, but because I have to think about where to use pointers and where not...

Re: opCmp with structs

2015-11-07 Thread Alex via Digitalmars-d-learn
Ok, ok... I see the direction, but I still miss something: From the point of view of "Programming in D", chapter 33.3, "Immutability of the slice vs the elements": I don't want to have an immutable slice but immutable elements. And your answers imply that sorting not only modify the slice its

Re: opCmp with structs

2015-11-06 Thread Alex via Digitalmars-d-learn
Ok... the question is not silly any more... without 'immutable' it works. So, what am I missing?

opCmp with structs

2015-11-06 Thread Alex via Digitalmars-d-learn
I'm sure I'm doing a silly mistake somewhere, but why this doesn't work? import std.stdio; import std.algorithm; struct ku { immutable int id; alias id this; this(int i) { id = i; } int opCmp(ref const ku rhs) cons

Re: proper range usage

2015-11-03 Thread Alex via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 22:36:21 UTC, Ali Çehreli wrote: That's fine. D's slices do that all the time: arr[0..3] and arr[3..$] seem to share index 3 but it is not the case: The first slice does not use it but the second one does. Ok... great! This is what I worried about... Aside: If

Re: proper range usage

2015-11-03 Thread Alex via Digitalmars-d-learn
... and yes, each P's M's are meant to be the same, as the associated M's in the B's class to the P. If you understand, what I mean ;)

Re: proper range usage

2015-11-03 Thread Alex via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 08:23:20 UTC, Ali Çehreli wrote: > "Programming in D" book (the revision of 2015-10-24) Oooh! That smells very fresh. :) :) > In my case, the container class can't become empty. Even if it contains > one single element, in this case the example should return tr

proper range usage

2015-11-03 Thread Alex via Digitalmars-d-learn
Hi everybody, first of all: this question is going to be unclear, because I'm lack of the "buzz word" I would like to ask about, sorry for this in advance. I try to describe the problem, where I stuck and hope somebody could think just a step further. Just a hint where to read about the way

Re: Move Semantics

2015-09-29 Thread Alex via Digitalmars-d-learn
Thank you very much for the comments. It is much clearer now. The .outer link is just a shortcut, which does not mean I don't have to reset it, where I have to. So... essentially, my expectation WAS to subjective and I have to separate better, what is the part of the model in my head and what i

Move Semantics

2015-09-29 Thread Alex via Digitalmars-d-learn
Another question on move semantics from the cheap seats... See my code here: http://dpaste.dzfl.pl/995c5af59dd6 There are indeed three questions, all marked in the code, so the rest of the text here is maybe redundant... but just in case and for summary: I try to model a inner class of some o

Re: Maximum number of threads

2015-09-24 Thread Alex via Digitalmars-d-learn
On Thursday, 24 September 2015 at 12:38:41 UTC, Temtaime wrote: Offtop: i think if number of threads > number of real cores, than there's something wrong with your design. Maybe fibers suit better ? Well... you got my idea :) So it is not so far offtop, as you think ))) Fibers DO suit better

Maximum number of threads

2015-09-24 Thread Alex via Digitalmars-d-learn
This should be a not so long question to answer, I hope. I took an example from the "Programming in D" book, chapter "Message Passing Concurrency", around page 550. The question of interest was, how many threads I can have spawned at the same time. So I made an array of robot objects from the

Re: Combining Unique type with concurrency module

2015-09-14 Thread Alex via Digitalmars-d-learn
On Monday, 14 September 2015 at 08:08:35 UTC, Ali Çehreli wrote: void main() { MultiThreadedUnique!S u1 = produce(); auto childTid2 = spawn(&spawnedFunc2, thisTid); u1.giveTo(childTid2); send(childTid2, cast(shared(MultiThreadedUnique!S*))&u1); import core.thread; thread

Re: Combining Unique type with concurrency module

2015-09-14 Thread Alex via Digitalmars-d-learn
On Monday, 14 September 2015 at 00:11:07 UTC, Ali Çehreli wrote: On 09/13/2015 09:09 AM, Alex wrote: > I'm new to this forum so, please excuse me in advance for > asking silly questions. Before somebody else says it: There are no silly questions. :) > struct std.typecons.Unique!(S).Unique is no

Combining Unique type with concurrency module

2015-09-13 Thread Alex via Digitalmars-d-learn
Hi everybody! I'm new to this forum so, please excuse me in advance for asking silly questions. I think I'm not the first person which wondering about this topic, but I'm trying to combine Unique type and concurrency module, getting the compiler error struct std.typecons.Unique!(S).Unique is

Re: Yes or No Options

2015-07-31 Thread Alex via Digitalmars-d-learn
On Thursday, 30 July 2015 at 15:14:28 UTC, Chris wrote: On Thursday, 30 July 2015 at 14:20:41 UTC, Alex wrote: My father owns a small software company, specialized in market data products. www.bccgi.com (in case anyone is interested) So programming was basically around all my life. I do a sm

Re: Yes or No Options

2015-07-30 Thread Alex via Digitalmars-d-learn
My father owns a small software company, specialized in market data products. www.bccgi.com (in case anyone is interested) So programming was basically around all my life. I do a small job in his company and my next task was to learn D. There are two trainees and the three of us have to learn

Re: Yes or No Options

2015-07-28 Thread Alex via Digitalmars-d-learn
So I now combined a few of the options here and got this, which finally works: import std.stdio; import std.string; import std.random; void main() { while (true) { string yesno; int weiter; char[] uschi; write("Press ENTER to roll the dice!");

Re: Yes or No Options

2015-07-27 Thread Alex via Digitalmars-d-learn
On Monday, 27 July 2015 at 17:31:08 UTC, Ali Çehreli wrote: On 07/27/2015 08:50 AM, Alex wrote: > a book that I bought The program looks a lot like one of the exercises in this chapter: http://ddili.org/ders/d.en/if.html You didn't actually pay for it, right? Because it is free. :) Ali

Re: Yes or No Options

2015-07-27 Thread Alex via Digitalmars-d-learn
Okay. By pure trying I found out what I did wrong: Apparently by typing Y I entered the shift key. Could that have been the problem? I changed it to a small y and it at least jumped back to the commandline instead of just being stuck. And by changing: writeln("Do you want to play again? Y/N?

Re: Yes or No Options

2015-07-27 Thread Alex via Digitalmars-d-learn
Thank you! That helped me a lot. I'm sure that - in order to get to the point to repeat the whole first part of the program - I'll have to read further in the instructions I have BUT let's just say that I don't want it to repeat the first part of the program but just writeln something like "O

Yes or No Options

2015-07-27 Thread Alex via Digitalmars-d-learn
Hey guys! I am super new to programming and still trying to learn the very basics via a book that I bought. My problem is the following: import std.stdio; import std.string; void main() { char[] yesno; write("Roll the dice: Enter a number!"); int dieNumber;

Re: Is this a bug?

2014-05-04 Thread Alex via Digitalmars-d-learn
On Sunday, 4 May 2014 at 10:28:30 UTC, Mike Parker wrote: On 5/4/2014 6:42 PM, Alex wrote: Hello, I am trying to use the std.log module that is here: https://github.com/linkrope/log.d And I encountered a segmentation fault using dmd 2.065 on a Linux 64 platform. The reduced test case is thi

Is this a bug?

2014-05-04 Thread Alex via Digitalmars-d-learn
Hello, I am trying to use the std.log module that is here: https://github.com/linkrope/log.d And I encountered a segmentation fault using dmd 2.065 on a Linux 64 platform. The reduced test case is this: // import std

<    1   2   3   4   5   6