digitalmars.D.learn - how to sort the container Array from std.container
- Flaze07 (6/6) Jun 06 2018 I know that sort accepts Range( I am correct right ? ), so,
- Adam D. Ruppe (5/8) Jun 06 2018 Range is the type, you want the value
- Flaze07 (5/13) Jun 06 2018 I see why it works, so, [] is called slice operator right ?
- rikki cattermole (2/18) Jun 06 2018 Yes.
- Flaze07 (6/25) Jun 06 2018 hmm, and sorry for asking more, what about removing an element
- rikki cattermole (3/30) Jun 06 2018 filter will remove any and all occurrences of whatever you tell it to.
- Flaze07 (2/17) Jun 06 2018 what about removing certain index ?
- rikki cattermole (2/19) Jun 06 2018 Indexes and ranges don't usually go together.
- Flaze07 (2/22) Jun 06 2018 welp, ok then, thank you
- Steven Schveighoffer (4/31) Jun 06 2018 To remove element 5, for example:
- ag0aep6g (16/20) Jun 06 2018 I think removeKey would be the container primitive for that. I don't
I know that sort accepts Range( I am correct right ? ), so, Array!uint arr; //inserts element to arr sort( arr.Range ); don't work, it says cannot pass RangeT!(Array!uint) as function argument
Jun 06 2018
On Wednesday, 6 June 2018 at 13:44:09 UTC, Flaze07 wrote:sort( arr.Range ); don't work, it says cannot pass RangeT!(Array!uint) as function argumentRange is the type, you want the value I think you can do sort(arr[]) maybe
Jun 06 2018
On Wednesday, 6 June 2018 at 13:46:41 UTC, Adam D. Ruppe wrote:On Wednesday, 6 June 2018 at 13:44:09 UTC, Flaze07 wrote:I see why it works, so, [] is called slice operator right ? and in https://dlang.org/phobos/std_container_array.html#.Array.opSlice it returns range, so that's why it workedsort( arr.Range ); don't work, it says cannot pass RangeT!(Array!uint) as function argumentRange is the type, you want the value I think you can do sort(arr[]) maybe
Jun 06 2018
On 07/06/2018 1:58 AM, Flaze07 wrote:On Wednesday, 6 June 2018 at 13:46:41 UTC, Adam D. Ruppe wrote:Yes.On Wednesday, 6 June 2018 at 13:44:09 UTC, Flaze07 wrote:I see why it works, so, [] is called slice operator right ? and in https://dlang.org/phobos/std_container_array.html#.Array.opSlice it returns range, so that's why it workedsort( arr.Range ); don't work, it says cannot pass RangeT!(Array!uint) as function argumentRange is the type, you want the value I think you can do sort(arr[]) maybe
Jun 06 2018
On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:On 07/06/2018 1:58 AM, Flaze07 wrote:hmm, and sorry for asking more, what about removing an element from it ? I found no remove operation that can remove from the middle ( removeAny and removeBack both removes the latest element, linearRemove receive Array!uint...which don't know how to provide )On Wednesday, 6 June 2018 at 13:46:41 UTC, Adam D. Ruppe wrote:Yes.On Wednesday, 6 June 2018 at 13:44:09 UTC, Flaze07 wrote:I see why it works, so, [] is called slice operator right ? and in https://dlang.org/phobos/std_container_array.html#.Array.opSlice it returns range, so that's why it workedsort( arr.Range ); don't work, it says cannot pass RangeT!(Array!uint) as function argumentRange is the type, you want the value I think you can do sort(arr[]) maybe
Jun 06 2018
On 07/06/2018 2:20 AM, Flaze07 wrote:On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:filter will remove any and all occurrences of whatever you tell it to. But only in the range not the origin data structure.On 07/06/2018 1:58 AM, Flaze07 wrote:hmm, and sorry for asking more, what about removing an element from it ? I found no remove operation that can remove from the middle ( removeAny and removeBack both removes the latest element, linearRemove receive Array!uint...which don't know how to provide )On Wednesday, 6 June 2018 at 13:46:41 UTC, Adam D. Ruppe wrote:Yes.On Wednesday, 6 June 2018 at 13:44:09 UTC, Flaze07 wrote:I see why it works, so, [] is called slice operator right ? and in https://dlang.org/phobos/std_container_array.html#.Array.opSlice it returns range, so that's why it workedsort( arr.Range ); don't work, it says cannot pass RangeT!(Array!uint) as function argumentRange is the type, you want the value I think you can do sort(arr[]) maybe
Jun 06 2018
On Wednesday, 6 June 2018 at 14:24:15 UTC, rikki cattermole wrote:On 07/06/2018 2:20 AM, Flaze07 wrote:what about removing certain index ?On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:filter will remove any and all occurrences of whatever you tell it to. But only in the range not the origin data structure.On 07/06/2018 1:58 AM, Flaze07 wrote:hmm, and sorry for asking more, what about removing an element from it ? I found no remove operation that can remove from the middle ( removeAny and removeBack both removes the latest element, linearRemove receive Array!uint...which don't know how to provide )[...]Yes.
Jun 06 2018
On 07/06/2018 2:27 AM, Flaze07 wrote:On Wednesday, 6 June 2018 at 14:24:15 UTC, rikki cattermole wrote:Indexes and ranges don't usually go together.On 07/06/2018 2:20 AM, Flaze07 wrote:what about removing certain index ?On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:filter will remove any and all occurrences of whatever you tell it to. But only in the range not the origin data structure.On 07/06/2018 1:58 AM, Flaze07 wrote:hmm, and sorry for asking more, what about removing an element from it ? I found no remove operation that can remove from the middle ( removeAny and removeBack both removes the latest element, linearRemove receive Array!uint...which don't know how to provide )[...]Yes.
Jun 06 2018
On Wednesday, 6 June 2018 at 14:29:28 UTC, rikki cattermole wrote:On 07/06/2018 2:27 AM, Flaze07 wrote:welp, ok then, thank youOn Wednesday, 6 June 2018 at 14:24:15 UTC, rikki cattermole wrote:Indexes and ranges don't usually go together.On 07/06/2018 2:20 AM, Flaze07 wrote:what about removing certain index ?On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:filter will remove any and all occurrences of whatever you tell it to. But only in the range not the origin data structure.[...]hmm, and sorry for asking more, what about removing an element from it ? I found no remove operation that can remove from the middle ( removeAny and removeBack both removes the latest element, linearRemove receive Array!uint...which don't know how to provide )
Jun 06 2018
On 6/6/18 10:20 AM, Flaze07 wrote:On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:To remove element 5, for example: arr.linearRemove(arr[5 .. 6]); -SteveOn 07/06/2018 1:58 AM, Flaze07 wrote:hmm, and sorry for asking more, what about removing an element from it ? I found no remove operation that can remove from the middle ( removeAny and removeBack both removes the latest element, linearRemove receive Array!uint...which don't know how to provide )On Wednesday, 6 June 2018 at 13:46:41 UTC, Adam D. Ruppe wrote:Yes.On Wednesday, 6 June 2018 at 13:44:09 UTC, Flaze07 wrote:I see why it works, so, [] is called slice operator right ? and in https://dlang.org/phobos/std_container_array.html#.Array.opSlice it returns range, so that's why it workedsort( arr.Range ); don't work, it says cannot pass RangeT!(Array!uint) as function argumentRange is the type, you want the value I think you can do sort(arr[]) maybe
Jun 06 2018
On 06/06/2018 04:20 PM, Flaze07 wrote:hmm, and sorry for asking more, what about removing an element from it ? I found no remove operation that can remove from the middle ( removeAny and removeBack both removes the latest element, linearRemove receive Array!uint...which don't know how to provide )I think removeKey would be the container primitive for that. I don't know if there's a reason why it isn't implemented for Array. Maybe it's just an oversight. You can use linearRemove like this: ---- import std.container.array: Array; import std.stdio: writeln; void main() { Array!int a = [1, 2, 100, 200, 300, 3, 4]; a.linearRemove(a[2 .. 5]); /* Removes elements at indices 2, 3, and 4. */ writeln(a[]); /* Prints "[1, 2, 3, 4]". */ } ----
Jun 06 2018
On Wednesday, 6 June 2018 at 14:46:56 UTC, ag0aep6g wrote:On 06/06/2018 04:20 PM, Flaze07 wrote:ah...well thank you, well...I did finds another way, but it is probably better to use linearRemove I used arr = make!( Array!uint )( remove( arr[], 2 ); so linearRemove is probably betterhmm, and sorry for asking more, what about removing an element from it ? I found no remove operation that can remove from the middle ( removeAny and removeBack both removes the latest element, linearRemove receive Array!uint...which don't know how to provide )I think removeKey would be the container primitive for that. I don't know if there's a reason why it isn't implemented for Array. Maybe it's just an oversight. You can use linearRemove like this: ---- import std.container.array: Array; import std.stdio: writeln; void main() { Array!int a = [1, 2, 100, 200, 300, 3, 4]; a.linearRemove(a[2 .. 5]); /* Removes elements at indices 2, 3, and 4. */ writeln(a[]); /* Prints "[1, 2, 3, 4]". */ } ----
Jun 08 2018
On 06/08/2018 10:52 AM, Flaze07 wrote:ah...well thank you, well...I did finds another way, but it is probably better to use linearRemove I used arr = make!( Array!uint )( remove( arr[], 2 ); so linearRemove is probably betterInstead of creating a new array, you could update the length of the existing one: arr.length = remove(arr[], 2).length; But linearRemove is probably clearer.
Jun 08 2018