Re: Overloading Based on Constraints

2015-07-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/23/15 5:58 PM, jmh530 wrote: I was looking at http://dlang.org/concepts.html where it discusses overloading templates based on constraints. I wanted to try to overload a template function with another version that does everything in place. So basically, one has a return and the other

Re: Converting uint[] slice to string for the purpose of hashing?

2015-07-23 Thread Enjoys Math via Digitalmars-d-learn
On Thursday, 23 July 2015 at 11:49:05 UTC, cym13 wrote: On Thursday, 23 July 2015 at 11:15:46 UTC, Enjoys Math wrote: 1. Is the best way to hash a uint[] slice 2. How do you do it? IIRC, std.digest functions take ubyte[] as input, so to hash a uint[] I would do the following: void

Re: Converting uint[] slice to string for the purpose of hashing?

2015-07-23 Thread Enjoys Math via Digitalmars-d-learn
On Thursday, 23 July 2015 at 12:10:04 UTC, Enjoys Math wrote: On Thursday, 23 July 2015 at 11:49:05 UTC, cym13 wrote: [...] Thanks. That worked. Here's my code: module hashtools; import std.conv; import std.digest.md; string uintSliceToHash(const uint[] slice) { auto md5 = new

Converting uint[] slice to string for the purpose of hashing?

2015-07-23 Thread Enjoys Math via Digitalmars-d-learn
1. Is the best way to hash a uint[] slice 2. How do you do it?

Re: Converting uint[] slice to string for the purpose of hashing?

2015-07-23 Thread cym13 via Digitalmars-d-learn
On Thursday, 23 July 2015 at 11:15:46 UTC, Enjoys Math wrote: 1. Is the best way to hash a uint[] slice 2. How do you do it? IIRC, std.digest functions take ubyte[] as input, so to hash a uint[] I would do the following: void main(string[] args) { import std.conv;

Re: Converting uint[] slice to string for the purpose of hashing?

2015-07-23 Thread Temtaime via Digitalmars-d-learn
All types are hashable and for your own structs and classes you can redefine opHash

How do you make a copy TO and object when you're INSIDE of it?

2015-07-23 Thread Enjoys Math via Digitalmars-d-learn
Here's my code: module grammar; class Grammar(T : ulong) { this(const T[] str) { auto grammar = str in grammarCache; if (grammar) { this = grammar.dup; } else { this = approximateSmallestGrammar(str); grammarCache[str] = this.dup;

Re: How do you make a copy TO and object when you're INSIDE of it?

2015-07-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/23/15 9:30 PM, Enjoys Math wrote: Here's my code: module grammar; class Grammar(T : ulong) { this(const T[] str) { auto grammar = str in grammarCache; if (grammar) { this = grammar.dup; } else { this =

Re: How do you make a copy TO and object when you're INSIDE of it?

2015-07-23 Thread Enjoys Math via Digitalmars-d-learn
On Friday, 24 July 2015 at 03:12:43 UTC, Steven Schveighoffer wrote: On 7/23/15 9:30 PM, Enjoys Math wrote: [...] You're approaching this wrong. Do the lookup before deciding whether to instantiate a new object: static Grammar getGrammar(const T[] str) { if(auto x = str in

Re: Measuring Execution time

2015-07-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 23, 2015 13:59:11 Steven Schveighoffer via Digitalmars-d-learn wrote: On 7/22/15 5:23 AM, Clayton wrote: How does one represent Duration in only Micro-seconds, or milliseconds. Trying to measure the execution time of an algorithm and I get 4 ms, 619 μs, and 8 hnsecs , I

Re: How do you make a copy TO and object when you're INSIDE of it?

2015-07-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, July 24, 2015 01:30:55 Enjoys Math via Digitalmars-d-learn wrote: Here's my code: module grammar; class Grammar(T : ulong) { this(const T[] str) { auto grammar = str in grammarCache; if (grammar) { this = grammar.dup; } else {

Overloading Based on Constraints

2015-07-23 Thread jmh530 via Digitalmars-d-learn
I was looking at http://dlang.org/concepts.html where it discusses overloading templates based on constraints. I wanted to try to overload a template function with another version that does everything in place. So basically, one has a return and the other doesn't. However, when I run the code,

Re: Converting uint[] slice to string for the purpose of hashing?

2015-07-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 23, 2015 12:56:13 Temtaime via Digitalmars-d-learn wrote: All types are hashable and for your own structs and classes you can redefine opHash It's toHash, actually, but yeah. - Jonathan M Davis

Re: How to get *32mscoff libraries for phobos?

2015-07-23 Thread Taylor Hillegeist via Digitalmars-d-learn
On Thursday, 23 July 2015 at 01:43:56 UTC, Mike Parker wrote: On Thursday, 23 July 2015 at 01:39:05 UTC, Mike Parker wrote: post at [1] where Rainer shared the relevant bits of a batch Gah, hate it when I forget the links. [1] http://forum.dlang.org/post/m456t5$2jc4$1...@digitalmars.com

Re: Sending an immutable object to a thread

2015-07-23 Thread Frank Pagliughi via Digitalmars-d-learn
On Thursday, 23 July 2015 at 09:05:12 UTC, Marc Schütz wrote: It is not safe, but for a different reason: `mt` is already a _reference_ to the actual object (that's how classes behave in D). This reference is located in a register or on the stack, and `mt` is therefore a pointer into the

Re: C bindings: typedef struct conflicts with method

2015-07-23 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-07-23 03:57, Mike Parker wrote: In your case, rd_kafka_metadata is the name of the struct, but in C instances would need to be declared like so: struct rd_kafka_metadata instance; Since the struct is declared directly in the typedef, is the struct name actually available? --

Re: How to get *32mscoff libraries for phobos?

2015-07-23 Thread Taylor Hillegeist via Digitalmars-d-learn
On Thursday, 23 July 2015 at 15:39:15 UTC, Taylor Hillegeist wrote: On Thursday, 23 July 2015 at 15:23:07 UTC, Taylor Hillegeist wrote: I found this nugget in the sc.ini file! [Environment32mscoff] LIB=%@P%\..\lib32mscoff Apparently i need to create a lib32mscoff folder in C:\D\dmd2\windows\

Re: How to get *32mscoff libraries for phobos?

2015-07-23 Thread Taylor Hillegeist via Digitalmars-d-learn
On Thursday, 23 July 2015 at 14:56:48 UTC, Taylor Hillegeist wrote: On Thursday, 23 July 2015 at 01:43:56 UTC, Mike Parker wrote: [...] IT worked! Placing this Batch file in the dmd2\src Folder. -- BEGIN FILE: BUILD.bat set

Re: How to get *32mscoff libraries for phobos?

2015-07-23 Thread Taylor Hillegeist via Digitalmars-d-learn
On Thursday, 23 July 2015 at 15:23:07 UTC, Taylor Hillegeist wrote: I found this nugget in the sc.ini file! [Environment32mscoff] LIB=%@P%\..\lib32mscoff Apparently i need to create a lib32mscoff folder in C:\D\dmd2\windows\ Well if its not one thing its always another :) LINK : fatal

Re: Measuring Execution time

2015-07-23 Thread Clayton via Digitalmars-d-learn
On Wednesday, 22 July 2015 at 09:32:15 UTC, John Colvin wrote: On Wednesday, 22 July 2015 at 09:23:36 UTC, Clayton wrote: [...] The normal way of doing this would be using std.datetime.StopWatch: StopWatch sw; sw.start(); algorithm(); long exec_ms = sw.peek().msecs; Am

Re: Passing struct and struct[] into a template

2015-07-23 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 22 July 2015 at 04:29:26 UTC, Taylor Gronka wrote: Hi, I have a template function, and I want it to do something if the input variable is a list of structs, and something else if the input is a struct. [...] Take a look at this thread, the poster had the same question:

Re: Measuring Execution time

2015-07-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/22/15 5:23 AM, Clayton wrote: How does one represent Duration in only Micro-seconds, or milliseconds. Trying to measure the execution time of an algorithm and I get 4 ms, 619 μs, and 8 hnsecs , I want to sum all these and get total hnsecs or μs . I would also appreciate advise on whether

Re: C bindings: typedef struct conflicts with method

2015-07-23 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 23 July 2015 at 06:26:28 UTC, Jacob Carlborg wrote: On 2015-07-23 03:57, Mike Parker wrote: In your case, rd_kafka_metadata is the name of the struct, but in C instances would need to be declared like so: struct rd_kafka_metadata instance; Since the struct is declared directly

Re: Getting this to work similar to self in Python

2015-07-23 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-07-23 00:22, nurfz wrote: I think you got overly complicated answers. I guess I'm confused as to why the D code isn't acting similar to the Python code in the sense that you would expect this to reference the speed property of the current instance and not statically reference the

Re: Getting this to work similar to self in Python

2015-07-23 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 22 July 2015 at 22:52:22 UTC, John Colvin wrote: On Wednesday, 22 July 2015 at 22:22:02 UTC, nurfz wrote: [...] Fields of classes are not in any way polymorphic in D (this is the same as C++ and I think java too). Base class members can be accessed like so: class Vehicle {

Re: Thread pools

2015-07-23 Thread Chris via Digitalmars-d-learn
On Wednesday, 22 July 2015 at 17:01:52 UTC, Marc Schütz wrote: You can probably simply terminate the main thread, which will send an OwnerTerminated message to all dependent threads. The threads need to `receive()` this message and terminate. Not possible here. Main has to run the all the

Re: Sending an immutable object to a thread

2015-07-23 Thread via Digitalmars-d-learn
On Wednesday, 22 July 2015 at 17:17:17 UTC, Frank Pagliughi wrote: Or, to put it another way, getting threads out of the equation, is this safe? class MyThing { ... } MyThing* create_a_thing() { MyThing mt = new MyThing(); do_something_with(mt); return mt; } void main() {

Re: Thread pools

2015-07-23 Thread Chris via Digitalmars-d-learn
On Wednesday, 22 July 2015 at 16:16:36 UTC, John Colvin wrote: I would send a message to terminate to thread1, which would in turn send a similar message to any threads it has started, wait until they've all stopped (maybe with a time-out), then return. I.e. every thread knows how to