Re: linked list

2010-09-26 Thread Joel Christensen
I am looking for use cases of singly|doubly linked lists, I (nearly) never need them in my code. Few questions: 1) What's a typical (or average) length of your list? Thanks for your interest bearophile. I haven't used linked list much more than just trying them out. And my game

Re: linked list

2010-09-26 Thread bearophile
Joel Christensen: > Not very much, 2 players, mines ad lazer bolts are added and removed > when used. I guess around 10. I see, then use a dynamic array, plus append, and few functions like remove. It's faster and simpler. In most situations today (in a language that allows mutability) linked

Re: linked list

2010-09-26 Thread Joel Christensen
I normally use D's built in dynamic arrays. but it doesn't work with adding and removing with the foreach loop (like removing an object from the list while still going through the list).

Re: linked list

2010-09-26 Thread Jonathan M Davis
pending to, prepending to, or inserting into, you use a linked list. std.container currently has SList, which is a singly-linked list but no doubly-linked list. However, they don't have random access and they take up more memory than an array or an Array (thanks to all of those prev and ne

Re: linked list

2010-09-26 Thread bearophile
Jonathan M Davis: > I can only assume that it's one of his pet peeves (we all have them - This is a long story, and I don't have time now, I am sorry. Something related: http://tinyurl.com/3yrawox Bye, bearophile

Re: linked list

2010-09-26 Thread Joel Christensen
Thanks for the long winded reply Jonathan. I don't know how to avoid using my own linked list, I have next/prev in each class (Ball, Lazer and Mine ) in the list. Thanks bearophile, I had a bit of a look at that site. My game is simple so just maybe the easiest way is the way to go, t

Re: linked list

2010-09-27 Thread Denis Koroskin
On Mon, 27 Sep 2010 10:27:36 +0400, Joel Christensen wrote: Thanks for the long winded reply Jonathan. I don't know how to avoid using my own linked list, I have next/prev in each class (Ball, Lazer and Mine ) in the list. That's called intrusive linked list, and I find usin

Re: linked list, ranges

2010-09-26 Thread Joel Christensen
Thanks again for the reply Jonathan. I'm using doublely linked list I made for a game where ships and there lazer bolts are in the same list. Without linked list I couldn't do things like create a lazer bolt or remove one while trans-versing the linked list. I had to use my own l

Re: linked list, ranges

2010-09-26 Thread bearophile
Joel Christensen: > Thanks again for the reply Jonathan. I'm using doublely linked list I > made for a game where ships and there lazer bolts are in the same list. > Without linked list I couldn't do things like create a lazer bolt or > remove one while trans-versing the

Re: linked list, ranges

2010-09-27 Thread Steven Schveighoffer
On Sun, 26 Sep 2010 04:38:36 -0400, Joel Christensen wrote: Thanks again for the reply Jonathan. I'm using doublely linked list I made for a game where ships and there lazer bolts are in the same list. Without linked list I couldn't do things like create a lazer bolt or remove

Re: intrusive linked list

2010-09-27 Thread Joel Christensen
That's called intrusive linked list, and I find using it quite viable: zero-allocation O(1) add/removal is a very strong characteristics. They are very useful especially for lock-free algorithms. That's for the info Denis. I got the idea from a friend who is interested in how to make games.

Synchronized Linked List Traversal

2010-01-20 Thread Jonathan Crapuchettes
I'm working on a project that requires multi-threading and I am trying to grasp the best way to work with setting up a linked-list where multiple threads might try to be setting the next element in the list at the same time. What I really need to know is if this will work: Node!(T)

Linked list, printing looks destructive.

2022-04-24 Thread Alain De Vod via Digitalmars-d-learn
Following program is a single linked list. We expect as output 1 2 3 1 2 3 But the output is only 1 2 3 I think this has something to do with popFront How to fix it using "class List" ? ``` import std.stdio: write,writeln; import std.range: empty,popFront,front; struct Node {

Re: Synchronized Linked List Traversal

2010-01-21 Thread Steven Schveighoffer
On Wed, 20 Jan 2010 19:25:27 -0500, Jonathan Crapuchettes wrote: I'm working on a project that requires multi-threading and I am trying to grasp the best way to work with setting up a linked-list where multiple threads might try to be setting the next element in the list at the

Re: Synchronized Linked List Traversal

2010-01-21 Thread Steven Schveighoffer
On Thu, 21 Jan 2010 08:35:50 -0500, Steven Schveighoffer wrote: To do this, you need a manual mutex, look in tango.core.sync.Mutex I think. or core.sync.mutex for D2... -Steve

Re: Synchronized Linked List Traversal

2010-01-21 Thread Jonathan Crapuchettes
Thank you for the help. Since I am using D1, I think I will use the pthread mutexes through the C API. Steven Schveighoffer wrote: On Thu, 21 Jan 2010 08:35:50 -0500, Steven Schveighoffer wrote: To do this, you need a manual mutex, look in tango.core.sync.Mutex I think. or core.sync.mutex

Re: Synchronized Linked List Traversal

2010-01-21 Thread Steven Schveighoffer
On Thu, 21 Jan 2010 13:29:37 -0500, Jonathan Crapuchettes wrote: Thank you for the help. Since I am using D1, I think I will use the pthread mutexes through the C API. Tango provides mutex objects for D1. -Steve

Re: Synchronized Linked List Traversal

2010-01-21 Thread Jonathan Crapuchettes
Yeah, but I have a lot of code in this project that uses phobos and it would be a major pain (not to mention the time) to switch over. Thank you for the thought, Jonathan Steven Schveighoffer wrote: On Thu, 21 Jan 2010 13:29:37 -0500, Jonathan Crapuchettes wrote: Thank you for the help. Sin

Re: Synchronized Linked List Traversal

2010-01-21 Thread Steven Schveighoffer
On Thu, 21 Jan 2010 13:44:53 -0500, Jonathan Crapuchettes wrote: Yeah, but I have a lot of code in this project that uses phobos and it would be a major pain (not to mention the time) to switch over. Thank you for the thought, Jonathan No problem. You also might consider tangobos, but I

Iteratable single linked list of floats.

2021-04-21 Thread Alain De Vos via Digitalmars-d-learn
I try to create manually and explicit an interetable single linked list of floats. Probably one of the most basic datastructures. import std.stdio; void main(){ struct List { struct Node { float f; Node *next

Re: Linked list, printing looks destructive.

2022-04-24 Thread Ali Çehreli via Digitalmars-d-learn
On 4/24/22 18:40, Alain De Vod wrote: > I think this has something to do with popFront This type violates a fundamental rule: Containers and ranges are separate concepts. Your List is a container, not a range. I changed your code by moving the range functions to a Range struct that is created

Re: Linked list, printing looks destructive.

2022-04-24 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 25 April 2022 at 02:19:46 UTC, Ali Çehreli wrote: This type violates a fundamental rule: Containers and ranges are separate concepts. Your List is a container, not a range. I changed your code by moving the range functions to a Range [...] Dear Ali, I implemented a linkedlist ove

Re: Linked list, printing looks destructive.

2022-04-25 Thread Alain De Vos via Digitalmars-d-learn
On Monday, 25 April 2022 at 05:17:28 UTC, Salih Dincer wrote: On Monday, 25 April 2022 at 02:19:46 UTC, Ali Çehreli wrote: This type violates a fundamental rule: Containers and ranges are separate concepts. Your List is a container, not a range. I changed your code by moving the range functio

Re: Linked list, printing looks destructive.

2022-04-25 Thread Alain De Vos via Digitalmars-d-learn
This program works ok, (but List is no Range) ``` class Node { int data; Node next; } class List { Node node=null; this(int[] AR){foreach(i ; AR)pushfront(i);} bool empty() const {return !node;} void popFront() {node=node.next;} float front

Re: Linked list, printing looks destructive.

2022-04-25 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 25 April 2022 at 09:38:05 UTC, Alain De Vos wrote: This program works ok, (but List is no Range) It is also possible with the copy constructor of a struct. I don't know how to do with class... ```d struct Node { int element; Node * next; } stru

Re: Linked list, printing looks destructive.

2022-04-25 Thread Ali Çehreli via Digitalmars-d-learn
On 4/25/22 03:48, Salih Dincer wrote: > It is also possible with the copy constructor of a struct. I don't know > how to do with class... Classes don't have language provided construction because nobody needs it and in fact they have to protect themselves when a language provides it. (See, e.g

Re: Linked list, printing looks destructive.

2022-04-25 Thread cc via Digitalmars-d-learn
On Monday, 25 April 2022 at 01:40:01 UTC, Alain De Vod wrote: Following program is a single linked list. We expect as output 1 2 3 1 2 3 But the output is only 1 2 3 ``` If you don't need List to be treated as a true range, but just want to iterate, a simple way to do this is with op

Re: Linked list, printing looks destructive.

2022-04-25 Thread Alain De Vos via Digitalmars-d-learn
Indeed code below works, ``` import std.stdio: write,writeln; class Node { int data; Node next; } class List { Node node=null; this(int[] AR){foreach(i ; AR)pushfront(i);} void pushfront(int data) { Node newnode=new Node();

Re: Iteratable single linked list of floats.

2021-04-21 Thread Alain De Vos via Digitalmars-d-learn
Formatted , ``` import std.stdio; void main(){ struct List { struct Node { float f; Node *next; } Node * root=null; bool empty() const {return !root;} voi

Re: Iteratable single linked list of floats.

2021-04-21 Thread drug via Digitalmars-d-learn
21.04.2021 16:19, Alain De Vos пишет: import std.stdio; void main(){ struct List {     struct Node {     float f;     Node *next;     }     Node * root=null;     bool empty() const {return !root;}     void popFront() {root=root.next;}     f

Re: Iteratable single linked list of floats.

2021-04-23 Thread Alain De Vos via Digitalmars-d-learn
Here a working code, ``` import std.stdio; void main(){ struct List { struct Node { float f; Node *next=null; } Node * root=null; bool empty() const {return !root;} void popFront() {root=root.next;} float front() const

Issue with free() for linked list implementation

2015-04-03 Thread Kitt via Digitalmars-d-learn
Hello. I’m trying to write my own version of a list that doesn’t rely on the garbage collector. I’m working on a very bare bones implementation using malloc and free, but I’m running into an exception when I attempt to call free. Here is a very minimal code sample to illustrate the issue: //

Keeping a reference to a linked list element

2016-05-11 Thread BLM768 via Digitalmars-d-learn
I just started working on a project in which it would be convenient to hold a reference to a specific entry in a DList. The interface doesn't seem to provide a way to get a pointer to a raw node struct, so about the best solution I can find is to get a range out of the list, pop elements until

Looking for a Simple Doubly Linked List Implementation

2019-09-20 Thread Ron Tarrant via Digitalmars-d-learn
Hi guys, I've been banging my head on the screen with this one for the last week or so. For whatever reason, I'm having major problems understanding how to implement a doubly-linked list in D. I don't know if it's because I'm losing my ability to sort these thi

Looking for a Simple Doubly Linked List Implementation

2020-10-29 Thread xpaceeight via Digitalmars-d-learn
https://forum.dlang.org/post/bpixuevxzzltiybdr...@forum.dlang.org It contains the data and a pointer to the next and previous linked list node. This is given as follows. struct Node { int data; struct Node *prev; struct Node *next; }; The function insert() inserts the data into the beginning

Re: Issue with free() for linked list implementation

2015-04-03 Thread Namespace via Digitalmars-d-learn
On Friday, 3 April 2015 at 22:02:13 UTC, Kitt wrote: Hello. I’m trying to write my own version of a list that doesn’t rely on the garbage collector. I’m working on a very bare bones implementation using malloc and free, but I’m running into an exception when I attempt to call free. Here is a v

Re: Issue with free() for linked list implementation

2015-04-03 Thread Kitt via Digitalmars-d-learn
On Friday, 3 April 2015 at 22:06:06 UTC, Namespace wrote: On Friday, 3 April 2015 at 22:02:13 UTC, Kitt wrote: Hello. I’m trying to write my own version of a list that doesn’t rely on the garbage collector. I’m working on a very bare bones implementation using malloc and free, but I’m running

Re: Issue with free() for linked list implementation

2015-04-03 Thread Namespace via Digitalmars-d-learn
Wow, I can't even begin to explain how red my cheeks are right now. You're completely right; I have no idea what my head was thinking. Sure enough, call malloc with the correct type, and the error goes away =P Thanks for the help =) I guess I've been in C# land at work for way too long now, m

Re: Issue with free() for linked list implementation

2015-04-03 Thread Gary Willoughby via Digitalmars-d-learn
On Friday, 3 April 2015 at 22:08:52 UTC, Kitt wrote: Thanks for the help =) I guess I've been in C# land at work for way too long now, my low level C skills are evaporating! I've written a straight forward linked list implementation here: https://github.com/nomad-software/etcetera/b

Re: Issue with free() for linked list implementation

2015-04-03 Thread Namespace via Digitalmars-d-learn
On Friday, 3 April 2015 at 22:38:00 UTC, Gary Willoughby wrote: On Friday, 3 April 2015 at 22:08:52 UTC, Kitt wrote: Thanks for the help =) I guess I've been in C# land at work for way too long now, my low level C skills are evaporating! I've written a straight forward l

Re: Issue with free() for linked list implementation

2015-04-04 Thread bearophile via Digitalmars-d-learn
Namespace: I've written a straight forward linked list implementation here: https://github.com/nomad-software/etcetera/blob/master/source/etcetera/collection/linkedlist.d Even though I'm using the GC to manage memory, maybe it will help you. Good idea to link to some existing

Re: Issue with free() for linked list implementation

2015-04-04 Thread Namespace via Digitalmars-d-learn
On Saturday, 4 April 2015 at 09:05:03 UTC, bearophile wrote: Namespace: I've written a straight forward linked list implementation here: https://github.com/nomad-software/etcetera/blob/master/source/etcetera/collection/linkedlist.d Even though I'm using the GC to manage memory

Re: Issue with free() for linked list implementation

2015-04-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/3/15 6:08 PM, Kitt wrote: On Friday, 3 April 2015 at 22:06:06 UTC, Namespace wrote: On Friday, 3 April 2015 at 22:02:13 UTC, Kitt wrote: Hello. I’m trying to write my own version of a list that doesn’t rely on the garbage collector. I’m working on a very bare bones implementation using mal

Re: Issue with free() for linked list implementation

2015-04-06 Thread Namespace via Digitalmars-d-learn
2. When you malloc, you use 'two.sizeof' and 'ten.sizeof'. Integers are 4 bytes, so you were allocating 4 bytes for each of these (not 2 or 10 bytes as is alluded to above). Yeah, my mistake. I saw the mistake but could not describe it correctly. :)

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-20 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 20, 2019 at 08:26:03PM +, Ron Tarrant via Digitalmars-d-learn wrote: > Hi guys, > > I've been banging my head on the screen with this one for the last > week or so. For whatever reason, I'm having major problems > understanding how to implement a doubly-

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-20 Thread Dennis via Digitalmars-d-learn
On Friday, 20 September 2019 at 20:26:03 UTC, Ron Tarrant wrote: If someone could please post a minimal example (if there's extra stuff in there, I'll get confused; I'm getting that old, dammit) I'd be ever so grateful. Below is a simple doubly linked list with Garbage Col

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Ron Tarrant via Digitalmars-d-learn
On Friday, 20 September 2019 at 20:35:41 UTC, H. S. Teoh wrote: Not a minimal example by any means, but Phobos *does* come with a doubly-linked list implementation: std.container.dlist. Thanks, H.S. I did come across that in my search. Trouble is, with all the extra stuff in there, I&#

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread ag0aep6g via Digitalmars-d-learn
On 21.09.19 10:34, Ron Tarrant wrote: Here's a question for the room: Does a doubly-linked list always have to be done with structs? Can it be classes instead? (Maybe that's why I can't get it to work, because I've been trying to make an OOP version?) It can be done w

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Ron Tarrant via Digitalmars-d-learn
On Saturday, 21 September 2019 at 08:49:48 UTC, ag0aep6g wrote: On 21.09.19 10:34, Ron Tarrant wrote: Here's a question for the room: Does a doubly-linked list always have to be done with structs? Can it be classes instead? (Maybe that's why I can't get it to work, because I

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Tobias Pankrath via Digitalmars-d-learn
On Saturday, 21 September 2019 at 09:03:13 UTC, Ron Tarrant wrote: Ah! Thanks, ag0aep6g. I was wondering about that when I was writing the code. (If I already knew this, I'd forgotten.) I did as you suggested, took out all '*' and '&' and it works perfectly. Is this what you want? --- current

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Alex via Digitalmars-d-learn
On Friday, 20 September 2019 at 20:26:03 UTC, Ron Tarrant wrote: Hi guys, I've been banging my head on the screen with this one for the last week or so. For whatever reason, I'm having major problems understanding how to implement a doubly-linked list in D. I don't know if i

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Ron Tarrant via Digitalmars-d-learn
Thanks for all the responses, y'all. I got it figured out thanks to ag0aep6g pointing out something I forgot about the nature of class objects in D (Damn my failing memory). The results will show up on the gtkDcoding blog sometime in (I'm guessing) November as part of the the Notebook discussi

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Dennis via Digitalmars-d-learn
, I meant it was a simple implementation not optimized for speed / memory efficiency. Making it 'complete' is a bit hard since I can think of tens of methods and operator overloads you could use, but if I include them all it's no longer minimal and it just becomes std.container.d

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Ron Tarrant via Digitalmars-d-learn
it's no longer minimal and it just becomes std.container.dlist. Does a doubly-linked list always have to be done with structs? Can it be classes instead? My example originally included classes actually. It was mostly the same, except that Node!T* was just Node!T. The only problem was

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Ron Tarrant via Digitalmars-d-learn
Sorry. I posted the wrong file. This is the one that works: ``` import std.stdio; import std.conv; class TabList { private: Tab _head; int _lastUniqueID = 0; string labelText; this() { append(); }

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Jonathan M Davis via Digitalmars-d-learn
t's publicly available for others to muck with, whereas nodes in a linked list are normally private to the list, so it's easy to ensure that they're only ever on the heap even if they're structs). - Jonathan M Davis

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-23 Thread Ron Tarrant via Digitalmars-d-learn
Well, it turns out, I didn't need a linked list, doubly or otherwise. That's what happens when a person quits coffee for a week: complete brain chaos. For a full week, I banged on this, trying to work out a scheme whereby I could track GTK Notebook tabs with a doubly-linked list

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-23 Thread Ali Çehreli via Digitalmars-d-learn
On 09/23/2019 01:45 PM, Ron Tarrant wrote: > Well, it turns out, I didn't need a linked list, doubly or otherwise. So, what was it then? Append to an array, sort it, and be happy? :) Ali

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-25 Thread Ron Tarrant via Digitalmars-d-learn
On Monday, 23 September 2019 at 22:40:41 UTC, Ali Çehreli wrote: So, what was it then? Append to an array, sort it, and be happy? :) Ali Hi, Ali, It turns out that the GTK Notebook has its own built-in mechanism for tracking tabs. Two things got me going down the wrong road on this: 1)

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-28 Thread snow jhon via Digitalmars-d-learn
it's no longer minimal and it just becomes std.container.dlist. Does a doubly-linked list always have to be done with structs? Can it be classes instead? My example originally included classes actually. It was mostly the same, except that Node!T* was just Node!T. The only problem was

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-29 Thread snow jhon via Digitalmars-d-learn
On Saturday, 28 September 2019 at 16:21:10 UTC, snow jhon wrote: On Saturday, 21 September 2019 at 18:52:23 UTC, Dennis wrote: [...] Below is a simple doubly linked list with Garbage Collected memory. It's not performant or complete by any means, just a minimal example in D like you w

Re: Looking for a Simple Doubly Linked List Implementation

2020-01-28 Thread Barry allen via Digitalmars-d-learn
your linked list seems very complex

Re: Looking for a Simple Doubly Linked List Implementation

2020-01-29 Thread Barry allen via Digitalmars-d-learn
On Tuesday, 28 January 2020 at 20:20:25 UTC, Barry allen wrote: your linked list seems very complex https://get-shareit.com https://get-vidmateapk.com /* Node of a doubly linked list */ struct Node { int data; struct Node* next; // Pointer to next node in DLL struct Node

Re: Looking for a Simple Doubly Linked List Implementation

2020-10-29 Thread IGotD- via Digitalmars-d-learn
On Thursday, 29 October 2020 at 18:06:55 UTC, xpaceeight wrote: https://forum.dlang.org/post/bpixuevxzzltiybdr...@forum.dlang.org It contains the data and a pointer to the next and previous linked list node. This is given as follows. struct Node { int data; struct Node *prev; struct Node

Re: Looking for a Simple Doubly Linked List Implementation

2020-10-29 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 29 October 2020 at 18:10:28 UTC, IGotD- wrote: Is this what you are looking for? https://dlang.org/phobos/std_container_dlist.html I'm pretty sure the post you replied to is spam.

Re: Looking for a Simple Doubly Linked List Implementation

2020-10-29 Thread IGotD- via Digitalmars-d-learn
On Thursday, 29 October 2020 at 22:02:52 UTC, Paul Backus wrote: I'm pretty sure the post you replied to is spam. Yes, when I read the post again it is kind of hollow.

Re: Is there a thread safe single linked list?

2012-10-12 Thread denizzzka
or dynamic array with this methods

Re: Is there a thread safe single linked list?

2012-10-12 Thread Jonathan M Davis
On Friday, October 12, 2012 14:59:56 denizzzka wrote: > Hi! > > Specifically, pushBack(x) and moveFront() operations should be a > thread safe. Not in Phobos. No containers in Phobos contain any kind of synchronization. The same goes for the built-in array types. If any of them are shared, you'l

Re: Is there a thread safe single linked list?

2012-10-12 Thread denizzzka
Thanks for answer! After investigation came to the conclusion that here is needed not synchronized-based solution. I am need compare-and-swap single linked list because it will be used in callback proc from C, and it cannot be throwable, but synchronized contains throwable _d_monitorenter

Re: Is there a thread safe single linked list?

2012-10-12 Thread denizzzka
I would be grateful if someone share singly linked list based on cas() Ok, this is a good opportunity to learn how to write such by oneself :-)

Re: Is there a thread safe single linked list?

2012-10-12 Thread Sean Kelly
On Oct 12, 2012, at 10:18 AM, denizzzka <4deni...@gmail.com> wrote: > Thanks for answer! > > After investigation came to the conclusion that here is needed not > synchronized-based solution. I am need compare-and-swap single linked list > because it will be used in callbac

Re: Is there a thread safe single linked list?

2012-10-13 Thread denizzzka
On Friday, 12 October 2012 at 23:30:39 UTC, Sean Kelly wrote: I would be grateful if someone share singly linked list based on cas() There's a sample Stack and SList implementation in the concurrency chapter: http://www.informit.com/articles/printerfriendly.aspx?p=1609144 Of cour

Re: Is there a thread safe single linked list?

2012-10-13 Thread denizzzka
Not that the "titanic" but the authors, probably, have used Java and another type of cas result returns.

Correctly implementing a bidirectional range on a linked list?

2015-07-06 Thread Gary Willoughby via Digitalmars-d-learn
How do you correctly implement a bidirectional range on a linked list? I have a linked list implementation and I've added a range interface to it but after a while I've realized it not quite right. The problem is when I call the save method of the forward range interface I don'

Linked list as a bidirectional range? I have some questions...

2014-08-11 Thread Gary Willoughby via Digitalmars-d-learn
Just for a bit a fun i've implemented a simple doubly linked list and trying out some range based stuff. Whilst doing so i have some questions which you guys might be able to answer. 1. In your opinion when accessing the elements of a linked list should they yield the data stored withi

Re: Correctly implementing a bidirectional range on a linked list?

2015-07-06 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 July 2015 at 20:50:19 UTC, Gary Willoughby wrote: The problem is when I call the save method of the forward range interface I don't get a copy I only get another view to the same state. So when i remove nodes from the original list the range becomes invalid. This is why modifyi

Re: Correctly implementing a bidirectional range on a linked list?

2015-07-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 July 2015 at 20:50:19 UTC, Gary Willoughby wrote: How do you correctly implement a bidirectional range on a linked list? I have a linked list implementation and I've added a range interface to it but after a while I've realized it not quite right. The problem is when

Re: Correctly implementing a bidirectional range on a linked list?

2015-07-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 July 2015 at 21:58:31 UTC, anonymous wrote: To make your removal methods stable, it may be enough to not free the removed node. That is, don't do this: https://github.com/nomad-software/etcetera/blob/master/source/etcetera/collection Looks like I messed up the URL. Here's the righ

Re: Correctly implementing a bidirectional range on a linked list?

2015-07-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, July 06, 2015 21:58:30 anonymous via Digitalmars-d-learn wrote: > Off topic: I think `@trusted:` is horrible. It's easy to forget > that you're in a @trusted environment when editing things later. > And even worse, you're trusting everything that's passed through > template parameters.

Re: Correctly implementing a bidirectional range on a linked list?

2015-07-07 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 7 July 2015 at 09:35:12 UTC, Jonathan M Davis wrote: This is why you almost never use @trusted on templated functions. You should _never_ mark anything with @trusted unless you can guarantee that it's actually @safe. @safe is inferred for templated functions, so unless you're doing

How should I sort a doubly linked list the D way?

2019-08-13 Thread Mirjam Akkersdijk via Digitalmars-d-learn
Hello there, If I had a DLL, how would I sort it judging by the node contents, the D way? In C if I were to sort a piece of malloc'd memory pointing to node pointers, I would write my compare function and let qsort sort it out. In D, I tried to use std.algorithm's sort functionality to no av

Re: Linked list as a bidirectional range? I have some questions...

2014-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 11, 2014 at 05:51:11PM +, Gary Willoughby via Digitalmars-d-learn wrote: > Just for a bit a fun i've implemented a simple doubly linked list and > trying out some range based stuff. Whilst doing so i have some > questions which you guys might be able to answer. &

Re: Linked list as a bidirectional range? I have some questions...

2014-08-11 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 11 August 2014 at 18:20:51 UTC, H. S. Teoh via Digitalmars-d-learn wrote: If you make your linked list container the same thing as a range over it, then iterating over the range will empty the container as well, which generally isn't what you want. Yes but only if it&#

Re: Linked list as a bidirectional range? I have some questions...

2014-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 11, 2014 at 07:35:04PM +, Gary Willoughby via Digitalmars-d-learn wrote: > On Monday, 11 August 2014 at 18:20:51 UTC, H. S. Teoh via > Digitalmars-d-learn wrote: > >If you make your linked list container the same thing as a range over > >it, then iterating o

Re: Linked list as a bidirectional range? I have some questions...

2014-08-11 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 11 August 2014 at 20:02:38 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Mon, Aug 11, 2014 at 07:35:04PM +, Gary Willoughby via Digitalmars-d-learn wrote: On Monday, 11 August 2014 at 18:20:51 UTC, H. S. Teoh via Digitalmars-d-learn wrote: >If you make your linked l

Re: Linked list as a bidirectional range? I have some questions...

2014-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 11, 2014 at 08:22:11PM +, Gary Willoughby via Digitalmars-d-learn wrote: [...] > That..is..awesome! and much more simpler than i thought. I get it now, > thanks. Is this pattern repeated in phobos? This is essentially what byKey and byValue of the built-in associative arrays do. :

Re: Linked list as a bidirectional range? I have some questions...

2014-08-12 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 11 August 2014 at 20:02:38 UTC, H. S. Teoh via Digitalmars-d-learn wrote: opApplyReverse. Was that a joke or does opApplyReverse exist?

Re: Linked list as a bidirectional range? I have some questions...

2014-08-12 Thread ketmar via Digitalmars-d-learn
On Tue, 12 Aug 2014 16:50:33 + Gary Willoughby via Digitalmars-d-learn wrote: > Was that a joke or does opApplyReverse exist? it's not a joke. http://dlang.org/statement.html ctrl+f, opApplyReverse signature.asc Description: PGP signature

Re: Linked list as a bidirectional range? I have some questions...

2014-08-12 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 12 August 2014 at 17:00:26 UTC, ketmar via Digitalmars-d-learn wrote: On Tue, 12 Aug 2014 16:50:33 + Gary Willoughby via Digitalmars-d-learn wrote: Was that a joke or does opApplyReverse exist? it's not a joke. http://dlang.org/statement.html ctrl+f, opApplyReverse Ha, awes

Re: Linked list as a bidirectional range? I have some questions...

2014-08-13 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 11 August 2014 at 20:02:38 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Anyway, clearly we're not understanding each other, so let me present some concrete code so that we aren't just talking past each other: I've used your advice and implemented a range over the list as suggeste

Re: Linked list as a bidirectional range? I have some questions...

2014-08-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 13, 2014 at 06:31:32PM +, Gary Willoughby via Digitalmars-d-learn wrote: > On Monday, 11 August 2014 at 20:02:38 UTC, H. S. Teoh via > Digitalmars-d-learn wrote: > >Anyway, clearly we're not understanding each other, so let me present > >some concrete code so that we aren't just ta

Re: Linked list as a bidirectional range? I have some questions...

2014-08-13 Thread via Digitalmars-d-learn
On Wednesday, 13 August 2014 at 18:58:59 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Aug 13, 2014 at 06:31:32PM +, Gary Willoughby via Digitalmars-d-learn wrote: On Monday, 11 August 2014 at 20:02:38 UTC, H. S. Teoh via Digitalmars-d-learn wrote: >Anyway, clearly we're not underst

Re: Linked list as a bidirectional range? I have some questions...

2014-08-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 13, 2014 at 07:23:30PM +, via Digitalmars-d-learn wrote: > On Wednesday, 13 August 2014 at 18:58:59 UTC, H. S. Teoh via > Digitalmars-d-learn wrote: > >On Wed, Aug 13, 2014 at 06:31:32PM +, Gary Willoughby via > >Digitalmars-d-learn wrote: [...] > >>I've used your advice and imp

Re: Linked list as a bidirectional range? I have some questions...

2014-08-13 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 13 August 2014 at 18:58:59 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Aug 13, 2014 at 06:31:32PM +, Gary Willoughby via Digitalmars-d-learn wrote: On Monday, 11 August 2014 at 20:02:38 UTC, H. S. Teoh via Digitalmars-d-learn wrote: >Anyway, clearly we're not underst

Re: Linked list as a bidirectional range? I have some questions...

2014-08-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 13, 2014 at 07:37:09PM +, Gary Willoughby via Digitalmars-d-learn wrote: > On Wednesday, 13 August 2014 at 18:58:59 UTC, H. S. Teoh via > Digitalmars-d-learn wrote: > >On Wed, Aug 13, 2014 at 06:31:32PM +, Gary Willoughby via > >Digitalmars-d-learn wrote: [...] > >>I've used yo

Re: Linked list as a bidirectional range? I have some questions...

2014-08-13 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 13 August 2014 at 19:43:20 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Aug 13, 2014 at 07:37:09PM +, Gary Willoughby via Digitalmars-d-learn wrote: On Wednesday, 13 August 2014 at 18:58:59 UTC, H. S. Teoh via Digitalmars-d-learn wrote: >On Wed, Aug 13, 2014 at 06:31:

Re: Linked list as a bidirectional range? I have some questions...

2014-08-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 13, 2014 at 07:58:49PM +, Gary Willoughby via Digitalmars-d-learn wrote: > On Wednesday, 13 August 2014 at 19:43:20 UTC, H. S. Teoh via > Digitalmars-d-learn wrote: > >On Wed, Aug 13, 2014 at 07:37:09PM +, Gary Willoughby via > >Digitalmars-d-learn wrote: > >>On Wednesday, 13 A

Re: Linked list as a bidirectional range? I have some questions...

2014-08-13 Thread via Digitalmars-d-learn
On Wednesday, 13 August 2014 at 20:27:29 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Aug 13, 2014 at 07:58:49PM +, Gary Willoughby via Digitalmars-d-learn wrote: On Wednesday, 13 August 2014 at 19:43:20 UTC, H. S. Teoh via Digitalmars-d-learn wrote: >On Wed, Aug 13, 2014 at 07:37:

Re: Linked list as a bidirectional range? I have some questions...

2014-08-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 13, 2014 at 08:52:32PM +, via Digitalmars-d-learn wrote: > On Wednesday, 13 August 2014 at 20:27:29 UTC, H. S. Teoh via > Digitalmars-d-learn wrote: > >On Wed, Aug 13, 2014 at 07:58:49PM +, Gary Willoughby via > >Digitalmars-d-learn wrote: > >>On Wednesday, 13 August 2014 at 19:

Re: Linked list as a bidirectional range? I have some questions...

2014-08-14 Thread via Digitalmars-d-learn
On Wednesday, 13 August 2014 at 19:30:53 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Aug 13, 2014 at 07:23:30PM +, via Digitalmars-d-learn wrote: On Wednesday, 13 August 2014 at 18:58:59 UTC, H. S. Teoh via Digitalmars-d-learn wrote: >On Wed, Aug 13, 2014 at 06:31:32PM +, Gary

  1   2   >