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: 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 opApply

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,

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; }

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

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

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

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

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: 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()

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;}    

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;}

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: 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: 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 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

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: 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-01-28 Thread Barry allen via Digitalmars-d-learn
your linked list seems very complex

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 wanted

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-28 Thread snow jhon via Digitalmars-d-learn
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 with const: ``` size_t length() const

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-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-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, an array

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Jonathan M Davis via Digitalmars-d-learn
k 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-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 Ron Tarrant via Digitalmars-d-learn
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 with const: ``` size_t length() const

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Dennis via Digitalmars-d-learn
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.dlist. Does a doubly-linked list always

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

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 it's because I'm

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? ---

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've been trying

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 with classes. When I

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'm

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 Collected memory. It's

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-linked lis

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 things or if it's just

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

2019-08-14 Thread Patrick Schluter via Digitalmars-d-learn
; and then iterate the array and repair the next/prev pointers. If possible, I would go further and ditch the linked list altogether: Just append the nodes to an array and then sort the array. It has been shown in research, conference presentations, and in personal code to be the fasted op

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

2019-08-14 Thread Ali Çehreli via Digitalmars-d-learn
On 08/13/2019 03:12 PM, Mirjam Akkersdijk wrote: > For the application I am writing, it makes very much sense to use a DLL. Yes, Dynamically Linked Libraries can be useful. Oh wait... You mean Doubly-Linked List. :o) > I tried setting the length first and iterating through it with `n

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

2019-08-13 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 22:12:23 UTC, Mirjam Akkersdijk wrote: Though, it left me with some semi-offtopic questions unanswered: (1) Ali, do you mean that from an optimization viewpoint, it's better to keep appending like `nodes ~= ...` instead of setting the length first? I would like

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

2019-08-13 Thread Mirjam Akkersdijk via Digitalmars-d-learn
application and create an array just for sorting operations. No new nodes are added and no nodes are permanently removed. You can still get a cache-efficient linked list by chunking. [...] I very much appreciate this thought, as I was thinking of adding such kind of cache to my implementation. It's

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

2019-08-13 Thread Mirjam Akkersdijk via Digitalmars-d-learn
e null for pointers. (If we are back to linked list Node pointers.) However, I wouldn't bother with setting length either as the cost of automatic array resizing is amortized, meaning that it won't hurt the O(1) algorithmic complexity in the general case. In the GC case that D uses, it will be even

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

2019-08-13 Thread H. S. Teoh via Digitalmars-d-learn
std::vector was a lot faster than a linked list for all supported > operations. I don't know how clever the caching strategies are on a > modern processor (Pointer chasing), but to my knowledge the only way > of getting a cache efficient linked list would be to effectively have > a very con

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

2019-08-13 Thread Max Haughton via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 18:54:58 UTC, H. S. Teoh wrote: On Tue, Aug 13, 2019 at 11:28:35AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: [...] Summary: Ditch the linked list and put the elements into an array. :) [...] +1. The linked list may have been faster 20 years ago, before

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

2019-08-13 Thread Sebastiaan Koppe via Digitalmars-d-learn
v pointers. If possible, I would go further and ditch the linked list altogether: Just append the nodes to an array and then sort the array. It has been shown in research, conference presentations, and in personal code to be the fasted option is most (or all) cases. Yeah, very like

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

2019-08-13 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 13, 2019 at 11:28:35AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: [...] > Summary: Ditch the linked list and put the elements into an array. :) [...] +1. The linked list may have been faster 20 years ago, before the advent of modern CPUs with caching hierarchies and mem

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

2019-08-13 Thread Ali Çehreli via Digitalmars-d-learn
rs. If possible, I would go further and ditch the linked list altogether: Just append the nodes to an array and then sort the array. It has been shown in research, conference presentations, and in personal code to be the fasted option is most (or all) cases. > doesn't the nature of the dynamic arr

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

2019-08-13 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 13, 2019 at 12:12:28PM -0600, Jonathan M Davis via Digitalmars-d-learn wrote: > On Tuesday, August 13, 2019 11:33:10 AM MDT Mirjam Akkersdijk via > Digitalmars-d-learn wrote: [...] > > Thank you, this is what I eventually chose to do. It's also fairly > > fast, though doesn't the

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

2019-08-13 Thread Johannes Loher via Digitalmars-d-learn
Am 13.08.19 um 11:48 schrieb Mirjam Akkersdijk: > 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

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

2019-08-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, August 13, 2019 11:33:10 AM MDT Mirjam Akkersdijk via Digitalmars-d-learn wrote: > On Tuesday, 13 August 2019 at 14:04:45 UTC, Sebastiaan Koppe > > wrote: > > On Tuesday, 13 August 2019 at 09:48:52 UTC, Mirjam Akkersdijk > > > > wrote: > >> and I would like to sort based on Node.t,

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

2019-08-13 Thread Mirjam Akkersdijk via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 14:04:45 UTC, Sebastiaan Koppe wrote: On Tuesday, 13 August 2019 at 09:48:52 UTC, Mirjam Akkersdijk wrote: and I would like to sort based on Node.t, how should I tackle it, preferably without resorting to C libraries? Convert the nodes into an D array, sort the

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

2019-08-13 Thread Mirjam Akkersdijk via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 12:34:46 UTC, bachmeier wrote: I'm confused by this statement. Are you referring to the qsort in C's stdlib? I had never heard of using that to sort a linked list, so I searched, and it is not possible. Ah yes, maybe I should have elaborated. In C, you can just

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

2019-08-13 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 09:48:52 UTC, Mirjam Akkersdijk wrote: and I would like to sort based on Node.t, how should I tackle it, preferably without resorting to C libraries? Convert the nodes into an D array, sort the array with nodes.sort!"a.x < b.x" and then iterate the array and

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

2019-08-13 Thread bachmeier via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 09:48:52 UTC, Mirjam Akkersdijk wrote: I would write my compare function and let qsort sort it out. I'm confused by this statement. Are you referring to the qsort in C's stdlib? I had never heard of using that to sort a linked list, so I searched

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

2019-08-13 Thread ikod via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 09:48:52 UTC, Mirjam Akkersdijk wrote: 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

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

2019-08-13 Thread Jonathan M Davis via Digitalmars-d-learn
ime. I don't know why you would think that arrays would need to know their size at compile time unless you've only been using static arrays. However, a doubly-linked list definitely isn't random access, so it wouldn't work with std.algorithm.sort, and I don't think that Phobos has anything which wo

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

2019-08-13 Thread Daniel Kozak via Digitalmars-d-learn
You can make an array from it On Tue, Aug 13, 2019 at 12:05 PM Mirjam Akkersdijk via Digitalmars-d-learn wrote: > > On Tuesday, 13 August 2019 at 09:48:52 UTC, Mirjam Akkersdijk > wrote: > > Hello there, > > If I had a DLL, how would I sort it judging by the node > > contents, the D way? > > > >

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

2019-08-13 Thread Mirjam Akkersdijk via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 09:48:52 UTC, Mirjam Akkersdijk wrote: Hello there, If I had a DLL, how would I sort it judging by the node contents, the D way? [...] Node.t Node.x, my bad

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

Re: Linked List iterating over and inserting an element around (before/after) the current position.

2019-05-19 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 19 May 2019 at 22:20:48 UTC, Josh wrote: Thank you, that helps big time. This is just more curiosity, but do you happen to know why I have to use DList.linearRemove() instead of DList.remove()? import std.stdio; import std.container.dlist; import std.algorithm; import std.range;

Re: Linked List iterating over and inserting an element around (before/after) the current position.

2019-05-19 Thread Boris-Barboris via Digitalmars-d-learn
On Sunday, 19 May 2019 at 22:20:48 UTC, Josh wrote: This is just more curiosity, but do you happen to know why I have to use DList.linearRemove() instead of DList.remove()? These two functions are separate because they differ in complexity. remove is O(1), linearRemove on the other hand

Re: Linked List iterating over and inserting an element around (before/after) the current position.

2019-05-19 Thread Josh via Digitalmars-d-learn
Thank you, that helps big time. This is just more curiosity, but do you happen to know why I have to use DList.linearRemove() instead of DList.remove()? import std.stdio; import std.container.dlist; import std.algorithm; import std.range; void main() { auto list = make!DList("the",

Re: Linked List iterating over and inserting an element around (before/after) the current position.

2019-05-19 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 19 May 2019 at 20:55:28 UTC, Josh wrote: Just started looking at D this weekend, coming from a C++/Java/Go/Rust background and it's really not going well. Trying to write something to play with the language and need a linked list, looking in std.container you have a single

Linked List iterating over and inserting an element around (before/after) the current position.

2019-05-19 Thread Josh via Digitalmars-d-learn
Just started looking at D this weekend, coming from a C++/Java/Go/Rust background and it's really not going well. Trying to write something to play with the language and need a linked list, looking in std.container you have a single or doubly linked list...great. Now how to I iterate over

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

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

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.

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't get a copy I

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

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 I call

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

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

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: 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 code. Here

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, maybe

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: //

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/blob/master

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

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,

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 linked list

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

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

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 talking

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

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 implemented

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

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 your

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

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 August

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

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:43:20

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 digitalmars-d-learn@puremagic.com 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 digitalmars-d-learn@puremagic.com wrote: Was that a joke or does opApplyReverse exist? it's not a joke. http://dlang.org/statement.html

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 within

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. 1. In your opinion

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's been

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 over the range will empty

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 list

  1   2   >