Re: how to sort the container Array from std.container

2018-06-08 Thread ag0aep6g via Digitalmars-d-learn

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 better


Instead 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.


Re: how to sort the container Array from std.container

2018-06-08 Thread Flaze07 via Digitalmars-d-learn

On Wednesday, 6 June 2018 at 14:46:56 UTC, ag0aep6g wrote:

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]". */
}



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 better


Re: how to sort the container Array from std.container

2018-06-06 Thread ag0aep6g via Digitalmars-d-learn

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]". */
}



Re: how to sort the container Array from std.container

2018-06-06 Thread Steven Schveighoffer via Digitalmars-d-learn

On 6/6/18 10:20 AM, Flaze07 wrote:

On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:

On 07/06/2018 1:58 AM, Flaze07 wrote:

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:

sort( arr.Range );
don't work, it says cannot pass RangeT!(Array!uint) as function 
argument


Range is the type, you want the value

I think you can do

sort(arr[])

maybe


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 worked


Yes.


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 )


To remove element 5, for example:
arr.linearRemove(arr[5 .. 6]);

-Steve


Re: how to sort the container Array from std.container

2018-06-06 Thread Flaze07 via Digitalmars-d-learn

On Wednesday, 6 June 2018 at 14:29:28 UTC, rikki cattermole wrote:

On 07/06/2018 2:27 AM, Flaze07 wrote:
On Wednesday, 6 June 2018 at 14:24:15 UTC, rikki cattermole 
wrote:

On 07/06/2018 2:20 AM, Flaze07 wrote:
On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole 
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 )


filter will remove any and all occurrences of whatever you 
tell it to. But only in the range not the origin data 
structure.


what about removing certain index ?


Indexes and ranges don't usually go together.


welp, ok then, thank you


Re: how to sort the container Array from std.container

2018-06-06 Thread rikki cattermole via Digitalmars-d-learn

On 07/06/2018 2:27 AM, Flaze07 wrote:

On Wednesday, 6 June 2018 at 14:24:15 UTC, rikki cattermole wrote:

On 07/06/2018 2:20 AM, Flaze07 wrote:

On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:

On 07/06/2018 1:58 AM, Flaze07 wrote:

[...]


Yes.


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 )


filter will remove any and all occurrences of whatever you tell it to. 
But only in the range not the origin data structure.


what about removing certain index ?


Indexes and ranges don't usually go together.


Re: how to sort the container Array from std.container

2018-06-06 Thread Flaze07 via Digitalmars-d-learn

On Wednesday, 6 June 2018 at 14:24:15 UTC, rikki cattermole wrote:

On 07/06/2018 2:20 AM, Flaze07 wrote:
On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole 
wrote:

On 07/06/2018 1:58 AM, Flaze07 wrote:

[...]


Yes.


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 )


filter will remove any and all occurrences of whatever you tell 
it to. But only in the range not the origin data structure.


what about removing certain index ?


Re: how to sort the container Array from std.container

2018-06-06 Thread rikki cattermole via Digitalmars-d-learn

On 07/06/2018 2:20 AM, Flaze07 wrote:

On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:

On 07/06/2018 1:58 AM, Flaze07 wrote:

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:

sort( arr.Range );
don't work, it says cannot pass RangeT!(Array!uint) as function 
argument


Range is the type, you want the value

I think you can do

sort(arr[])

maybe


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 worked


Yes.


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 )


filter will remove any and all occurrences of whatever you tell it to. 
But only in the range not the origin data structure.


Re: how to sort the container Array from std.container

2018-06-06 Thread Flaze07 via Digitalmars-d-learn

On Wednesday, 6 June 2018 at 14:06:54 UTC, rikki cattermole wrote:

On 07/06/2018 1:58 AM, Flaze07 wrote:

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:

sort( arr.Range );
don't work, it says cannot pass RangeT!(Array!uint) as 
function argument


Range is the type, you want the value

I think you can do

sort(arr[])

maybe


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 worked


Yes.


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 )


Re: how to sort the container Array from std.container

2018-06-06 Thread rikki cattermole via Digitalmars-d-learn

On 07/06/2018 1:58 AM, Flaze07 wrote:

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:

sort( arr.Range );
don't work, it says cannot pass RangeT!(Array!uint) as function argument


Range is the type, you want the value

I think you can do

sort(arr[])

maybe


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 worked


Yes.


Re: how to sort the container Array from std.container

2018-06-06 Thread Flaze07 via Digitalmars-d-learn

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:

sort( arr.Range );
don't work, it says cannot pass RangeT!(Array!uint) as 
function argument


Range is the type, you want the value

I think you can do

sort(arr[])

maybe


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 worked


Re: how to sort the container Array from std.container

2018-06-06 Thread Adam D. Ruppe via Digitalmars-d-learn

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 
argument


Range is the type, you want the value

I think you can do

sort(arr[])

maybe


how to sort the container Array from std.container

2018-06-06 Thread Flaze07 via Digitalmars-d-learn

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


Re: Container Array or tuples Sorting

2017-12-13 Thread Vino via Digitalmars-d-learn

On Wednesday, 13 December 2017 at 15:58:40 UTC, Vino wrote:

On Wednesday, 13 December 2017 at 15:16:50 UTC, Vino wrote:

Hi All,

 Request your help, on how to sort a tuple container array, I 
have raised the same topic in one of the other thread "Tuple 
Array Sorting" and was addressed to use standard array rather 
than container array, and i am not able to find any document 
or example in the library for the same.


Eg: Program.
import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;

void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT"];
Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir)

.sort!((a,b) => a.timeCreated > b.timeCreated)
.map!(a => tuple(a.name, a.timeCreated)));
writeln(dFiles[]);
} }

From,
Vino.B


HI All,

  As per the message from the below forum  I understand that 
that we cannot perform a sorting on filtered result a container 
array but the same can be performed form the standard array, so 
i adjusted the above code as below and getting a different 
error than what is discussed in the forum.


Forum:
 
"https://forum.dlang.org/post/mcteinnryudlqvbkq...@forum.dlang.org;


Program:
void main () {
auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", 
"C:\\Temp\\sapnas2\\EXPORT"];

Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)))[]

.sort!((a,b) => a[1] > b[1]);
writeln(dFiles[]);
} }

Error:
Message.d(14): Error: function 
Message.main.SortedRange!(RangeT!(Array!(Tuple!(string, 
SysTime))), __lambda3).SortedRange.opSlice (uint a, uint b) is 
not callab

le using argument types ()
Failed: ["dmd", "-v", "-o-", "Message.d", "-I."]

From,
Vino.B


Hi All,

 Was able to find a solution and it is working as expected

import std.algorithm: filter, map, sort, each;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln,writefln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;
import std.conv;
void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT"];
Array!(Tuple!(string, SysTime)) Sorted;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)));

foreach(i; dFiles[]){ Sorted ~= i; }
Sorted[].sort!((a,b) => a[1] > b[1]).each!(e => writefln!"%-63s 
%.20s"(e[0], e[1].to!string));

}
}

From,
Vino.B


Re: Container Array or tuples Sorting

2017-12-13 Thread Vino via Digitalmars-d-learn

On Wednesday, 13 December 2017 at 15:16:50 UTC, Vino wrote:

Hi All,

 Request your help, on how to sort a tuple container array, I 
have raised the same topic in one of the other thread "Tuple 
Array Sorting" and was addressed to use standard array rather 
than container array, and i am not able to find any document or 
example in the library for the same.


Eg: Program.
import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;

void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT"];
Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir)

.sort!((a,b) => a.timeCreated > b.timeCreated)
.map!(a => tuple(a.name, a.timeCreated)));
writeln(dFiles[]);
} }

From,
Vino.B


HI All,

  As per the message from the below forum  I understand that that 
we cannot perform a sorting on filtered result a container array 
but the same can be performed form the standard array, so i 
adjusted the above code as below and getting a different error 
than what is discussed in the forum.


Forum:
 
"https://forum.dlang.org/post/mcteinnryudlqvbkq...@forum.dlang.org;


Program:
void main () {
auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", 
"C:\\Temp\\sapnas2\\EXPORT"];

Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)))[]

.sort!((a,b) => a[1] > b[1]);
writeln(dFiles[]);
} }

Error:
Message.d(14): Error: function 
Message.main.SortedRange!(RangeT!(Array!(Tuple!(string, 
SysTime))), __lambda3).SortedRange.opSlice (uint a, uint b) is 
not callab

le using argument types ()
Failed: ["dmd", "-v", "-o-", "Message.d", "-I."]

From,
Vino.B


Container Array or tuples Sorting

2017-12-13 Thread Vino via Digitalmars-d-learn

Hi All,

 Request your help, on how to sort a tuple container array, I 
have raised the same topic in one of the other thread "Tuple 
Array Sorting" and was addressed to use standard array rather 
than container array, and i am not able to find any document or 
example in the library for the same.


Eg: Program.
import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;

void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT"];
Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir)

.sort!((a,b) => a.timeCreated > b.timeCreated)
.map!(a => tuple(a.name, a.timeCreated)));
writeln(dFiles[]);
} }

From,
Vino.B



Re: Question on Container Array.

2017-09-18 Thread Eugene Wissner via Digitalmars-d-learn

On Monday, 18 September 2017 at 11:47:07 UTC, Vino.B wrote:

Hi All,

  Can some one explain me on the below question.

Q1: void main (Array!string args) : Why can't we use container 
array in void main?


Q2: What is the difference between the below?
insert, insertBack
stableInsert, stableInsertBack
linearInsert, stableLinearInsert, stableLinearInsert

Q3: Storing the data in a container array store's the data in 
memory which is managed by malloc/free, where as operation such 
as appending data using any of the above nor "~=" is managed by 
gc, is my understanding correct.



From,
Vino.B


Q1: I think that someone could explain it better, but basically a 
program gets its arguments as an array of C strings. So a C main 
looks like:


main(int argc, char **argv);

To make this a bit safer, D's main works with an array of strings 
instead of pointers. D's main function is called from druntime: 
https://github.com/dlang/druntime/blob/95fd6e1e395e6320284a22f5d19fa41de8e1dcbb/src/rt/dmain2.d#L301. And it wouldn't be that cool to make the druntime depend on phobos and containers. But theoretically it would be possible to make 'void main (Array!string args)' with custom dmd and druntime.


Q2: They are the same for Array. But theoretically they can be 
defined differently. "stable" in "stableInsert" just means that a 
range got from container can be used after changing the 
container. So if you get an Array range with Array[], you can 
still use this range after stableInsert. "insert" is just shorter 
than "insertBack".


Q3: "~=" uses GC only for built-in arrays. You can define your 
own "~=" for containers. "~=" for Array calls insertBack. So it 
will use malloc here.


Question on Container Array.

2017-09-18 Thread Vino.B via Digitalmars-d-learn

Hi All,

  Can some one explain me on the below question.

Q1: void main (Array!string args) : Why can't we use container 
array in void main?


Q2: What is the difference between the below?
insert, insertBack
stableInsert, stableInsertBack
linearInsert, stableLinearInsert, stableLinearInsert

Q3: Storing the data in a container array store's the data in 
memory which is managed by malloc/free, where as operation such 
as appending data using any of the above nor "~=" is managed by 
gc, is my understanding correct.



From,
Vino.B




Re: Container Array

2017-09-08 Thread Vino.B via Digitalmars-d-learn

On Friday, 8 September 2017 at 15:48:47 UTC, Vino.B wrote:

On Friday, 8 September 2017 at 12:14:46 UTC, Vino.B wrote:

On Friday, 8 September 2017 at 09:51:38 UTC, Ali Çehreli wrote:

[...]


Hi Ali,

  As stated earlier my release 1 code are still using 
std.array, so now in release 2 i am converting all my standard 
array to container array. My program has 5 function and I was 
able to adopt 4 function to container array, and facing issue 
with this 1 function. I would like to have all my function to 
be neither in standard array nor in container array, more over 
I am facing gc issue in standard array and this is the main 
reason I would like to convert my function to container array, 
as this function would find the size of folder which are 
greater then a specified size in a 5 file system each with 10 
TB, so i have added the thread(with Local storage) and 
parallelism to my function as container array give's me the 
option of reserving memory, so that i would bump it up as and 
when it is required with any gc issues. All help to resolve 
this issue would be appreciated.


Updated Code:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

Tuple!(RangeT!(Array!string), RangeT!(Array!ulong)) 
coSizeDirList () {

string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subdir;
Array!(ulong) Subsize;
Tuple!((Array!string), (Array!string)) Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; dFiles[]) {
auto SdFiles = Array!ulong ((dirEntries(d, 
SpanMode.depth)).map!(a => a.size));

foreach(f; SdFiles[]) { subdirTotal += f; }
	subdirTotalGB = (subdirTotal/1024/1024); { Subdir ~= d; 
Subsize ~= subdirTotalGB; }

if (subdirTotalGB > SizeDir)
subdirTotal = 0;
}
return tuple (Subdir[], Subsize[]);
}

void main () {
writeln(coSizeDirList[]);
}

From,
Vino.B


Hi Ali,

 Was able to resolve the above issue but not sure whether it is 
correct and now i am getting the output as below, request your 
help.


Output:
C:\Temp\sapnas2\BACKUP\dir1, 34, C:\Temp\sapnas2\BACKUP\DND3, 
1, C:\Temp\sapnas2\BACKUP\DND5, 5


Required Output:
C:\Temp\sapnas2\BACKUP\dir134
C:\Temp\sapnas2\BACKUP\DND3 1
C:\Temp\sapnas2\BACKUP\DND5 5

Program:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir, isFile;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

Array!string coSizeDirList () {
string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subsize;
Array!string Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; dFiles[]) {
auto SdFiles = Array!ulong(dirEntries(d, 
SpanMode.depth).map!(a => a.size));

foreach(f; SdFiles[]) { subdirTotal += f; }
subdirTotalGB = (subdirTotal/1024/1024); { Result ~= d; 
Result ~= to!string(subdirTotalGB); }

if (subdirTotalGB > SizeDir)
subdirTotal = 0;
}
return Result;
}

void main () {
writefln("%-(%s, %)", coSizeDirList[]);
}

From,
Vino.B


Hi Ali,

 At last was able to resolve the issue including the output too, 
thank you very much for your help, please let me know in case if 
you find any issue with the below code.


import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir, isFile;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

string[][] coSizeDirList () {
string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subsize;
string[][] Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; dFiles[]) {
auto SdFiles = Array!ulong(dirEntries(d, 
SpanMode.depth).map!(a => a.size));

foreach(f; SdFiles[]) { subdirTotal += f; }
subdirTotalGB = 

Re: Container Array

2017-09-08 Thread Vino.B via Digitalmars-d-learn

On Friday, 8 September 2017 at 12:14:46 UTC, Vino.B wrote:

On Friday, 8 September 2017 at 09:51:38 UTC, Ali Çehreli wrote:

On 09/07/2017 11:21 PM, Vino.B wrote:

>   At last was able to print the output, but i am getting some
> "Deprecation" warnings like below and also can you help me in
formating
> the output to display ulong.
>
> Output:
> Size.d(9): Deprecation: std.container.array.RangeT(A) is not
visible
> from module Size

That's due to std.container.array.RangeT being private. The 
deprecation warning is about a bug that leaked such private 
symbols when they were imported selectively (I think). Now the 
bug is fixed, you won't be able to access the symbol at the 
end of the deprecation period.


> import std.algorithm: filter, map, fold;
> import std.container;
> import std.file: SpanMode, dirEntries, isDir;
> import std.stdio: File, writefln, writeln;
> import std.typecons: tuple, Tuple;
> import std.parallelism: parallel;
> import std.conv;
> import std.range;
> Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong))
> coSizeDirList () {
> string FFs = "C:\\Temp\\sapnas2\\BACKUP";
> int SizeDir = 1;
> ulong subdirTotal;
> ulong subdirTotalGB;
> Array!(ulong) Subdata;
> auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs,
> SpanMode.shallow).filter!(a => a.isDir).map!(a =>
tuple(a.name)));
> foreach (d; dFiles[]) {
> auto SdFiles = Array!(Tuple!(ulong))
(dirEntries(d[0],
> SpanMode.depth).map!(a => tuple(a.size)));
> foreach(f; SdFiles[]) { subdirTotal +=
f.fold!((a, b) =>
> a + b); }
> subdirTotalGB = (subdirTotal/1024/1024);
> if (subdirTotalGB > SizeDir) { Subdata ~=
> subdirTotalGB; }
> subdirTotal = 0;
> }
> return tuple (dFiles[], Subdata[]);
> }
>
> void main () {
> writeln(coSizeDirList[]);
> //writefln("%(%-(%-63s %)\n%)", coSizeDirList[]);
> }

I apologize for not really having time to look at what you're 
trying to achieve. I gave you advice which ended up trying to 
solve compilation errors.


I think the main problem here is to determine directories 
above a certain size. So, I think Array should enter the 
picture only if built-in arrays are not usable for some 
reason. Even better, one should stay with lazy range 
algorithms as long as it's possible.


How about the following approach, which you can either use 
directly or populate an Array with:


import std.algorithm: filter, map, sum;
import std.file: SpanMode, dirEntries, isDir, DirEntry;
import std.stdio: writeln;

auto dFiles(string dirName) {
return dirEntries(dirName, SpanMode.shallow).filter!(a => 
a.isDir);

}

auto totalSize(DirEntry dir) {
return dirEntries(dir, SpanMode.depth).map!(a => 
a.size).sum;

}

struct DirInfo {
string name;
ulong size;
}

auto coSizeDirList (string dirName, ulong sizeLimit) {
return dFiles(dirName).map!(dir => DirInfo(dir.name, 
dir.totalSize)).filter!(info => info.size > sizeLimit);

}

void main () {
writeln(coSizeDirList("./deleteme", 1));

// Only if Array is really needed:
import std.container : Array;
auto arr = Array!DirInfo(coSizeDirList("./deleteme", 42));
writeln(arr[]);
}

Ali


Hi Ali,

  As stated earlier my release 1 code are still using 
std.array, so now in release 2 i am converting all my standard 
array to container array. My program has 5 function and I was 
able to adopt 4 function to container array, and facing issue 
with this 1 function. I would like to have all my function to 
be neither in standard array nor in container array, more over 
I am facing gc issue in standard array and this is the main 
reason I would like to convert my function to container array, 
as this function would find the size of folder which are 
greater then a specified size in a 5 file system each with 10 
TB, so i have added the thread(with Local storage) and 
parallelism to my function as container array give's me the 
option of reserving memory, so that i would bump it up as and 
when it is required with any gc issues. All help to resolve 
this issue would be appreciated.


Updated Code:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

Tuple!(RangeT!(Array!string), RangeT!(Array!ulong)) 
coSizeDirList () {

string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subdir;
Array!(ulong) Subsize;
Tuple!((Array!string), (Array!string)) Result;
	auto d

Re: Container Array

2017-09-08 Thread Vino.B via Digitalmars-d-learn

On Friday, 8 September 2017 at 09:51:38 UTC, Ali Çehreli wrote:

On 09/07/2017 11:21 PM, Vino.B wrote:

>   At last was able to print the output, but i am getting some
> "Deprecation" warnings like below and also can you help me in
formating
> the output to display ulong.
>
> Output:
> Size.d(9): Deprecation: std.container.array.RangeT(A) is not
visible
> from module Size

That's due to std.container.array.RangeT being private. The 
deprecation warning is about a bug that leaked such private 
symbols when they were imported selectively (I think). Now the 
bug is fixed, you won't be able to access the symbol at the end 
of the deprecation period.


> import std.algorithm: filter, map, fold;
> import std.container;
> import std.file: SpanMode, dirEntries, isDir;
> import std.stdio: File, writefln, writeln;
> import std.typecons: tuple, Tuple;
> import std.parallelism: parallel;
> import std.conv;
> import std.range;
> Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong))
> coSizeDirList () {
> string FFs = "C:\\Temp\\sapnas2\\BACKUP";
> int SizeDir = 1;
> ulong subdirTotal;
> ulong subdirTotalGB;
> Array!(ulong) Subdata;
> auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs,
> SpanMode.shallow).filter!(a => a.isDir).map!(a =>
tuple(a.name)));
> foreach (d; dFiles[]) {
> auto SdFiles = Array!(Tuple!(ulong))
(dirEntries(d[0],
> SpanMode.depth).map!(a => tuple(a.size)));
> foreach(f; SdFiles[]) { subdirTotal +=
f.fold!((a, b) =>
> a + b); }
> subdirTotalGB = (subdirTotal/1024/1024);
> if (subdirTotalGB > SizeDir) { Subdata ~=
> subdirTotalGB; }
> subdirTotal = 0;
> }
> return tuple (dFiles[], Subdata[]);
> }
>
> void main () {
> writeln(coSizeDirList[]);
> //writefln("%(%-(%-63s %)\n%)", coSizeDirList[]);
> }

I apologize for not really having time to look at what you're 
trying to achieve. I gave you advice which ended up trying to 
solve compilation errors.


I think the main problem here is to determine directories above 
a certain size. So, I think Array should enter the picture only 
if built-in arrays are not usable for some reason. Even better, 
one should stay with lazy range algorithms as long as it's 
possible.


How about the following approach, which you can either use 
directly or populate an Array with:


import std.algorithm: filter, map, sum;
import std.file: SpanMode, dirEntries, isDir, DirEntry;
import std.stdio: writeln;

auto dFiles(string dirName) {
return dirEntries(dirName, SpanMode.shallow).filter!(a => 
a.isDir);

}

auto totalSize(DirEntry dir) {
return dirEntries(dir, SpanMode.depth).map!(a => 
a.size).sum;

}

struct DirInfo {
string name;
ulong size;
}

auto coSizeDirList (string dirName, ulong sizeLimit) {
return dFiles(dirName).map!(dir => DirInfo(dir.name, 
dir.totalSize)).filter!(info => info.size > sizeLimit);

}

void main () {
writeln(coSizeDirList("./deleteme", 1));

// Only if Array is really needed:
import std.container : Array;
auto arr = Array!DirInfo(coSizeDirList("./deleteme", 42));
writeln(arr[]);
}

Ali


Hi Ali,

  As stated earlier my release 1 code are still using std.array, 
so now in release 2 i am converting all my standard array to 
container array. My program has 5 function and I was able to 
adopt 4 function to container array, and facing issue with this 1 
function. I would like to have all my function to be neither in 
standard array nor in container array, more over I am facing gc 
issue in standard array and this is the main reason I would like 
to convert my function to container array, as this function would 
find the size of folder which are greater then a specified size 
in a 5 file system each with 10 TB, so i have added the 
thread(with Local storage) and parallelism to my function as 
container array give's me the option of reserving memory, so that 
i would bump it up as and when it is required with any gc issues. 
All help to resolve this issue would be appreciated.


Updated Code:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

Tuple!(RangeT!(Array!string), RangeT!(Array!ulong)) coSizeDirList 
() {

string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subdir;
Array!(ulong) Subsize;
Tuple!((Array!string), (Array!string)) Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.i

Re: Container Array

2017-09-08 Thread Ali Çehreli via Digitalmars-d-learn

On 09/07/2017 11:21 PM, Vino.B wrote:

>   At last was able to print the output, but i am getting some
> "Deprecation" warnings like below and also can you help me in formating
> the output to display ulong.
>
> Output:
> Size.d(9): Deprecation: std.container.array.RangeT(A) is not visible
> from module Size

That's due to std.container.array.RangeT being private. The deprecation 
warning is about a bug that leaked such private symbols when they were 
imported selectively (I think). Now the bug is fixed, you won't be able 
to access the symbol at the end of the deprecation period.


> import std.algorithm: filter, map, fold;
> import std.container;
> import std.file: SpanMode, dirEntries, isDir;
> import std.stdio: File, writefln, writeln;
> import std.typecons: tuple, Tuple;
> import std.parallelism: parallel;
> import std.conv;
> import std.range;
> Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong))
> coSizeDirList () {
> string FFs = "C:\\Temp\\sapnas2\\BACKUP";
> int SizeDir = 1;
> ulong subdirTotal;
> ulong subdirTotalGB;
> Array!(ulong) Subdata;
> auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs,
> SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name)));
> foreach (d; dFiles[]) {
> auto SdFiles = Array!(Tuple!(ulong)) (dirEntries(d[0],
> SpanMode.depth).map!(a => tuple(a.size)));
> foreach(f; SdFiles[]) { subdirTotal += f.fold!((a, b) =>
> a + b); }
> subdirTotalGB = (subdirTotal/1024/1024);
> if (subdirTotalGB > SizeDir) { Subdata ~=
> subdirTotalGB; }
> subdirTotal = 0;
> }
> return tuple (dFiles[], Subdata[]);
> }
>
> void main () {
> writeln(coSizeDirList[]);
> //writefln("%(%-(%-63s %)\n%)", coSizeDirList[]);
> }

I apologize for not really having time to look at what you're trying to 
achieve. I gave you advice which ended up trying to solve compilation 
errors.


I think the main problem here is to determine directories above a 
certain size. So, I think Array should enter the picture only if 
built-in arrays are not usable for some reason. Even better, one should 
stay with lazy range algorithms as long as it's possible.


How about the following approach, which you can either use directly or 
populate an Array with:


import std.algorithm: filter, map, sum;
import std.file: SpanMode, dirEntries, isDir, DirEntry;
import std.stdio: writeln;

auto dFiles(string dirName) {
return dirEntries(dirName, SpanMode.shallow).filter!(a => a.isDir);
}

auto totalSize(DirEntry dir) {
return dirEntries(dir, SpanMode.depth).map!(a => a.size).sum;
}

struct DirInfo {
string name;
ulong size;
}

auto coSizeDirList (string dirName, ulong sizeLimit) {
return dFiles(dirName).map!(dir => DirInfo(dir.name, 
dir.totalSize)).filter!(info => info.size > sizeLimit);

}

void main () {
writeln(coSizeDirList("./deleteme", 1));

// Only if Array is really needed:
import std.container : Array;
auto arr = Array!DirInfo(coSizeDirList("./deleteme", 42));
writeln(arr[]);
}

Ali



Re: Container Array

2017-09-08 Thread Vino.B via Digitalmars-d-learn

On Thursday, 7 September 2017 at 20:47:43 UTC, Ali Çehreli wrote:

On 09/07/2017 10:39 AM, Vino.B wrote:

> Array!(Tuple!(string, ulong)) coSizeDirList () {

You stated the return type explicitly above.

> return tuple (dFiles[], Subdata[]);

According to the error message, what is being returned does not 
have the same type:


> Test1.d(27): Error: cannot implicitly convert expression
> (tuple(dFiles.opSlice(), Subdata.opSlice())) of type
> Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong)) to
> Array!(Tuple!(string, ulong))

The actual return type is

Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong))

There needs to be some transformations to match the two.

Ali


Hi Ali,

  At last was able to print the output, but i am getting some 
"Deprecation" warnings like below and also can you help me in 
formating the output to display ulong.


Output:
Size.d(9): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(9): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(9): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(9): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
[Tuple!string("C:\\Temp\\sapnas2\\BACKUP\\dir1"), 
Tuple!string("C:\\Temp\\sapnas2\\BACKUP\\DND3"), 
Tuple!string("C:\\Temp\\sapnas2\\BACKUP\\DND5")][34, 4]


Program:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;
Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong)) 
coSizeDirList () {

string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(ulong) Subdata;
	auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name)));

foreach (d; dFiles[]) {
auto SdFiles = Array!(Tuple!(ulong)) (dirEntries(d[0], 
SpanMode.depth).map!(a => tuple(a.size)));
foreach(f; SdFiles[]) { subdirTotal += f.fold!((a, b) => a + 
b); }

subdirTotalGB = (subdirTotal/1024/1024);
if (subdirTotalGB > SizeDir) { Subdata 
~= subdirTotalGB; }
subdirTotal = 0;
}
return tuple (dFiles[], Subdata[]);
}

void main () {
writeln(coSizeDirList[]);
//writefln("%(%-(%-63s %)\n%)", coSizeDirList[]);
}


Re: Container Array

2017-09-07 Thread Ali Çehreli via Digitalmars-d-learn

On 09/07/2017 10:39 AM, Vino.B wrote:

> Array!(Tuple!(string, ulong)) coSizeDirList () {

You stated the return type explicitly above.

> return tuple (dFiles[], Subdata[]);

According to the error message, what is being returned does not have the 
same type:


> Test1.d(27): Error: cannot implicitly convert expression
> (tuple(dFiles.opSlice(), Subdata.opSlice())) of type
> Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong)) to
> Array!(Tuple!(string, ulong))

The actual return type is

Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong))

There needs to be some transformations to match the two.

Ali



Re: Container Array

2017-09-07 Thread Vino.B via Digitalmars-d-learn

On Thursday, 7 September 2017 at 17:12:14 UTC, Vino.B wrote:

On Thursday, 7 September 2017 at 15:07:56 UTC, Vino.B wrote:
On Thursday, 7 September 2017 at 14:26:08 UTC, Ali Çehreli 
wrote:

On 09/07/2017 03:56 AM, Vino.B wrote:


writeln(coCleanFiles);


Access the elements by taking a slice of the container:

writeln(coCleanFiles[]);

Ali


Hi Ali,

 Thank you very much, was ablee to resolve this issue and now 
facing a new issue as the below code is not working as 
expected. The below code has to list the folders and their 
size's.


import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;

Array!(Tuple!(string, ulong)) coSizeDirList () {
string FFs = "C:\\Temp\\TEST1\\BACKUP";
int SizeDir = 10;
ulong subdirTotal;
ulong subdirTotalGB;
	auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => 
tuple(a.name)));

foreach (d; dFiles) {
auto SdFiles = Array!(Tuple!(ulong)) (dirEntries(d[0], 
SpanMode.depth).map!(a => tuple(a.size)));
foreach(f; parallel(SdFiles, 1)) { subdirTotal += 
f.fold!((a, b) => a + b); }

subdirTotalGB = (subdirTotal/1024/1024);
	if (subdirTotalGB > SizeDir) { auto Subdata = 
Array!(Tuple!(string, ulong))(dFiles ~ subdirTotalGB); }

 subdirTotal = 0;
}
return Subdata;
}

void main () {
writeln (coSizeDirList[]);
}


Hi,

 Few updates,

 If i change the function to main i am able to print the 
required output, but if i change the main to function and call 
this function from another main then i am not able to return 
the result from the function.


Updated Code:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
Array!(Tuple!(string, ulong)) coSizeDirList () {
//void main () {
string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(Tuple!(ulong)) Subdata;
	auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => 
tuple(a.name)));

foreach (d; dFiles[]) {
auto SdFiles = Array!(Tuple!(ulong)) (dirEntries(d[0], 
SpanMode.depth).map!(a => tuple(a.size)));
foreach(f; SdFiles[]) { subdirTotal += f.fold!((a, b) => a 
+ b); }

subdirTotalGB = (subdirTotal/1024/1024);
if (subdirTotalGB > SizeDir) { Subdata 
~= subdirTotalGB; }
subdirTotal = 0;
}
//writeln(dFiles);
//writeln(Subdata);
return dFiles[];
return Subdata[];
}

void main () {
writeln (coSizeDirList[]);
}

From,
Vino.B


Few Update:

Update Code :
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
Array!(Tuple!(string, ulong)) coSizeDirList () {
//void main () {
string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!ulong Subdata;
	auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name)));

foreach (d; dFiles[]) {
auto SdFiles = Array!(Tuple!(ulong)) (dirEntries(d[0], 
SpanMode.depth).map!(a => tuple(a.size)));
foreach(f; SdFiles[]) { subdirTotal += f.fold!((a, b) => a + 
b); }

subdirTotalGB = (subdirTotal/1024/1024);
if (subdirTotalGB > SizeDir) { Subdata 
~= subdirTotalGB; }
subdirTotal = 0;
}
//writeln(dFiles[]);
//writeln(Subdata[]);
return tuple (dFiles[], Subdata[]);
//return Subdata[];
//return Result;
}

void main () {
writeln (coSizeDirList[]);
}

Error Output
Test1.d(27): Error: cannot implicitly convert expression 
(tuple(dFiles.opSlice(), Subdata.opSlice())) of type 
Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong)) to 
Array!(Tuple!(string, ulong))

Failed: ["dmd", "-v", "-o-", "Test1.d", "-I."]

From,
Vino.B


Re: Container Array

2017-09-07 Thread Vino.B via Digitalmars-d-learn

On Thursday, 7 September 2017 at 15:07:56 UTC, Vino.B wrote:
On Thursday, 7 September 2017 at 14:26:08 UTC, Ali Çehreli 
wrote:

On 09/07/2017 03:56 AM, Vino.B wrote:


writeln(coCleanFiles);


Access the elements by taking a slice of the container:

writeln(coCleanFiles[]);

Ali


Hi Ali,

 Thank you very much, was ablee to resolve this issue and now 
facing a new issue as the below code is not working as 
expected. The below code has to list the folders and their 
size's.


import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;

Array!(Tuple!(string, ulong)) coSizeDirList () {
string FFs = "C:\\Temp\\TEST1\\BACKUP";
int SizeDir = 10;
ulong subdirTotal;
ulong subdirTotalGB;
	auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => 
tuple(a.name)));

foreach (d; dFiles) {
auto SdFiles = Array!(Tuple!(ulong)) (dirEntries(d[0], 
SpanMode.depth).map!(a => tuple(a.size)));
foreach(f; parallel(SdFiles, 1)) { subdirTotal += 
f.fold!((a, b) => a + b); }

subdirTotalGB = (subdirTotal/1024/1024);
	if (subdirTotalGB > SizeDir) { auto Subdata = 
Array!(Tuple!(string, ulong))(dFiles ~ subdirTotalGB); }

 subdirTotal = 0;
}
return Subdata;
}

void main () {
writeln (coSizeDirList[]);
}


Hi,

 Few updates,

 If i change the function to main i am able to print the required 
output, but if i change the main to function and call this 
function from another main then i am not able to return the 
result from the function.


Updated Code:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
Array!(Tuple!(string, ulong)) coSizeDirList () {
//void main () {
string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(Tuple!(ulong)) Subdata;
	auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name)));

foreach (d; dFiles[]) {
auto SdFiles = Array!(Tuple!(ulong)) (dirEntries(d[0], 
SpanMode.depth).map!(a => tuple(a.size)));
foreach(f; SdFiles[]) { subdirTotal += f.fold!((a, b) => a + 
b); }

subdirTotalGB = (subdirTotal/1024/1024);
if (subdirTotalGB > SizeDir) { Subdata 
~= subdirTotalGB; }
subdirTotal = 0;
}
//writeln(dFiles);
//writeln(Subdata);
return dFiles[];
return Subdata[];
}

void main () {
writeln (coSizeDirList[]);
}

From,
Vino.B



Re: Container Array

2017-09-07 Thread Vino.B via Digitalmars-d-learn

On Thursday, 7 September 2017 at 14:26:08 UTC, Ali Çehreli wrote:

On 09/07/2017 03:56 AM, Vino.B wrote:


writeln(coCleanFiles);


Access the elements by taking a slice of the container:

writeln(coCleanFiles[]);

Ali


Hi Ali,

 Thank you very much, was ablee to resolve this issue and now 
facing a new issue as the below code is not working as expected. 
The below code has to list the folders and their size's.


import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;

Array!(Tuple!(string, ulong)) coSizeDirList () {
string FFs = "C:\\Temp\\TEST1\\BACKUP";
int SizeDir = 10;
ulong subdirTotal;
ulong subdirTotalGB;
	auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name)));

foreach (d; dFiles) {
auto SdFiles = Array!(Tuple!(ulong)) (dirEntries(d[0], 
SpanMode.depth).map!(a => tuple(a.size)));
foreach(f; parallel(SdFiles, 1)) { subdirTotal += f.fold!((a, 
b) => a + b); }

subdirTotalGB = (subdirTotal/1024/1024);
	if (subdirTotalGB > SizeDir) { auto Subdata = 
Array!(Tuple!(string, ulong))(dFiles ~ subdirTotalGB); }

 subdirTotal = 0;
}
return Subdata;
}

void main () {
writeln (coSizeDirList[]);
}


Re: Container Array

2017-09-07 Thread Ali Çehreli via Digitalmars-d-learn

On 09/07/2017 03:56 AM, Vino.B wrote:


writeln(coCleanFiles);


Access the elements by taking a slice of the container:

writeln(coCleanFiles[]);

Ali



Re: Container Array

2017-09-07 Thread Vino.B via Digitalmars-d-learn

On Wednesday, 6 September 2017 at 16:41:06 UTC, Vino.B wrote:

HI All,

 Can some one provide me a example of how to use the 
std.container.array for the below code.


import std.algorithm: filter, map;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: writeln;
import std.typecons: tuple;
import std.array: array;

void main () {
	string[] Filesys = ["C:\\Temp\\TEST1\\BACKUP", 
"C:\\Temp\\TEST2\\EXPORT"];

foreach(FFs; Filesys) {
		auto dFiles = dirEntries("C:\\Temp\\TEST1\\BACKUP", 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.size));

foreach(d; dFiles)
writeln(d[0], "\t", d[1]);
}
}

From,
Vino.B


Hi,

  I tried a small code using container array, and the output i 
get form the code is a below, so can one help me on this issue.


Program:
import std.algorithm: filter, map;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: writeln;
import std.typecons: tuple, Tuple;
import std.container;

Array!(Tuple!(string, string)) coCleanFiles() {
	auto dFiles = make!Array(dirEntries("C:\\Temp\\TEST1\\BACKUP", 
SpanMode.shallow).filter!(a => a.isFile).map!(a => tuple(a.name, 
a.timeCreated.toSimpleString[0 .. 20])));

return dFiles;
}

void main () {
writeln(coCleanFiles);
}

Output:
Array!(Tuple!(string, string))(RefCounted!(Payload, 
cast(RefCountedAutoInitialize)0)(RefCountedStore(62D818)))


From,
Vino.B



Container Array

2017-09-06 Thread Vino.B via Digitalmars-d-learn

HI All,

 Can some one provide me a example of how to use the 
std.container.array for the below code.


import std.algorithm: filter, map;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: writeln;
import std.typecons: tuple;
import std.array: array;

void main () {
	string[] Filesys = ["C:\\Temp\\TEST1\\BACKUP", 
"C:\\Temp\\TEST2\\EXPORT"];

foreach(FFs; Filesys) {
		auto dFiles = dirEntries("C:\\Temp\\TEST1\\BACKUP", 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.size));

foreach(d; dFiles)
writeln(d[0], "\t", d[1]);
}
}

From,
Vino.B


How to apply a function to a container/array ?

2014-10-15 Thread Domingo via Digitalmars-d-learn

Ideally I want to use something like this:
-
import std.stdio;
import std.string;
import std.algorithm;
import std.conv;

void main()
{
string[] ar = [ dad ,  blue ];
writeln(typeid(ar));

//ar.each(writeln);
//ar.map!writeln;
//ar.apply!writeln;

//string[] ar_striped = ar.map!strip;
//string[] ar_striped = ar.apply!strip;
//string[] ar_striped = ar.each!strip;

//ar_striped.each!writeln;
//ar_striped.apply!writeln;
//ar_striped.map!writeln;


alias stringize = map!(to!string);
auto sz = stringize([ 1, 2, 3, 4 ]);
writeln(typeid(sz));
assert(equal(sz, [ 1, 2, 3, 4 ]));
}
-

But none of then work, any idea of how to that in D ?

Cheers !


Re: How to apply a function to a container/array ?

2014-10-15 Thread bearophile via Digitalmars-d-learn

Domingo:


Ideally I want to use something like this:
-
import std.stdio;
import std.string;
import std.algorithm;
import std.conv;

void main()
{
string[] ar = [ dad ,  blue ];
writeln(typeid(ar));

//ar.each(writeln);
//ar.map!writeln;
//ar.apply!writeln;

//string[] ar_striped = ar.map!strip;
//string[] ar_striped = ar.apply!strip;
//string[] ar_striped = ar.each!strip;

//ar_striped.each!writeln;
//ar_striped.apply!writeln;
//ar_striped.map!writeln;


alias stringize = map!(to!string);
auto sz = stringize([ 1, 2, 3, 4 ]);
writeln(typeid(sz));
assert(equal(sz, [ 1, 2, 3, 4 ]));
}
-

But none of then work, any idea of how to that in D ?


D algorithms like map don't return an array, but a lazy range. 
Use .array if you need an array:


void main() {
import std.stdio;
import std.algorithm;
import std.array;
import std.string;
import std.conv;

immutable ar = [ dad ,  blue ];
pragma(msg, typeof(ar));
ar.writeln;
auto arStriped = ar.map!strip;
arStriped.writeln;
pragma(msg, typeof(arStriped));
immutable arStripedArray = arStriped.array;
pragma(msg, typeof(arStripedArray));

alias stringize = map!text;
auto sz = stringize([ 1, 2, 3, 4 ]);
assert(sz.equal([1, 2, 3, 4]));
}


Usually it's better to use pragma+typeof, typeid is used less 
often, for run time management/use of types.


Bye,
bearophile


Re: How to apply a function to a container/array ?

2014-10-15 Thread Ali Çehreli via Digitalmars-d-learn

On 10/15/2014 04:26 PM, Domingo wrote:


Ideally I want to use something like this:


import std.stdio;
import std.string;
import std.algorithm;
import std.conv;

void main()
{
string[] ar = [ dad ,  blue ];
writeln(typeid(ar));

// a) foreach for purely side-effect expressions:
foreach (s; ar) {
writeln(s);
}

// b) Element format specifiers %( %) and %|
writefln(%-(%s%|, %), ar);

// Again:
auto ar_striped = ar.map!strip;
writefln(%-(%s%), ar_striped);

alias stringize = map!(to!string);
auto sz = stringize([ 1, 2, 3, 4 ]);
writeln(typeid(sz));
assert(equal(sz, [ 1, 2, 3, 4 ]));
}

Ali



Re: How to apply a function to a container/array ?

2014-10-15 Thread Domingo via Digitalmars-d-learn
Thanks so much it's a bit more bloated than I was expecting but 
it works.

---
void main() {
import std.stdio;
import std.algorithm;
import std.array;
import std.string;
import std.conv;

auto ar = [ dad ,  blue ];
ar.writeln;
auto arStriped = ar.map!strip.array;
arStriped.writeln;

alias stringize = map!text;
auto sz = stringize([ 1, 2, 3, 4 ]);
assert(sz.equal([1, 2, 3, 4]));
}



Re: How to apply a function to a container/array ?

2014-10-15 Thread Domingo via Digitalmars-d-learn

Even better would be if phobos provided it out of the box:
---
import std.stdio;
import std.algorithm;
import std.array;
import std.string;
import std.conv;

void stripStringArrayInPlace(T)(T[] ar){for(long i=0, 
len=ar.length; i  len; ++i) ar[i] = ar[i].strip;}


T[] stripStringArray(T)(T[] ar){return ar.map!strip.array;}

T[] splitString(T)(T str, T sep=,){return 
str.split(sep).map!strip.array;}



void main() {

 auto str =   abor   , France   , Spain   ;
 auto arstr = str.splitString;
 arstr.writeln; 

auto ar = [ dad ,  blue ];
ar.writeln;
auto arStriped = ar.map!strip.array;
arStriped.writeln;

auto ar2 = ar.stripStringArray;
ar2.writeln;

ar.stripStringArrayInPlace;
ar.writeln;

alias stringize = map!text;
auto sz = stringize([ 1, 2, 3, 4 ]);
assert(sz.equal([1, 2, 3, 4]));
}
---