Re: use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
Steve, thank you once again. Now it compiles & runs! I now create my tree like this: auto debs = new RedBlackTree!(Deb, (a, b) => a.name < b.name); (I feel that the rbtree docs are inadequate regarding creating new empty trees, so have submitted a bug report:

Re: use of struct vs class

2020-03-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/7/20 8:22 AM, mark wrote: 0x55701ef0 in _D3std9container6rbtree__T12RedBlackTreeTAyaVQea5_61203c2062Vbi0ZQBn5emptyMFNaNbNdNiNfZb (this=0x0)     at /home/mark/opt/ldc2-1.20.0-linux-x86_64/bin/../import/std/container/rbtree.d:967 967    return _end.left is null; (gdb) bt

Re: use of struct vs class

2020-03-07 Thread drug via Digitalmars-d-learn
07.03.2020 15:58, Steven Schveighoffer пишет: Hm... I'd say: 1. Don't use a pointer for the element. Just use the struct directly. Using a pointer is bad because it's now going to compare pointers, and not the element data. Not only that, but RBNodes are stored as heap-allocated structs, so

Re: use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
I've now gone back to using structs direct without pointers but I'm still doing something wrong. struct Deb { string name; ... RedBlackTree!string tags; bool valid() { return !(name.empty || description.empty); } void clear() { name = ""; ...; tags.clear; } }

Re: use of struct vs class

2020-03-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/7/20 5:58 AM, mark wrote: change #1:     if (line.empty) {     if (deb != null && deb.valid)     debs.insert(deb);     else // report incomplete     deb = null;     continue;  

Re: use of struct vs class

2020-03-07 Thread drug via Digitalmars-d-learn
07.03.2020 13:58, mark пишет: change #1:     if (line.empty) {     if (deb != null && deb.valid)     debs.insert(deb);     else // report incomplete     deb = null;     continue;   

Re: use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
change #1: if (line.empty) { if (deb != null && deb.valid) debs.insert(deb); else // report incomplete deb = null; continue; } if (deb == null)

Re: use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
Instead of deb.clear I'm now doing deb = null;

Re: use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
On Saturday, 7 March 2020 at 10:30:06 UTC, drug wrote: 07.03.2020 13:20, mark пишет: I have this struct (with details omitted [ snip ] Should Deb be a class rather than a struct? Do you consider using pointers in AA: ``` Deb*[string] debForName; ``` I've done some changes including using

Re: use of struct vs class

2020-03-07 Thread drug via Digitalmars-d-learn
07.03.2020 13:20, mark пишет: I have this struct (with details omitted [ snip ] Should Deb be a class rather than a struct? Do you consider using pointers in AA: ``` Deb*[string] debForName; ```

use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
I have this struct (with details omitted ... for brevity): struct Deb { string name; ... RedBlackTree!string tags; void clear() { name = ""; ...; tags.clear; } bool valid() { return !(name.empty || description.empty); } } I plan to store >65K of these (with potential for