www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Collections in D

reply Roguish <nospam nospam.net> writes:
I can't find anything about collections in D. All I have found 
are arrays and maps ("associative arrays"). What about lists and 
sets? What if I just want a linked list?
Jan 13 2021
next sibling parent Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= <aferust gmail.com> writes:
On Wednesday, 13 January 2021 at 11:58:11 UTC, Roguish wrote:
 I can't find anything about collections in D. All I have found 
 are arrays and maps ("associative arrays"). What about lists 
 and sets? What if I just want a linked list?
You can refer to the docs for them: https://dlang.org/phobos/std_container.html https://dlang.org/phobos/std_container_slist.html https://dlang.org/phobos/std_container_dlist.html For sets see: https://forum.dlang.org/thread/vqyxqkcszqfwpgqtjgcm forum.dlang.org
Jan 13 2021
prev sibling parent reply Roguish <nospam nospam.net> writes:
On Wednesday, 13 January 2021 at 11:58:11 UTC, Roguish wrote:
 I can't find anything about collections in D. All I have found 
 are arrays and maps ("associative arrays"). What about lists 
 and sets? What if I just want a linked list?
It seems collections are called "containers" in D's standard library, which explains why I didn't find anything searching for "collections". As concerns linked lists, I have found https://dlang.org/phobos/std_container_dlist.html which seems perfectly adequate. What about sets?
Jan 13 2021
next sibling parent reply evilrat <evilrat666 gmail.com> writes:
On Wednesday, 13 January 2021 at 12:06:05 UTC, Roguish wrote:
 What about sets?
There is no specific set container, they just implemented as generic algorithms over the ranges. There is a section for set operations (std.algorithm.setops module). https://dlang.org/phobos/std_algorithm.html
Jan 13 2021
parent Roguish <nospam nospam.net> writes:
On Wednesday, 13 January 2021 at 12:39:50 UTC, evilrat wrote:
 There is no specific set container, they just implemented as 
 generic algorithms over the ranges.
I see. Thanks for pointing that out.
Jan 13 2021
prev sibling next sibling parent reply Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= <aferust gmail.com> writes:
On Wednesday, 13 January 2021 at 12:06:05 UTC, Roguish wrote:
 On Wednesday, 13 January 2021 at 11:58:11 UTC, Roguish wrote:
 I can't find anything about collections in D. All I have found 
 are arrays and maps ("associative arrays"). What about lists 
 and sets? What if I just want a linked list?
It seems collections are called "containers" in D's standard library, which explains why I didn't find anything searching for "collections". As concerns linked lists, I have found https://dlang.org/phobos/std_container_dlist.html which seems perfectly adequate. What about sets?
I read many posts that rbtree can be a replacement for sets in dlang. see its behaviour is identical. https://dlang.org/phobos/std_container_rbtree.html
Jan 13 2021
parent Roguish <nospam nospam.net> writes:
On Wednesday, 13 January 2021 at 12:48:47 UTC, Ferhat Kurtulmuş 
wrote:
 I read many posts that rbtree can be a replacement for sets in 
 dlang.

 see its behaviour is identical.
Thanks, will read up.
Jan 13 2021
prev sibling parent mw <mingwu gmail.com> writes:
On Wednesday, 13 January 2021 at 12:06:05 UTC, Roguish wrote:

 which seems perfectly adequate.

 What about sets?
You can also search https://code.dlang.org I use: https://code.dlang.org/packages/emsi_containers Which has hashset: https://github.com/dlang-community/containers/blob/fc1625a5a0c253272b80addfb4107928495fd647/src/containers/hashset.d
Jan 13 2021