digitalmars.D.learn - Generic range to read array or a file as a phobos range
- bioinfornatics (8/8) Mar 15 2013 Dear,
- Andrea Fontana (3/11) Mar 15 2013 Have you tried to cache front() result and read next block on
- bioinfornatics (4/19) Mar 15 2013 that is ok. Just missed the \n the followed code should work
- Andrea Fontana (12/32) Mar 15 2013 int[] a = [ 0, 1, 1, 2, 3, 5, 8 ];
- bioinfornatics (4/39) Mar 17 2013 As you said that do not works i update the code with some
- Andrea Fontana (12/58) Mar 17 2013 Your code works if you use .writeln instead of .array. This why
- bioinfornatics (2/63) Mar 17 2013 yes that was a reference problem using dup fix it. Thanks
- Andrea Fontana (3/71) Mar 18 2013 Maybe you should check for dup vs local var performance (on big
Dear, By using CTFE I try to get a generic range to read array or a file as a phobos range. code hosted here: http://dpaste.dzfl.pl/1f2bcf39 that works fine for array but for a File instance .eof seem to not return true a right time. Soemone could say what happen ? Thanks
Mar 15 2013
On Friday, 15 March 2013 at 14:31:43 UTC, bioinfornatics wrote:Dear, By using CTFE I try to get a generic range to read array or a file as a phobos range. code hosted here: http://dpaste.dzfl.pl/1f2bcf39 that works fine for array but for a File instance .eof seem to not return true a right time. Soemone could say what happen ? ThanksHave you tried to cache front() result and read next block on popFront()?
Mar 15 2013
On Friday, 15 March 2013 at 14:40:17 UTC, Andrea Fontana wrote:On Friday, 15 March 2013 at 14:31:43 UTC, bioinfornatics wrote:that is ok. Just missed the \n the followed code should work http://dpaste.dzfl.pl/1f2bcf39 You are welcome to take it :)Dear, By using CTFE I try to get a generic range to read array or a file as a phobos range. code hosted here: http://dpaste.dzfl.pl/1f2bcf39 that works fine for array but for a File instance .eof seem to not return true a right time. Soemone could say what happen ? ThanksHave you tried to cache front() result and read next block on popFront()?
Mar 15 2013
On Friday, 15 March 2013 at 16:11:38 UTC, bioinfornatics wrote:On Friday, 15 March 2013 at 14:40:17 UTC, Andrea Fontana wrote:int[] a = [ 0, 1, 1, 2, 3, 5, 8 ]; std.file.write("/tmp/filename", a); File f = File("/tmp/filename", "r"); auto r = GenericRange!File(f,1); r.filter!"a.length > 0 && a[0] != 0"().writeln; output: [[0], [0], [0], [0], [0], [0]] but i think output expected is: [[1], [1], [2], [3], [5], [8]] Caching front() and reading buffer from popFront() did the trick for me.On Friday, 15 March 2013 at 14:31:43 UTC, bioinfornatics wrote:that is ok. Just missed the \n the followed code should work http://dpaste.dzfl.pl/1f2bcf39 You are welcome to take it :)Dear, By using CTFE I try to get a generic range to read array or a file as a phobos range. code hosted here: http://dpaste.dzfl.pl/1f2bcf39 that works fine for array but for a File instance .eof seem to not return true a right time. Soemone could say what happen ? ThanksHave you tried to cache front() result and read next block on popFront()?
Mar 15 2013
On Friday, 15 March 2013 at 16:40:26 UTC, Andrea Fontana wrote:On Friday, 15 March 2013 at 16:11:38 UTC, bioinfornatics wrote:As you said that do not works i update the code with some unittest could you please to share your version ? you can use fork from dpast -> http://dpaste.dzfl.pl/1f2bcf39e. ThanksOn Friday, 15 March 2013 at 14:40:17 UTC, Andrea Fontana wrote:int[] a = [ 0, 1, 1, 2, 3, 5, 8 ]; std.file.write("/tmp/filename", a); File f = File("/tmp/filename", "r"); auto r = GenericRange!File(f,1); r.filter!"a.length > 0 && a[0] != 0"().writeln; output: [[0], [0], [0], [0], [0], [0]] but i think output expected is: [[1], [1], [2], [3], [5], [8]] Caching front() and reading buffer from popFront() did the trick for me.On Friday, 15 March 2013 at 14:31:43 UTC, bioinfornatics wrote:that is ok. Just missed the \n the followed code should work http://dpaste.dzfl.pl/1f2bcf39 You are welcome to take it :)Dear, By using CTFE I try to get a generic range to read array or a file as a phobos range. code hosted here: http://dpaste.dzfl.pl/1f2bcf39 that works fine for array but for a File instance .eof seem to not return true a right time. Soemone could say what happen ? ThanksHave you tried to cache front() result and read next block on popFront()?
Mar 17 2013
On Sunday, 17 March 2013 at 18:36:17 UTC, bioinfornatics wrote:On Friday, 15 March 2013 at 16:40:26 UTC, Andrea Fontana wrote:Your code works if you use .writeln instead of .array. This why *it seems* that struct member "U buffer" is returned by reference. Check this. It passes unittest. http://dpaste.dzfl.pl/828f7cc4 I move buffer inside popFront function, so "value = rawWrite(..)" assign every time a reference to a different "buffer". In your code it returns always the same member variable so, output array was an array of 8 identical reference to last read value (e.g. [8]) Maybe you can achieve the same in other way (for example using idup?). I hope it works.On Friday, 15 March 2013 at 16:11:38 UTC, bioinfornatics wrote:As you said that do not works i update the code with some unittest could you please to share your version ? you can use fork from dpast -> http://dpaste.dzfl.pl/1f2bcf39e. ThanksOn Friday, 15 March 2013 at 14:40:17 UTC, Andrea Fontana wrote:int[] a = [ 0, 1, 1, 2, 3, 5, 8 ]; std.file.write("/tmp/filename", a); File f = File("/tmp/filename", "r"); auto r = GenericRange!File(f,1); r.filter!"a.length > 0 && a[0] != 0"().writeln; output: [[0], [0], [0], [0], [0], [0]] but i think output expected is: [[1], [1], [2], [3], [5], [8]] Caching front() and reading buffer from popFront() did the trick for me.On Friday, 15 March 2013 at 14:31:43 UTC, bioinfornatics wrote:that is ok. Just missed the \n the followed code should work http://dpaste.dzfl.pl/1f2bcf39 You are welcome to take it :)Dear, By using CTFE I try to get a generic range to read array or a file as a phobos range. code hosted here: http://dpaste.dzfl.pl/1f2bcf39 that works fine for array but for a File instance .eof seem to not return true a right time. Soemone could say what happen ? ThanksHave you tried to cache front() result and read next block on popFront()?
Mar 17 2013
On Sunday, 17 March 2013 at 20:21:23 UTC, Andrea Fontana wrote:On Sunday, 17 March 2013 at 18:36:17 UTC, bioinfornatics wrote:yes that was a reference problem using dup fix it. ThanksOn Friday, 15 March 2013 at 16:40:26 UTC, Andrea Fontana wrote:Your code works if you use .writeln instead of .array. This why *it seems* that struct member "U buffer" is returned by reference. Check this. It passes unittest. http://dpaste.dzfl.pl/828f7cc4 I move buffer inside popFront function, so "value = rawWrite(..)" assign every time a reference to a different "buffer". In your code it returns always the same member variable so, output array was an array of 8 identical reference to last read value (e.g. [8]) Maybe you can achieve the same in other way (for example using idup?). I hope it works.On Friday, 15 March 2013 at 16:11:38 UTC, bioinfornatics wrote:As you said that do not works i update the code with some unittest could you please to share your version ? you can use fork from dpast -> http://dpaste.dzfl.pl/1f2bcf39e. ThanksOn Friday, 15 March 2013 at 14:40:17 UTC, Andrea Fontana wrote:int[] a = [ 0, 1, 1, 2, 3, 5, 8 ]; std.file.write("/tmp/filename", a); File f = File("/tmp/filename", "r"); auto r = GenericRange!File(f,1); r.filter!"a.length > 0 && a[0] != 0"().writeln; output: [[0], [0], [0], [0], [0], [0]] but i think output expected is: [[1], [1], [2], [3], [5], [8]] Caching front() and reading buffer from popFront() did the trick for me.On Friday, 15 March 2013 at 14:31:43 UTC, bioinfornatics wrote:that is ok. Just missed the \n the followed code should work http://dpaste.dzfl.pl/1f2bcf39 You are welcome to take it :)Dear, By using CTFE I try to get a generic range to read array or a file as a phobos range. code hosted here: http://dpaste.dzfl.pl/1f2bcf39 that works fine for array but for a File instance .eof seem to not return true a right time. Soemone could say what happen ? ThanksHave you tried to cache front() result and read next block on popFront()?
Mar 17 2013
On Sunday, 17 March 2013 at 22:12:42 UTC, bioinfornatics wrote:On Sunday, 17 March 2013 at 20:21:23 UTC, Andrea Fontana wrote:Maybe you should check for dup vs local var performance (on big file, of course)On Sunday, 17 March 2013 at 18:36:17 UTC, bioinfornatics wrote:yes that was a reference problem using dup fix it. ThanksOn Friday, 15 March 2013 at 16:40:26 UTC, Andrea Fontana wrote:Your code works if you use .writeln instead of .array. This why *it seems* that struct member "U buffer" is returned by reference. Check this. It passes unittest. http://dpaste.dzfl.pl/828f7cc4 I move buffer inside popFront function, so "value = rawWrite(..)" assign every time a reference to a different "buffer". In your code it returns always the same member variable so, output array was an array of 8 identical reference to last read value (e.g. [8]) Maybe you can achieve the same in other way (for example using idup?). I hope it works.On Friday, 15 March 2013 at 16:11:38 UTC, bioinfornatics wrote:As you said that do not works i update the code with some unittest could you please to share your version ? you can use fork from dpast -> http://dpaste.dzfl.pl/1f2bcf39e. ThanksOn Friday, 15 March 2013 at 14:40:17 UTC, Andrea Fontana wrote:int[] a = [ 0, 1, 1, 2, 3, 5, 8 ]; std.file.write("/tmp/filename", a); File f = File("/tmp/filename", "r"); auto r = GenericRange!File(f,1); r.filter!"a.length > 0 && a[0] != 0"().writeln; output: [[0], [0], [0], [0], [0], [0]] but i think output expected is: [[1], [1], [2], [3], [5], [8]] Caching front() and reading buffer from popFront() did the trick for me.On Friday, 15 March 2013 at 14:31:43 UTC, bioinfornatics wrote:that is ok. Just missed the \n the followed code should work http://dpaste.dzfl.pl/1f2bcf39 You are welcome to take it :)Dear, By using CTFE I try to get a generic range to read array or a file as a phobos range. code hosted here: http://dpaste.dzfl.pl/1f2bcf39 that works fine for array but for a File instance .eof seem to not return true a right time. Soemone could say what happen ? ThanksHave you tried to cache front() result and read next block on popFront()?
Mar 18 2013