Thread overview | |||||
---|---|---|---|---|---|
|
July 10, 2020 So how do I find and remove an element from DList? | ||||
---|---|---|---|---|
| ||||
auto list = DList!int([1, 2, 3, 4]); list.remove(list[].find(2).take(1)); > Error: function std.container.dlist.DList!int.DList.remove(Range r) is not callable using argument types (Take!(Range)) It works if I replace `remove` with `linearRemove`, but that defeats the whole purpose of using a doubly linked list. |
July 10, 2020 Re: So how do I find and remove an element from DList? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ogi | On 7/10/20 3:08 PM, Ogi wrote:
> auto list = DList!int([1, 2, 3, 4]);
> list.remove(list[].find(2).take(1));
>
>> Error: function std.container.dlist.DList!int.DList.remove(Range r) is not callable using argument types (Take!(Range))
>
> It works if I replace `remove` with `linearRemove`, but that defeats the whole purpose of using a doubly linked list.
It's not linear over the size of the list, it's linear over the size of the range.
If you are always removing 1 element, it's effectively O(1).
-Steve
|
July 10, 2020 Re: So how do I find and remove an element from DList? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Friday, 10 July 2020 at 19:23:57 UTC, Steven Schveighoffer wrote:
> It's not linear over the size of the list, it's linear over the size of the range.
>
> If you are always removing 1 element, it's effectively O(1).
>
> -Steve
I see. Thanks!
|
Copyright © 1999-2021 by the D Language Foundation