Re: Need for speed

2021-04-02 Thread Nestor via Digitalmars-d-learn
On Thursday, 1 April 2021 at 19:38:39 UTC, H. S. Teoh wrote: On Thu, Apr 01, 2021 at 04:52:17PM +, Nestor via Digitalmars-d-learn wrote: [...] [...] Since the length of the array is already known beforehand, you could get significant speedups by preallocating the array

Need for speed

2021-04-01 Thread Nestor via Digitalmars-d-learn
I am a python programmer and I am enjoying Dlang and learning some programming insights on the way, thank everyone. I have no formal education and also program JS and PHP. Watching a video where a guy programs some simple code in Python and the same code in Go and compares speed I thought

Re: Can this implementation of Damm algorithm be optimized?

2017-02-12 Thread Nestor via Digitalmars-d-learn
On Sunday, 12 February 2017 at 05:54:34 UTC, Era Scarecrow wrote: On Saturday, 11 February 2017 at 21:56:54 UTC, Era Scarecrow wrote: Just ran the unittests under the dmd profiler, says the algorithm is 11% faster now. So yeah slightly more optimized. Ran some more tests. Without

Re: Can this implementation of Damm algorithm be optimized?

2017-02-11 Thread Nestor via Digitalmars-d-learn
On Saturday, 11 February 2017 at 21:41:11 UTC, Era Scarecrow wrote: On Saturday, 11 February 2017 at 21:02:40 UTC, Era Scarecrow wrote: Yes i know, which is why i had 3 to calculate 2 inputs because the third is the temp/previous calculation. Alright I've found the bug and fixed it, and it

Re: Can this implementation of Damm algorithm be optimized?

2017-02-11 Thread Nestor via Digitalmars-d-learn
On Saturday, 11 February 2017 at 11:45:02 UTC, Era Scarecrow wrote: On Friday, 10 February 2017 at 11:27:02 UTC, Nestor wrote: Thank you for the detailed reply. I wasn't able to follow you regarding the multilevel stuff though :( The idea behind it is like this (which you can scale up):

Re: Can this implementation of Damm algorithm be optimized?

2017-02-10 Thread Nestor via Digitalmars-d-learn
On Thursday, 9 February 2017 at 23:49:19 UTC, Era Scarecrow wrote: Other optimizations could be to make it multiple levels, taking the basic 100 elements and expanding them 2-3 levels deep in a lookup and having it do it in more or less a single operation. (100 bytes for 1 level, 10,000 for 2

Re: Can this implementation of Damm algorithm be optimized?

2017-02-09 Thread Nestor via Digitalmars-d-learn
On Thursday, 9 February 2017 at 21:43:08 UTC, Daniel Kozak wrote: Any idea of what might be happening here? Did you try it with different backends? llvm (ldc), gcc(gdc)? Not really, just standard dmd. I tried running each algoritm a few times through avgtime using different digit lengths

Re: Can this implementation of Damm algorithm be optimized?

2017-02-09 Thread Nestor via Digitalmars-d-learn
On Thursday, 9 February 2017 at 20:46:06 UTC, Daniel Kozak wrote: Maybe you can try use static array instead of dynamic static immutable ubyte[10][10] QG10Matrix = ... I shaved it to this to discard unneccessary time-consuming functions: static immutable ubyte[10][10] QG10Matrix = [

Re: Can this implementation of Damm algorithm be optimized?

2017-02-09 Thread Nestor via Digitalmars-d-learn
On Thursday, 9 February 2017 at 18:34:30 UTC, Era Scarecrow wrote: ... Actually since you're also multiplying by 10, you can incorporate that in the table too... I forgot to comment that what is multiplied by ten is not the value but the starting position in the array (a way to emulate a

Re: Can this implementation of Damm algorithm be optimized?

2017-02-09 Thread Nestor via Digitalmars-d-learn
On Thursday, 9 February 2017 at 18:34:30 UTC, Era Scarecrow wrote: On Thursday, 9 February 2017 at 17:36:11 UTC, Nestor wrote: I was trying to port C code from the article in Wikiversity [1] to D, but I'm not sure this implementation is the most efficient way to do it in D, so suggestions to

Can this implementation of Damm algorithm be optimized?

2017-02-09 Thread Nestor via Digitalmars-d-learn
Hi, I was trying to port C code from the article in Wikiversity [1] to D, but I'm not sure this implementation is the most efficient way to do it in D, so suggestions to optimize it are welcome: import std.stdio; static immutable char[] QG10Matrix =

Implementation of B+ trees

2017-02-08 Thread Nestor via Digitalmars-d-learn
Hi, Is there a native D implementation of B+ tree anywhere? So far I have found only std.container.rbtree but I wanted to compare both algorithms regarding search performance, memory and cpu usage, and storage space required for serialization. Thanks in advance.

Re: embedding a library in Windows

2017-01-30 Thread Nestor via Digitalmars-d-learn
On Monday, 30 January 2017 at 16:40:47 UTC, biozic wrote: As an alternative, you could build an object file from Sqlite's source code (e.g. the amalgamation file from Sqlite's website) with a C compiler. Then you just build your D application with: dmd app.d sqlite3.d sqlite3.o[bj] No dll.

Re: embedding a library in Windows

2017-01-30 Thread Nestor via Digitalmars-d-learn
On Monday, 30 January 2017 at 13:58:45 UTC, Adam D. Ruppe wrote: On Monday, 30 January 2017 at 13:29:20 UTC, Nestor wrote: OK, and in case I have a sqlite3.a file Just pass the sqlite3.a file instead of sqlite3.lib and the compiler should do the rest... worst case is you might need to edit

Re: embedding a library in Windows

2017-01-30 Thread Nestor via Digitalmars-d-learn
On Monday, 30 January 2017 at 13:22:45 UTC, Kagamin wrote: In general case the library can depend on it being a dll, then it can't be linked statically. OK, and in case I have a sqlite3.a file, what parameters should I pass to dmd to build a static application?

embedding a library in Windows

2017-01-30 Thread Nestor via Digitalmars-d-learn
Hi, In Windows, is it possible embed a dll library into an application (in this particular case, sqlite3.dll)? Notice I don't mean storing the resource in the application to extract it at runtime, but rather to produce a static self-contained application. If it's possible, please provide a

Re: Problems compiling sqlite-d

2017-01-30 Thread Nestor via Digitalmars-d-learn
On Monday, 30 January 2017 at 03:07:22 UTC, Adam D. Ruppe wrote: If I specify all source files, there are even more problems: Error 42: Symbol Undefined _sqlite3_open It apparently couldn't find sqlite3.lib. Files sqlite3.{def|dll|lib} are on both source/ and source/arsd/ (just in case)

Re: Problems compiling sqlite-d

2017-01-29 Thread Nestor via Digitalmars-d-learn
On Monday, 30 January 2017 at 02:25:40 UTC, Adam D. Ruppe wrote: On Monday, 30 January 2017 at 00:06:00 UTC, Nestor wrote: I wasn't doing it explicitly. However I just did that and still encountered a few errors, which I removed with this patch: Where did you get that ancient version? The

Re: Problems compiling sqlite-d

2017-01-29 Thread Nestor via Digitalmars-d-learn
On Sunday, 29 January 2017 at 17:36:45 UTC, Adam D. Ruppe wrote: On Sunday, 29 January 2017 at 16:26:30 UTC, Nestor wrote: dmd yourfile.d database.d sqlite.d I have just tried your way and I get some errors: Error 42: Symbol Undefined _D4arsd8database3Row7opIndexMFkAyaiZAya Are you sure

Re: Problems compiling sqlite-d

2017-01-29 Thread Nestor via Digitalmars-d-learn
On Saturday, 28 January 2017 at 19:01:48 UTC, Adam D. Ruppe wrote: On Friday, 27 January 2017 at 12:01:30 UTC, Nestor wrote: Is there any other native D implementation of sqlite reader? My sqlite.d and database.d from here can do it too: https://github.com/adamdruppe/arsd Just download those

Re: Where do you get implib

2017-01-29 Thread Nestor via Digitalmars-d-learn
On Friday, 4 November 2011 at 16:31:30 UTC, Johannes Pfau wrote: On http://www.digitalmars.com/download/freecompiler.html there's a link to this file: http://ftp.digitalmars.com/bup.zip I think that's the implib you want? I just tried implib with latest sqlite library def (windows x86) like

Re: Problems compiling sqlite-d

2017-01-28 Thread Nestor via Digitalmars-d-learn
On Sunday, 29 January 2017 at 03:11:34 UTC, Stefan Koch wrote: On Sunday, 29 January 2017 at 02:59:12 UTC, Nestor wrote: On Sunday, 29 January 2017 at 02:55:04 UTC, Adam D. Ruppe wrote: On Sunday, 29 January 2017 at 00:36:34 UTC, Nestor wrote: Well, native implementations are useful at least

Re: Problems compiling sqlite-d

2017-01-28 Thread Nestor via Digitalmars-d-learn
On Sunday, 29 January 2017 at 02:55:04 UTC, Adam D. Ruppe wrote: On Sunday, 29 January 2017 at 00:36:34 UTC, Nestor wrote: Well, native implementations are useful at least for building self-contained applications. Sometimes true, but sqlite can be easily embedded and statically linked, so

Re: Problems compiling sqlite-d

2017-01-28 Thread Nestor via Digitalmars-d-learn
On Sunday, 29 January 2017 at 01:53:30 UTC, Stefan Koch wrote: On Sunday, 29 January 2017 at 01:47:44 UTC, Nestor wrote: On Saturday, 28 January 2017 at 21:09:25 UTC, Stefan Koch wrote: On Saturday, 28 January 2017 at 12:09:35 UTC, Nestor wrote: On Friday, 27 January 2017 at 12:55:55 UTC,

Re: Problems compiling sqlite-d

2017-01-28 Thread Nestor via Digitalmars-d-learn
On Saturday, 28 January 2017 at 21:09:25 UTC, Stefan Koch wrote: On Saturday, 28 January 2017 at 12:09:35 UTC, Nestor wrote: On Friday, 27 January 2017 at 12:55:55 UTC, Stefan Koch wrote: [...] Thanks. It did compile using dub, though I had a couple of issues with dub, by the way. [...]

Re: size of a string in bytes

2017-01-28 Thread Nestor via Digitalmars-d-learn
On Saturday, 28 January 2017 at 19:09:01 UTC, ag0aep6g wrote: In D, a `char` is a UTF-8 code unit. Its size is one byte, exactly and always. A `char` is not a "character" in the common meaning of the word. There's a more specialized word for "character" as a visual unit: grapheme. For

Re: Problems compiling sqlite-d

2017-01-28 Thread Nestor via Digitalmars-d-learn
On Sunday, 29 January 2017 at 00:14:02 UTC, Adam D. Ruppe wrote: On Saturday, 28 January 2017 at 21:03:08 UTC, Stefan Koch wrote: It's not native though. It's a mistake to ask for native D implementations of mature C libraries, especially a public domain one like sqlite. There's just no

Re: size of a string in bytes

2017-01-28 Thread Nestor via Digitalmars-d-learn
On Saturday, 28 January 2017 at 16:01:38 UTC, Ivan Kazmenko wrote: As said, the byte count is indeed string.length. The number of code points can be found by std.range.walkLength, but be aware it takes O(answer) time to compute. Example: - import std.range, std.stdio; void main () {

Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-28 Thread Nestor via Digitalmars-d-learn
On Friday, 27 January 2017 at 04:26:31 UTC, Era Scarecrow wrote: Skipping the BOM is just a matter of skipping the first two bytes identifying it... AFAIK in some cases the BOM takes up to 4 bytes (FOR UTF-32), so when input encoding is unknown one must perform some kind of detection in

Re: size of a string in bytes

2017-01-28 Thread Nestor via Digitalmars-d-learn
On Saturday, 28 January 2017 at 14:56:03 UTC, rikki cattermole wrote: On 29/01/2017 3:51 AM, Nestor wrote: Hi, One can get the length of a string easily, however since strings are UTF-8, sometimes characters take more than one byte. I would like to know then how many bytes does a string

size of a string in bytes

2017-01-28 Thread Nestor via Digitalmars-d-learn
Hi, One can get the length of a string easily, however since strings are UTF-8, sometimes characters take more than one byte. I would like to know then how many bytes does a string take, but this code didn't work as I expected: import std.stdio; void main() { string mystring1; string

Re: Problems compiling sqlite-d

2017-01-28 Thread Nestor via Digitalmars-d-learn
On Friday, 27 January 2017 at 12:55:55 UTC, Stefan Koch wrote: You have to compile the library with your app. or better yet use dub replace app.d with your app.d and run dub Thanks. It did compile using dub, though I had a couple of issues with dub, by the way. The first occured because I

Re: Problems compiling sqlite-d

2017-01-27 Thread Nestor via Digitalmars-d-learn
On Friday, 27 January 2017 at 12:06:33 UTC, Stefan Koch wrote: On Friday, 27 January 2017 at 12:04:06 UTC, Stefan Koch wrote: I take it you build without dub ? Have you specified source/sqlite.d on your compile commandline ? That was supposed to say. sqlite-d/source/sqlited.d Please feel

Problems compiling sqlite-d

2017-01-27 Thread Nestor via Digitalmars-d-learn
Hi, I was trying to use https://github.com/UplinkCoder/sqlite-d Unfortunately even something as simple as this doesn´t compile (at least on Windows): import std.stdio, sqlited; void main(string[] args) { string filename = (args.length == 2 ? args[1] : "data.db"); Database db =

Re: Compile to C?

2017-01-22 Thread Nestor via Digitalmars-d-learn
On Monday, 23 January 2017 at 01:17:20 UTC, Adam D. Ruppe wrote: On Monday, 23 January 2017 at 01:12:21 UTC, Nestor wrote: You mean phobos, or system libraries? Phobos but mostly the druntime that interfaces with the system. I see, I was mostly thinking in Android and/or other platforms,

Re: Compile to C?

2017-01-22 Thread Nestor via Digitalmars-d-learn
On Saturday, 21 January 2017 at 19:33:27 UTC, Adam D. Ruppe wrote: On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote: That would be cool for greater portability. The hard part in porting to a new platform is rarely the code generation - gdc and ldc have diverse backends already

Compile to C?

2017-01-21 Thread Nestor via Digitalmars-d-learn
Hi friends, Is there a way to "compile" d code to C, similar to what nim does? That would be cool for greater portability.

Re: iterating through members of bitfields

2017-01-21 Thread Nestor via Digitalmars-d-learn
Thank you both!

Re: iterating through members of bitfields

2017-01-20 Thread Nestor via Digitalmars-d-learn
On Friday, 20 January 2017 at 08:13:08 UTC, drug wrote: Something like that https://goo.gl/C4nOqw Because you generate code iterating over AliasSeq you can do almost everything you need - for example generate setters/getters. Interesting site, I wouldn't implemente something like this in a

Re: iterating through members of bitfields

2017-01-19 Thread Nestor via Digitalmars-d-learn
On Wednesday, 18 January 2017 at 12:52:56 UTC, drug wrote: I've "solved" the same problem by using AliasSeq to generate bitfields so that for iterating over bitfields I can iterate over alias sequence and mixin code. Not very good but it works. Interesting, could you provide a working

Re: iterating through members of bitfields

2017-01-18 Thread Nestor via Digitalmars-d-learn
On Wednesday, 18 January 2017 at 01:15:05 UTC, Ali Çehreli wrote: Not available but it should be possible to parse the produced code: import std.bitmanip; string makeBitFieldPrinter(string fieldImpl) { return q{ void printBitFields() const { import std.stdio: writeln;

iterating through members of bitfields

2017-01-17 Thread Nestor via Digitalmars-d-learn
Hi, I was just looking at an interesting function from http://codepad.org/lSDTFd7E : void printFields(T)(T args) { auto values = args.tupleof; size_t max; size_t temp; foreach (index, value; values) { temp = T.tupleof[index].stringof.length; if (max < temp) max = temp; }

Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-17 Thread Nestor via Digitalmars-d-learn
On Monday, 16 January 2017 at 14:47:23 UTC, Era Scarecrow wrote: On Sunday, 15 January 2017 at 19:48:04 UTC, Nestor wrote: I see. So correcting my original doubt: How could I parse an UTF16LE file line by line (producing a proper string in each iteration) without loading the entire file into

Re: Quine using strings?

2017-01-16 Thread Nestor via Digitalmars-d-learn
On Monday, 16 January 2017 at 06:41:50 UTC, Basile B. wrote: I remember on Rosetta to have seen this: module quine; import std.stdio; void main(string[] args) { write(import("quine.d")); } compiles with: dmd path/quine.d -Jpath Very good! By the way, module name and arguments aren't

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
Thank you all.

Re: Quine using strings?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 22:08:47 UTC, pineapple wrote: On Sunday, 15 January 2017 at 21:37:53 UTC, Nestor wrote: Any ideas for a shorter version (preferably without using pointers)? When compiling with the -main flag, this D program is a quine: You forgot to include the program... or

Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 16:29:23 UTC, Daniel Kozák wrote: This is because byLine does return range, so until you do something with that it does not cause any harm :) I see. So correcting my original doubt: How could I parse an UTF16LE file line by line (producing a proper string in

Quine using strings?

2017-01-15 Thread Nestor via Digitalmars-d-learn
I was reading some of the examples of writing a quine with D, but apparently the language has evolved and they no longer compiled unchanged. So I tried to program one by myself using strings and std.stdio, but the result seems long and redundant: import std.stdio;void main(){string

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 16:57:35 UTC, biozic wrote: On Sunday, 15 January 2017 at 14:20:04 UTC, Nestor wrote: On second thought, if a baby was born in march 1 of 1999 (non-leap year), in march 1 of 2000 (leap year) the age would have been one year plus one day (because of february 29).

Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 14:48:12 UTC, Nestor wrote: After some testing I realized that byLine was not the one failing, but any string manipulation done to the obtained line. Compile the following example with and without -debug and run to see what I mean: import std.stdio, std.string;

Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Friday, 6 January 2017 at 11:42:17 UTC, Mike Wey wrote: On 01/06/2017 11:33 AM, pineapple wrote: On Friday, 6 January 2017 at 06:24:12 UTC, rumbu wrote: I'm not sure if this works quite as intended, but I was at least able to produce a UTF-16 decode error rather than a UTF-8 decode error

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 14:04:39 UTC, Nestor wrote: ... For example, take a baby born in february 29 of year 2000 (leap year). In february 28 of 2001 that baby was one day short to one year. Family can make a concession and celebrate birthdays in february 28 of non-leap years, but

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 11:01:28 UTC, biozic wrote: On Sunday, 15 January 2017 at 08:40:37 UTC, Nestor wrote: I cleaned up the function a little, but it still feels like a hack: uint getAge(uint , uint mm, uint dd) { import std.datetime; SysTime t = Clock.currTime; ubyte

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
I cleaned up the function a little, but it still feels like a hack: uint getAge(uint , uint mm, uint dd) { import std.datetime; SysTime t = Clock.currTime; ubyte correction = 0; if( (t.month < mm) || ( (t.month == mm) && (t.day < dd) ) ) correction += 1; return (t.year -

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 07:25:26 UTC, rikki cattermole wrote: So I had a go at this and found I struggled looking at "magic" functions and methods. Turns out there is a much simpler answer. int getAge(int , int mm, int dd) { import std.datetime; auto t1 =

Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-04 Thread Nestor via Digitalmars-d-learn
On Wednesday, 4 January 2017 at 18:48:59 UTC, Daniel Kozák wrote: Ok, I've done some testing and you are right byLine is broken, so please fill a bug A bug? I was under the impression that this function was *intended* to work only with UTF-8 encoded files.

Parsing a UTF-16LE file line by line?

2017-01-04 Thread Nestor via Digitalmars-d-learn
Hi, I was just trying to parse a UTF-16LE file using byLine, but apparently this function doesn't work with anything other than UTF-8, because I get this error: "Invalid UTF-8 sequence (at index 1)" How can I achieve what I want, without loading the entire file into memory? Thanks in

Re: Unittest in a windows app

2014-12-20 Thread Dan Nestor via Digitalmars-d-learn
I managed to isolate the problem to the following. Program 1 below works (displays unit test failure when run), while program 2 does not. * Program 1 * import std.stdio; unittest { assert(false); } void main() { writeln(Hello D-World!); } * Program 2 * module

Unittest in a windows app

2014-12-19 Thread Dan Nestor via Digitalmars-d-learn
Hello everybody, this is my first post on this forum. I have a question about unit testing a Windows application. I have slightly modified Visual D's default Windows application stub to the following: code module winmain; import core.runtime; import core.sys.windows.windows; unittest {